CryptoAuthLib
Atmel CryptoAuthentication Library
Hardware abstraction layer (hal_)

These methods define the hardware abstraction layer for communicating with a CryptoAuth device. More...

Data Structures

struct  ATCAHAL_t
 an intermediary data structure to allow the HAL layer to point the standard API functions used by the upper layers to the HAL implementation for the interface. This isolates the upper layers and loosely couples the ATCAIface object from the physical implementation. More...
 
struct  atcaI2Cmaster
 This is the hal_data for ATCA HAL. More...
 
struct  cdc_device
 
struct  atcacdc
 
struct  atcaSWImaster
 This is the hal_data for ATCA HAL. More...
 
struct  hid_device
 
struct  atcahid
 

Macros

#define max(a, b)    (((a) > (b)) ? (a) : (b))
 
#define min(a, b)    (((a) < (b)) ? (a) : (b))
 
#define CDC_DEVICES_MAX   10
 
#define CDC_BUFFER_MAX   1024
 
#define INVALID_HANDLE_VALUE   ((int)(-1))
 
#define MAX_I2C_BUSES   2
 
#define MAX_I2C_BUSES   6
 
#define MAX_I2C_BUSES   6
 
#define MAX_I2C_BUSES   3
 
#define SWI_WAKE_TOKEN   ((uint8_t)0x00)
 flag preceding a command More...
 
#define SWI_FLAG_CMD   ((uint8_t)0x77)
 flag preceding a command More...
 
#define SWI_FLAG_TX   ((uint8_t)0x88)
 flag requesting a response More...
 
#define SWI_FLAG_IDLE   ((uint8_t)0xBB)
 flag requesting to go into Idle mode More...
 
#define SWI_FLAG_SLEEP   ((uint8_t)0xCC)
 flag requesting to go into Sleep mode More...
 
#define HID_GUID   { 0x4d1e55b2, 0xf16f, 0x11cf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 }
 
#define HID_DEVICES_MAX   10
 
#define HID_PACKET_MAX   512
 
#define MAX_I2C_BUSES   4
 
#define KIT_TX_WRAP_SIZE   (7)
 
#define KIT_MSG_SIZE   (32)
 
#define KIT_RX_WRAP_SIZE   (KIT_MSG_SIZE + 6)
 
#define MAX_SWI_BUSES   6
 
#define RECEIVE_MODE   0
 
#define TRANSMIT_MODE   1
 
#define RX_DELAY   { volatile uint8_t delay = 90; while (delay--) __asm__(""); }
 
#define TX_DELAY   90
 
#define DEBUG_PIN_1   EXT2_PIN_5
 
#define DEBUG_PIN_2   EXT2_PIN_6
 
#define MAX_SWI_BUSES   6
 
#define RECEIVE_MODE   0
 
#define TRANSMIT_MODE   1
 
#define RX_DELAY   10
 
#define TX_DELAY   93
 
#define MAX_SWI_BUSES   6
 
#define RECEIVE_MODE   0
 
#define TRANSMIT_MODE   1
 
#define RX_DELAY   10
 
#define TX_DELAY   90
 

Typedefs

typedef struct atcaI2Cmaster ATCAI2CMaster_t
 This is the hal_data for ATCA HAL. More...
 
typedef int HANDLE
 
typedef struct cdc_device cdc_device_t
 
typedef struct atcacdc atcacdc_t
 
typedef struct atcaI2Cmaster ATCAI2CMaster_t
 this is the hal_data for ATCA HAL More...
 
typedef struct atcaI2Cmaster ATCAI2CMaster_t
 this is the hal_data for ATCA HAL for ASF SERCOM More...
 
typedef struct atcaI2Cmaster ATCAI2CMaster_t
 this is the hal_data for ATCA HAL for Atmel START SERCOM More...
 
typedef struct atcaI2Cmaster ATCAI2CMaster_t
 this is the hal_data for ATCA HAL for ASF SERCOM More...
 
typedef struct atcaSWImaster ATCASWIMaster_t
 This is the hal_data for ATCA HAL. More...
 
typedef struct hid_device hid_device_t
 
typedef struct atcahid atcahid_t
 
typedef struct atcaI2Cmaster ATCAI2CMaster_t
 this is the hal_data for ATCA HAL created using ASF More...
 
typedef struct atcaSWImaster ATCASWIMaster_t
 this is the hal_data for ATCA HAL for ASF SERCOM More...
 
typedef struct atcaSWImaster ATCASWIMaster_t
 this is the hal_data for ATCA HAL for ASF SERCOM More...
 
typedef struct atcaSWImaster ATCASWIMaster_t
 this is the hal_data for ATCA HAL for SWI UART More...
 

Enumerations

enum  i2c_read_write_flag { I2C_WRITE = (uint8_t) 0x00, I2C_READ = (uint8_t) 0x01 }
 This enumeration lists flags for I2C read or write addressing. More...
 
enum  swi_flag { SWI_FLAG_CMD = (uint8_t) 0x77, SWI_FLAG_TX = (uint8_t) 0x88, SWI_FLAG_IDLE = (uint8_t) 0xBB, SWI_FLAG_SLEEP = (uint8_t) 0xCC }
 This enumeration lists flags for SWI. More...
 

Functions

ATCA_STATUS hal_iface_init (ATCAIfaceCfg *, ATCAHAL_t *hal)
 Standard HAL API for ATCA to initialize a physical interface. More...
 
ATCA_STATUS hal_iface_release (ATCAIfaceType, void *hal_data)
 releases a physical interface, HAL knows how to interpret hal_data More...
 
void atca_delay_us (uint32_t delay)
 Timer API implemented at the HAL level. More...
 
void atca_delay_10us (uint32_t delay)
 This function delays for a number of tens of microseconds. More...
 
void atca_delay_ms (uint32_t delay)
 This function delays for a number of milliseconds. You can override this function if you like to do something else in your system while delaying. More...
 
ATCA_STATUS hal_i2c_init (void *hal, ATCAIfaceCfg *cfg)
 hal_i2c_init manages requests to initialize a physical interface. It manages use counts so when an interface has released the physical layer, it will disable the interface for some other use. You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on multiple i2c buses, so hal_i2c_init manages these things and ATCAIFace is abstracted from the physical details. More...
 
ATCA_STATUS hal_i2c_post_init (ATCAIface iface)
 HAL implementation of I2C post init. More...
 
ATCA_STATUS hal_i2c_send (ATCAIface iface, uint8_t *txdata, int txlength)
 Send byte(s) via I2C. More...
 
ATCA_STATUS hal_i2c_receive (ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)
 Receive byte(s) via I2C. More...
 
ATCA_STATUS hal_i2c_wake (ATCAIface iface)
 Send Wake flag via I2C. More...
 
ATCA_STATUS hal_i2c_idle (ATCAIface iface)
 Send Idle flag via I2C. More...
 
ATCA_STATUS hal_i2c_sleep (ATCAIface iface)
 Send Sleep flag via I2C. More...
 
ATCA_STATUS hal_i2c_release (void *hal_data)
 Manages reference count on given bus and releases resource if no more reference(s) exist. More...
 
ATCA_STATUS hal_cdc_discover_buses (int cdc_buses[], int max_buses)
 discover cdc buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge More...
 
ATCA_STATUS hal_cdc_discover_devices (int busNum, ATCAIfaceCfg cfg[], int *found)
 discover any CryptoAuth devices on a given logical bus number More...
 
ATCA_STATUS hal_kit_cdc_init (void *hal, ATCAIfaceCfg *cfg)
 
ATCA_STATUS hal_kit_cdc_post_init (ATCAIface iface)
 HAL implementation of Kit USB CDC post init. More...
 
ATCA_STATUS kit_phy_send (ATCAIface iface, uint8_t *txdata, int txlength)
 HAL implementation of send over USB CDC. More...
 
ATCA_STATUS kit_phy_receive (ATCAIface iface, uint8_t *rxdata, int *rxsize)
 HAL implementation of kit protocol send over USB CDC. More...
 
ATCA_STATUS hal_kit_phy_num_found (int8_t *num_found)
 Number of USB CDC devices found. More...
 
ATCA_STATUS hal_kit_cdc_send (ATCAIface iface, uint8_t *txdata, int txlength)
 HAL implementation of kit protocol send over USB CDC. More...
 
ATCA_STATUS hal_kit_cdc_receive (ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
 HAL implementation of send over USB CDC. More...
 
ATCA_STATUS hal_kit_cdc_wake (ATCAIface iface)
 Call the wake for kit protocol. More...
 
ATCA_STATUS hal_kit_cdc_idle (ATCAIface iface)
 Call the idle for kit protocol. More...
 
ATCA_STATUS hal_kit_cdc_sleep (ATCAIface iface)
 Call the sleep for kit protocol. More...
 
ATCA_STATUS hal_kit_cdc_release (void *hal_data)
 Close the physical port for CDC. More...
 
ATCA_STATUS hal_kit_cdc_discover_buses (int i2c_buses[], int max_buses)
 
ATCA_STATUS hal_kit_cdc_discover_devices (int busNum, ATCAIfaceCfg *cfg, int *found)
 
ATCA_STATUS hal_i2c_discover_buses (int i2c_buses[], int max_buses)
 This HAL implementation assumes you've included the ASF TWI libraries in your project, otherwise, the HAL layer will not compile because the ASF TWI drivers are a dependency. More...
 
ATCA_STATUS hal_i2c_discover_devices (int busNum, ATCAIfaceCfg cfg[], int *found)
 discover any CryptoAuth devices on a given logical bus number More...
 
void change_i2c_speed (ATCAIface iface, uint32_t speed)
 method to change the bus speed of I2C More...
 
ATCA_STATUS hal_swi_init (void *hal, ATCAIfaceCfg *cfg)
 hal_swi_init manages requests to initialize a physical interface. It manages use counts so when an interface has released the physical layer, it will disable the interface for some other use. You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on multiple swi buses, so hal_swi_init manages these things and ATCAIFace is abstracted from the physical details. More...
 
ATCA_STATUS hal_swi_post_init (ATCAIface iface)
 HAL implementation of SWI post init. More...
 
ATCA_STATUS hal_swi_send (ATCAIface iface, uint8_t *txdata, int txlength)
 Send byte(s) via SWI. More...
 
ATCA_STATUS hal_swi_receive (ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)
 Receive byte(s) via SWI. More...
 
ATCA_STATUS hal_swi_wake (ATCAIface iface)
 Send Wake flag via SWI. More...
 
ATCA_STATUS hal_swi_idle (ATCAIface iface)
 Send Idle flag via SWI. More...
 
ATCA_STATUS hal_swi_sleep (ATCAIface iface)
 Send Sleep flag via SWI. More...
 
ATCA_STATUS hal_swi_release (void *hal_data)
 Manages reference count on given bus and releases resource if no more reference(s) exist. More...
 
ATCA_STATUS hal_swi_discover_buses (int swi_buses[], int max_buses)
 discover swi buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge More...
 
ATCA_STATUS hal_swi_discover_devices (int busNum, ATCAIfaceCfg cfg[], int *found)
 discover any CryptoAuth devices on a given logical bus number More...
 
ATCA_STATUS hal_swi_send_flag (ATCAIface iface, uint8_t data)
 HAL implementation of SWI send one byte over UART. More...
 
ATCA_STATUS hal_kit_hid_init (void *hal, ATCAIfaceCfg *cfg)
 HAL implementation of Kit USB HID init. More...
 
ATCA_STATUS hal_kit_hid_discover_buses (int i2c_buses[], int max_buses)
 
ATCA_STATUS hal_kit_hid_discover_devices (int busNum, ATCAIfaceCfg cfg[], int *found)
 discover any CryptoAuth devices on a given logical bus number More...
 
ATCA_STATUS hal_kit_hid_post_init (ATCAIface iface)
 HAL implementation of Kit HID post init. More...
 
ATCA_STATUS kit_phy_num_found (int8_t *num_found)
 Number of USB HID devices found. More...
 
ATCA_STATUS hal_kit_hid_send (ATCAIface iface, uint8_t *txdata, int txlength)
 HAL implementation of kit protocol send over USB HID. More...
 
ATCA_STATUS hal_kit_hid_receive (ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
 HAL implementation of send over USB HID. More...
 
ATCA_STATUS hal_kit_hid_wake (ATCAIface iface)
 Call the wake for kit protocol. More...
 
ATCA_STATUS hal_kit_hid_idle (ATCAIface iface)
 Call the idle for kit protocol. More...
 
ATCA_STATUS hal_kit_hid_sleep (ATCAIface iface)
 Call the sleep for kit protocol. More...
 
ATCA_STATUS hal_kit_hid_release (void *hal_data)
 Close the physical port for HID. More...
 
ATCA_STATUS kit_init (ATCAIface iface)
 HAL implementation of kit protocol init. This function calls back to the physical protocol to send the bytes. More...
 
ATCA_STATUS kit_send (ATCAIface iface, uint8_t *txdata, int txlength)
 HAL implementation of kit protocol send. This function calls back to the physical protocol to send the bytes. More...
 
ATCA_STATUS kit_receive (ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
 HAL implementation to receive bytes and unwrap from kit protocol. This function calls back to the physical protocol to receive the bytes. More...
 
ATCA_STATUS kit_wake (ATCAIface iface)
 Call the wake for kit protocol. More...
 
ATCA_STATUS kit_idle (ATCAIface iface)
 Call the idle for kit protocol. More...
 
ATCA_STATUS kit_sleep (ATCAIface iface)
 Call the sleep for kit protocol. More...
 
ATCA_STATUS kit_wrap_cmd (uint8_t *txdata, int txlen, char *pkitcmd, int *nkitcmd)
 Wrap binary bytes in ascii kit protocol. More...
 
ATCA_STATUS kit_parse_rsp (char *pkitbuf, int nkitbuf, uint8_t *kitstatus, uint8_t *rxdata, int *datasize)
 Parse the response ascii from the kit. More...
 
ATCA_STATUS swi_uart_init (ATCASWIMaster_t *instance)
 Implementation of SWI UART init. More...
 
ATCA_STATUS swi_uart_deinit (ATCASWIMaster_t *instance)
 Implementation of SWI UART deinit. More...
 
void swi_uart_setbaud (ATCASWIMaster_t *instance, uint32_t baudrate)
 implementation of SWI UART change baudrate. More...
 
void swi_uart_mode (ATCASWIMaster_t *instance, uint8_t mode)
 implementation of SWI UART change mode. More...
 
void swi_uart_discover_buses (int swi_uart_buses[], int max_buses)
 discover UART buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge More...
 
ATCA_STATUS swi_uart_send_byte (ATCASWIMaster_t *instance, uint8_t data)
 HAL implementation of SWI UART send byte over ASF. This function send one byte over UART. More...
 
ATCA_STATUS swi_uart_receive_byte (ATCASWIMaster_t *instance, uint8_t *data)
 HAL implementation of SWI UART receive bytes over ASF. This function receive one byte over UART. More...
 

Variables

ATCAI2CMaster_ti2c_hal_data [MAX_I2C_BUSES]
 Logical to physical bus mapping structure. More...
 
int i2c_bus_ref_ct = 0
 total in-use count across buses More...
 
atcacdc_t _gCdc
 
char * dev = "/dev/ttyACM0"
 HAL implementation of Kit USB CDC init. More...
 
int speed = B115200
 
ATCAI2CMaster_ti2c_hal_data [MAX_I2C_BUSES]
 Logical to physical bus mapping structure. More...
 
int i2c_bus_ref_ct = 0
 
twi_master_options_t opt_twi_master
 
ATCAI2CMaster_ti2c_hal_data [MAX_I2C_BUSES]
 logical to physical bus mapping structure More...
 
int i2c_bus_ref_ct = 0
 
ATCAI2CMaster_ti2c_hal_data [MAX_I2C_BUSES]
 
int i2c_bus_ref_ct = 0
 
ATCAI2CMaster_ti2c_hal_data [MAX_I2C_BUSES]
 logical to physical bus mapping structure More...
 
int i2c_bus_ref_ct = 0
 
ATCASWIMaster_tswi_hal_data [MAX_SWI_BUSES]
 Logical to physical bus mapping structure. More...
 
int swi_bus_ref_ct = 0
 total in-use count across buses More...
 
ATCASWIMaster_tswi_hal_data [MAX_SWI_BUSES]
 logical to physical bus mapping structure More...
 
int swi_bus_ref_ct = 0
 
atcahid_t _gHid
 
ATCAI2CMaster_ti2c_hal_data [MAX_I2C_BUSES]
 logical to physical bus mapping structure More...
 
int i2c_bus_ref_ct = 0
 
struct port_config pin_conf
 

Detailed Description

These methods define the hardware abstraction layer for communicating with a CryptoAuth device.

These methods define the hardware abstraction layer for communicating with a CryptoAuth device using SWI interface.

These methods define the hardware abstraction layer for communicating with a CryptoAuth device using SWI Interface.

These methods define the hardware abstraction layer for communicating with a CryptoAuth device using SWI bit banging.

< Uncomment when debugging

These methods define the hardware abstraction layer for communicating with a CryptoAuth device using I2C bit banging.

These methods define the hardware abstraction layer for communicating with a CryptoAuth device using I2C driver of ASF.

Macro Definition Documentation

#define CDC_BUFFER_MAX   1024
#define CDC_DEVICES_MAX   10
#define DEBUG_PIN_1   EXT2_PIN_5
#define DEBUG_PIN_2   EXT2_PIN_6
#define HID_DEVICES_MAX   10
#define HID_GUID   { 0x4d1e55b2, 0xf16f, 0x11cf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 }
#define HID_PACKET_MAX   512
#define INVALID_HANDLE_VALUE   ((int)(-1))
#define KIT_MSG_SIZE   (32)
#define KIT_RX_WRAP_SIZE   (KIT_MSG_SIZE + 6)
#define KIT_TX_WRAP_SIZE   (7)
#define max (   a,
 
)    (((a) > (b)) ? (a) : (b))
#define MAX_I2C_BUSES   6
#define MAX_I2C_BUSES   3
#define MAX_I2C_BUSES   6
#define MAX_I2C_BUSES   4
#define MAX_I2C_BUSES   2
#define MAX_SWI_BUSES   6
  • this HAL implementation assumes you've included the ASF SERCOM UART libraries in your project, otherwise, the HAL layer will not compile because the ASF UART drivers are a dependency *
#define MAX_SWI_BUSES   6
  • this HAL implementation assumes you've included the ASF UART libraries in your project, otherwise, the HAL layer will not compile because the ASF UART drivers are a dependency *
#define MAX_SWI_BUSES   6
  • this HAL implementation assumes you've included the ASF SERCOM UART libraries in your project, otherwise, the HAL layer will not compile because the ASF UART drivers are a dependency *
#define min (   a,
 
)    (((a) < (b)) ? (a) : (b))
#define RECEIVE_MODE   0
#define RECEIVE_MODE   0
#define RECEIVE_MODE   0
#define RX_DELAY   { volatile uint8_t delay = 90; while (delay--) __asm__(""); }
#define RX_DELAY   10
#define RX_DELAY   10
#define SWI_FLAG_CMD   ((uint8_t)0x77)

flag preceding a command

#define SWI_FLAG_IDLE   ((uint8_t)0xBB)

flag requesting to go into Idle mode

#define SWI_FLAG_SLEEP   ((uint8_t)0xCC)

flag requesting to go into Sleep mode

#define SWI_FLAG_TX   ((uint8_t)0x88)

flag requesting a response

#define SWI_WAKE_TOKEN   ((uint8_t)0x00)

flag preceding a command

#define TRANSMIT_MODE   1
#define TRANSMIT_MODE   1
#define TRANSMIT_MODE   1
#define TX_DELAY   90
#define TX_DELAY   90
#define TX_DELAY   93

Typedef Documentation

typedef struct atcacdc atcacdc_t
typedef struct atcahid atcahid_t

this is the hal_data for ATCA HAL for ASF SERCOM

this is the hal_data for ATCA HAL for ASF SERCOM

this is the hal_data for ATCA HAL for Atmel START SERCOM

this is the hal_data for ATCA HAL created using ASF

this is the hal_data for ATCA HAL

This is the hal_data for ATCA HAL.

this is the hal_data for ATCA HAL for ASF SERCOM

this is the hal_data for ATCA HAL for SWI UART

this is the hal_data for ATCA HAL for ASF SERCOM

This is the hal_data for ATCA HAL.

typedef struct cdc_device cdc_device_t
typedef int HANDLE
typedef struct hid_device hid_device_t

Enumeration Type Documentation

This enumeration lists flags for I2C read or write addressing.

Enumerator
I2C_WRITE 

write command flag

I2C_READ 

read command flag

enum swi_flag

This enumeration lists flags for SWI.

Enumerator
SWI_FLAG_CMD 

flag preceding a command

SWI_FLAG_TX 

flag requesting a response

SWI_FLAG_IDLE 

flag requesting to go into Idle mode

SWI_FLAG_SLEEP 

flag requesting to go into Sleep mode

Function Documentation

void atca_delay_10us ( uint32_t  delay)

This function delays for a number of tens of microseconds.

Parameters
[in]delaynumber of 0.01 milliseconds to delay
void atca_delay_ms ( uint32_t  delay)

This function delays for a number of milliseconds. You can override this function if you like to do something else in your system while delaying.

This function delays for a number of milliseconds.

Parameters
[in]delaynumber of milliseconds to delay

You can override this function if you like to do something else in your system while delaying.

Parameters
[in]delaynumber of milliseconds to delay
void atca_delay_us ( uint32_t  delay)

Timer API implemented at the HAL level.

This function delays for a number of microseconds.

Parameters
[in]delaynumber of 0.001 milliseconds to delay
[in]delaynumber of 1 microseconds to delay
void change_i2c_speed ( ATCAIface  iface,
uint32_t  speed 
)

method to change the bus speed of I2C

method to change the bus speec of I2C

Parameters
[in]ifaceinterface on which to change bus speed
[in]speedbaud rate (typically 100000 or 400000)
ATCA_STATUS hal_cdc_discover_buses ( int  cdc_buses[],
int  max_buses 
)

discover cdc buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge

Parameters
[in]cdc_buses- an array of logical bus numbers
[in]max_buses- maximum number of buses the app wants to attempt to discover
ATCA_STATUS hal_cdc_discover_devices ( int  busNum,
ATCAIfaceCfg  cfg[],
int *  found 
)

discover any CryptoAuth devices on a given logical bus number

Parameters
[in]busNum- logical bus number on which to look for CryptoAuth devices
[out]cfg[]- pointer to head of an array of interface config structures which get filled in by this method
[out]*found- number of devices found on this bus
ATCA_STATUS hal_i2c_discover_buses ( int  i2c_buses[],
int  max_buses 
)

This HAL implementation assumes you've included the ASF TWI libraries in your project, otherwise, the HAL layer will not compile because the ASF TWI drivers are a dependency.

discover i2c buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge

discover i2c buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge

Parameters
[in]i2c_buses- an array of logical bus numbers
[in]max_buses- maximum number of buses the app wants to attempt to discover
[in]i2c_buses- an array of logical bus numbers
[in]max_buses- maximum number of buses the app wants to attempt to discover
ATCA_STATUS hal_i2c_discover_devices ( int  busNum,
ATCAIfaceCfg  cfg[],
int *  found 
)

discover any CryptoAuth devices on a given logical bus number

Parameters
[in]busNum- logical bus number on which to look for CryptoAuth devices
[out]cfg[]- pointer to head of an array of interface config structures which get filled in by this method
[out]*found- number of devices found on this bus
[in]busNumlogical bus number on which to look for CryptoAuth devices
[out]cfgpointer to head of an array of interface config structures which get filled in by this method
[out]foundnumber of devices found on this bus

default configuration, to be reused during discovery process

default configuration, to be reused during discovery process

default configuration, to be reused during discovery process

ATCA_STATUS hal_i2c_idle ( ATCAIface  iface)

Send Idle flag via I2C.

idle CryptoAuth device using I2C bus

Parameters
[in]ifaceinterface of the logical device to idle
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to idle
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to idle

Set I2C pins

Address the device and indicate that bytes are to be written

< Word Address Value = Idle

ATCA_STATUS hal_i2c_init ( void *  hal,
ATCAIfaceCfg cfg 
)

hal_i2c_init manages requests to initialize a physical interface. It manages use counts so when an interface has released the physical layer, it will disable the interface for some other use. You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on multiple i2c buses, so hal_i2c_init manages these things and ATCAIFace is abstracted from the physical details.

hal_i2c_init manages requests to initialize a physical interface. it manages use counts so when an interface has released the physical layer, it will disable the interface for some other use. You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on multiple i2c buses, so hal_i2c_init manages these things and ATCAIFace is abstracted from the physical details.

Initialize an I2C interface using given config.

Parameters
[in]halopaque pointer to HAL data
[in]cfginterface configuration
Returns
ATCA_STATUS

initialize an I2C interface using given config

Parameters
[in]hal- opaque ptr to HAL data
[in]cfg- interface configuration
Returns
ATCA_STATUS
  • this HAL implementation assumes you've included the ASF SERCOM I2C libraries in your project, otherwise, the HAL layer will not compile because the ASF I2C drivers are a dependency *initialize an I2C interface using given config
    Parameters
    [in]hal- opaque ptr to HAL data
    [in]cfg- interface configuration
  • this HAL implementation assumes you've included the ASF Twi libraries in your project, otherwise, the HAL layer will not compile because the ASF TWI drivers are a dependency *initialize an I2C interface using given config
    Parameters
    [in]hal- opaque ptr to HAL data
    [in]cfg- interface configuration
  • this HAL implementation assumes you've included the ASF I2C libraries in your project, otherwise, the HAL layer will not compile because the ASF I2C drivers are a dependency *initialize an I2C interface using given config
    Parameters
    [in]hal- opaque ptr to HAL data
    [in]cfg- interface configuration

< 0-based logical bus number

< power up state, no i2c buses will have been used

< total across buses

if this is the first time this bus and interface has been created, do the physical work of enabling it

< buses are shared, this is the first instance

assign GPIO pins

store this for use during the release phase

otherwise, another interface already initialized the bus, so this interface will share it and any different cfg parameters will be ignored...first one to initialize this sets the configuration

ATCA_STATUS hal_i2c_post_init ( ATCAIface  iface)

HAL implementation of I2C post init.

Parameters
[in]ifaceATCAIface instance
Returns
ATCA_STATUS
Parameters
[in]ifaceinstance
Returns
ATCA_STATUS
ATCA_STATUS hal_i2c_receive ( ATCAIface  iface,
uint8_t *  rxdata,
uint16_t *  rxlength 
)

Receive byte(s) via I2C.

HAL implementation of I2C receive function for START I2C.

HAL implementation of I2C receive function for ASF I2C.

Parameters
[in]ifaceinterface of the logical device to receive data from
[in]rxdatapointer to where bytes will be received
[in]rxlengthpointer to expected number of receive bytes to request
Returns
ATCA_STATUS
Parameters
[in]ifaceinstance
[in]rxdatapointer to space to receive the data
[in]rxlengthptr to expected number of receive bytes to request
Returns
ATCA_STATUS

Set I2C pins

Address the device and indicate that bytes are to be read

Receive count byte

Receive the remaining bytes

ATCA_STATUS hal_i2c_release ( void *  hal_data)

Manages reference count on given bus and releases resource if no more reference(s) exist.

manages reference count on given bus and releases resource if no more refences exist

Parameters
[in]hal_dataopaque pointer to hal data structure - known only to the HAL implementation
Returns
ATCA_STATUS
Parameters
[in]hal_data- opaque pointer to hal data structure - known only to the HAL implementation
Returns
ATCA_STATUS
Parameters
[in]hal_data- opaque pointer to hal data structure - known only to the HAL implementation
ATCA_STATUS hal_i2c_send ( ATCAIface  iface,
uint8_t *  txdata,
int  txlength 
)

Send byte(s) via I2C.

HAL implementation of I2C send over START.

HAL implementation of I2C send over ASF.

Parameters
[in]ifaceinterface of the logical device to send data to
[in]txdatapointer to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS
Parameters
[in]ifaceinstance
[in]txdatapointer to space to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS

< Word Address Value = Command

< count Word Address byte towards txlength

Set I2C pins

Address the device and indicate that bytes are to be written

Send the remaining bytes

Send STOP regardless of i2c_status

ATCA_STATUS hal_i2c_sleep ( ATCAIface  iface)

Send Sleep flag via I2C.

sleep CryptoAuth device using I2C bus

Parameters
[in]ifaceinterface of the logical device to sleep
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to sleep
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to sleep

Set I2C pins

Address the device and indicate that bytes are to be written

< Word Address Value = Sleep

ATCA_STATUS hal_i2c_wake ( ATCAIface  iface)

Send Wake flag via I2C.

wake up CryptoAuth device using I2C bus

Parameters
[in]ifaceinterface of the logical device to wake up
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to wakeup
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to wakeup

Set I2C pins

Generate Wake Token

Wait tWHI + tWLO

Receive Wake Response

Compare response with expected_response

ATCA_STATUS hal_iface_init ( ATCAIfaceCfg cfg,
ATCAHAL_t hal 
)

Standard HAL API for ATCA to initialize a physical interface.

Parameters
[in]cfgpointer to ATCAIfaceCfg object
[in]halpointer to ATCAHAL_t intermediate datastructure
ATCA_STATUS hal_iface_release ( ATCAIfaceType  ifacetype,
void *  hal_data 
)

releases a physical interface, HAL knows how to interpret hal_data

Parameters
[in]ifacetype- the type of physical interface to release
[in]hal_data- pointer to opaque hal data maintained by HAL implementation for this interface type
ATCA_STATUS hal_kit_cdc_discover_buses ( int  i2c_buses[],
int  max_buses 
)
ATCA_STATUS hal_kit_cdc_discover_devices ( int  busNum,
ATCAIfaceCfg cfg,
int *  found 
)
ATCA_STATUS hal_kit_cdc_idle ( ATCAIface  iface)

Call the idle for kit protocol.

Parameters
[in]ifaceATCAIface instance that is the interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_cdc_init ( void *  hal,
ATCAIfaceCfg cfg 
)
ATCA_STATUS hal_kit_cdc_post_init ( ATCAIface  iface)

HAL implementation of Kit USB CDC post init.

Parameters
[in]ifaceinstance
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_cdc_receive ( ATCAIface  iface,
uint8_t *  rxdata,
uint16_t *  rxsize 
)

HAL implementation of send over USB CDC.

Parameters
[in]ifaceinstance
[in]rxdatapointer to space to receive the data
[in,out]rxsizeptr to expected number of receive bytes to request
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_cdc_release ( void *  hal_data)

Close the physical port for CDC.

Parameters
[in]hal_dataThe hardware abstraction data specific to this HAL
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_cdc_send ( ATCAIface  iface,
uint8_t *  txdata,
int  txlength 
)

HAL implementation of kit protocol send over USB CDC.

Parameters
[in]ifaceinstance
[in]txdatapointer to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_cdc_sleep ( ATCAIface  iface)

Call the sleep for kit protocol.

Parameters
[in]ifaceATCAIface instance that is the interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_cdc_wake ( ATCAIface  iface)

Call the wake for kit protocol.

Parameters
[in]ifaceATCAIface instance that is the interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_discover_buses ( int  i2c_buses[],
int  max_buses 
)
ATCA_STATUS hal_kit_hid_discover_devices ( int  busNum,
ATCAIfaceCfg  cfg[],
int *  found 
)

discover any CryptoAuth devices on a given logical bus number

Parameters
[in]busNum- logical bus number on which to look for CryptoAuth devices
[out]cfg[]- pointer to head of an array of interface config structures which get filled in by this method
[out]*found- number of devices found on this bus
ATCA_STATUS hal_kit_hid_idle ( ATCAIface  iface)

Call the idle for kit protocol.

Parameters
[in]ifaceATCAIface instance that is the interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_init ( void *  hal,
ATCAIfaceCfg cfg 
)

HAL implementation of Kit USB HID init.

Parameters
[in]halpointer to HAL specific data that is maintained by this HAL
[in]cfgpointer to HAL specific configuration data that is used to initialize this HAL
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_post_init ( ATCAIface  iface)

HAL implementation of Kit HID post init.

Parameters
[in]ifaceinstance
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_receive ( ATCAIface  iface,
uint8_t *  rxdata,
uint16_t *  rxsize 
)

HAL implementation of send over USB HID.

Parameters
[in]ifaceinstance
[in]rxdatapointer to space to receive the data
[in,out]rxsizeptr to expected number of receive bytes to request
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_release ( void *  hal_data)

Close the physical port for HID.

Parameters
[in]hal_dataThe hardware abstraction data specific to this HAL
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_send ( ATCAIface  iface,
uint8_t *  txdata,
int  txlength 
)

HAL implementation of kit protocol send over USB HID.

Parameters
[in]ifaceinstance
[in]txdatapointer to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_sleep ( ATCAIface  iface)

Call the sleep for kit protocol.

Parameters
[in]ifaceATCAIface instance that is the interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_hid_wake ( ATCAIface  iface)

Call the wake for kit protocol.

Parameters
[in]ifaceATCAIface instance that is the interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS hal_kit_phy_num_found ( int8_t *  num_found)

Number of USB CDC devices found.

Parameters
[out]num_found
Returns
ATCA_STATUS
ATCA_STATUS hal_swi_discover_buses ( int  swi_buses[],
int  max_buses 
)

discover swi buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge

Parameters
[in]swi_buses- an array of logical bus numbers
[in]max_buses- maximum number of buses the app wants to attempt to discover
ATCA_STATUS hal_swi_discover_devices ( int  busNum,
ATCAIfaceCfg  cfg[],
int *  found 
)

discover any CryptoAuth devices on a given logical bus number

Parameters
[in]busNum- logical bus number on which to look for CryptoAuth devices
[out]cfg[]- pointer to head of an array of interface config structures which get filled in by this method
[out]*found- number of devices found on this bus

default configuration, to be reused during discovery process

ATCA_STATUS hal_swi_idle ( ATCAIface  iface)

Send Idle flag via SWI.

idle CryptoAuth device using SWI interface

Parameters
[in]ifaceinterface of the logical device to idle
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to idle

Set SWI pin

ATCA_STATUS hal_swi_init ( void *  hal,
ATCAIfaceCfg cfg 
)

hal_swi_init manages requests to initialize a physical interface. It manages use counts so when an interface has released the physical layer, it will disable the interface for some other use. You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on multiple swi buses, so hal_swi_init manages these things and ATCAIFace is abstracted from the physical details.

hal_swi_init manages requests to initialize a physical interface. it manages use counts so when an interface has released the physical layer, it will disable the interface for some other use. You can have multiple ATCAIFace instances using the same bus, and you can have multiple ATCAIFace instances on multiple swi buses, so hal_swi_init manages these things and ATCAIFace is abstracted from the physical details.

Initialize an SWI interface using given config.

Parameters
[in]halopaque pointer to HAL data
[in]cfginterface configuration
Returns
ATCA_STATUS

initialize an SWI interface using given config

Parameters
[in]hal- opaque ptr to HAL data
[in]cfg- interface configuration

< 0-based logical bus number

< power up state, no swi buses will have been used

< total across buses

if this is the first time this bus and interface has been created, do the physical work of enabling it

assign GPIO pin

store this for use during the release phase

otherwise, another interface already initialized the bus, any different cfg parameters will be ignored...first one to initialize this sets the configuration

ATCA_STATUS hal_swi_post_init ( ATCAIface  iface)

HAL implementation of SWI post init.

Parameters
[in]ifaceATCAIface instance
Returns
ATCA_STATUS
Parameters
[in]ifaceinstance
Returns
ATCA_STATUS
ATCA_STATUS hal_swi_receive ( ATCAIface  iface,
uint8_t *  rxdata,
uint16_t *  rxlength 
)

Receive byte(s) via SWI.

HAL implementation of SWI receive function over UART.

Parameters
[in]ifaceinterface of the logical device to receive data from
[in]rxdatapointer to where bytes will be received
[in]rxlengthpointer to expected number of receive bytes to request
Returns
ATCA_STATUS
Parameters
[in]ifaceinstance
[in]rxdatapointer to space to receive the data
[in]rxlengthptr to expected number of receive bytes to request
Returns
ATCA_STATUS

Set SWI pin

ATCA_STATUS hal_swi_release ( void *  hal_data)

Manages reference count on given bus and releases resource if no more reference(s) exist.

manages reference count on given bus and releases resource if no more refences exist

Parameters
[in]hal_dataopaque pointer to hal data structure - known only to the HAL implementation
Returns
ATCA_STATUS
Parameters
[in]hal_data- opaque pointer to hal data structure - known only to the HAL implementation

< track total SWI instances

if the use count for this bus has gone to 0 references, disable it. protect against an unbracketed release

ATCA_STATUS hal_swi_send ( ATCAIface  iface,
uint8_t *  txdata,
int  txlength 
)

Send byte(s) via SWI.

HAL implementation of SWI send command over UART.

Parameters
[in]ifaceinterface of the logical device to send data to
[in]txdatapointer to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS
Parameters
[in]ifaceinstance
[in]txdatapointer to space to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS

Skip the Word Address data as SWI doesn't use it

Set SWI pin

Send Command Flag

Send the remaining bytes

ATCA_STATUS hal_swi_send_flag ( ATCAIface  iface,
uint8_t  data 
)

HAL implementation of SWI send one byte over UART.

Parameters
[in]ifaceinstance
[in]databytes to send
Returns
ATCA_STATUS
ATCA_STATUS hal_swi_sleep ( ATCAIface  iface)

Send Sleep flag via SWI.

sleep CryptoAuth device using SWI interface

Parameters
[in]ifaceinterface of the logical device to sleep
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to sleep

Set SWI pin

ATCA_STATUS hal_swi_wake ( ATCAIface  iface)

Send Wake flag via SWI.

wake up CryptoAuth device using SWI interface

Parameters
[in]ifaceinterface of the logical device to wake up
Returns
ATCA_STATUS
Parameters
[in]ifaceinterface to logical device to wakeup

Set SWI pin

Generate Wake Token

Wait tWHI + tWLO

Compare response with expected_response

ATCA_STATUS kit_idle ( ATCAIface  iface)

Call the idle for kit protocol.

Parameters
[in]ifacethe interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS kit_init ( ATCAIface  iface)

HAL implementation of kit protocol init. This function calls back to the physical protocol to send the bytes.

Parameters
[in]ifaceinstance
Returns
ATCA_STATUS
ATCA_STATUS kit_parse_rsp ( char *  pkitbuf,
int  nkitbuf,
uint8_t *  kitstatus,
uint8_t *  rxdata,
int *  datasize 
)

Parse the response ascii from the kit.

Parameters
[out]pkitbufpointer to ascii kit protocol data to parse
[in]nkitbuflength of the ascii kit protocol data
[in]rxdatapointer to the binary data buffer
[in]datasizesize of the pointer to the binary data buffer
Returns
ATCA_STATUS
ATCA_STATUS kit_phy_num_found ( int8_t *  num_found)

Number of USB HID devices found.

Parameters
[out]num_found
Returns
ATCA_STATUS
ATCA_STATUS kit_phy_receive ( ATCAIface  iface,
uint8_t *  rxdata,
int *  rxsize 
)

HAL implementation of kit protocol send over USB CDC.

HAL implementation of kit protocol send over USB HID.

Parameters
[in]ifaceinstance
[out]rxdatapointer to space to receive the data
[in,out]rxsizeptr to expected number of receive bytes to request
Returns
ATCA_STATUS
ATCA_STATUS kit_phy_send ( ATCAIface  iface,
uint8_t *  txdata,
int  txlength 
)

HAL implementation of send over USB CDC.

HAL implementation of send over USB HID.

Parameters
[in]ifaceinstance
[in]txdatapointer to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS
ATCA_STATUS kit_receive ( ATCAIface  iface,
uint8_t *  rxdata,
uint16_t *  rxsize 
)

HAL implementation to receive bytes and unwrap from kit protocol. This function calls back to the physical protocol to receive the bytes.

Parameters
[in]ifaceinstance
[in]rxdatapointer to space to receive the data
[in,out]rxsizeptr to expected number of receive bytes to request
Returns
ATCA_STATUS
ATCA_STATUS kit_send ( ATCAIface  iface,
uint8_t *  txdata,
int  txlength 
)

HAL implementation of kit protocol send. This function calls back to the physical protocol to send the bytes.

Parameters
[in]ifaceinstance
[in]txdatapointer to bytes to send
[in]txlengthnumber of bytes to send
Returns
ATCA_STATUS
ATCA_STATUS kit_sleep ( ATCAIface  iface)

Call the sleep for kit protocol.

Parameters
[in]ifacethe interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS kit_wake ( ATCAIface  iface)

Call the wake for kit protocol.

Parameters
[in]ifacethe interface object to send the bytes over
Returns
ATCA_STATUS
ATCA_STATUS kit_wrap_cmd ( uint8_t *  txdata,
int  txlen,
char *  pkitcmd,
int *  nkitcmd 
)

Wrap binary bytes in ascii kit protocol.

Parameters
[in]txdatapointer to the binary data to wrap
[in]txlenlength of the binary data to wrap
[out]pkitcmdpointer to binary data converted to ascii kit protocol
[in,out]nkitcmdpointer to the size of the binary data converted to ascii kit protocol
Returns
ATCA_STATUS
ATCA_STATUS swi_uart_deinit ( ATCASWIMaster_t instance)

Implementation of SWI UART deinit.

HAL implementation of SWI UART deinit.

Parameters
[in]instanceinstance
Returns
ATCA_STATUS
void swi_uart_discover_buses ( int  swi_uart_buses[],
int  max_buses 
)

discover UART buses available for this hardware this maintains a list of logical to physical bus mappings freeing the application of the a-priori knowledge

Parameters
[in]swi_uart_buses- an array of logical bus numbers
[in]max_buses- maximum number of buses the app wants to attempt to discover
ATCA_STATUS swi_uart_init ( ATCASWIMaster_t instance)

Implementation of SWI UART init.

HAL implementation of SWI UART init.

Parameters
[in]instanceinstance
Returns
ATCA_STATUS
void swi_uart_mode ( ATCASWIMaster_t instance,
uint8_t  mode 
)

implementation of SWI UART change mode.

HAL implementation of SWI UART change mode.

Parameters
[in]instanceinstance
[in]mode(TRANSMIT_MODE or RECEIVE_MODE)
ATCA_STATUS swi_uart_receive_byte ( ATCASWIMaster_t instance,
uint8_t *  data 
)

HAL implementation of SWI UART receive bytes over ASF. This function receive one byte over UART.

Parameters
[in]instanceinstance
[in,out]datapointer to space to receive the data
Returns
ATCA_STATUS
ATCA_STATUS swi_uart_send_byte ( ATCASWIMaster_t instance,
uint8_t  data 
)

HAL implementation of SWI UART send byte over ASF. This function send one byte over UART.

Parameters
[in]instanceinstance
[in]databyte to send
Returns
ATCA_STATUS
void swi_uart_setbaud ( ATCASWIMaster_t instance,
uint32_t  baudrate 
)

implementation of SWI UART change baudrate.

HAL implementation of SWI UART change baudrate.

Parameters
[in]instanceinstance
[in]baudrate(typically 230400 , 160000 or 115200)
[in]instanceinstance
[in]baudrate(typically 230400 or 115200)

Variable Documentation

atcacdc_t _gCdc
atcahid_t _gHid
char* dev = "/dev/ttyACM0"

HAL implementation of Kit USB CDC init.

this discovery assumes a udev rule is active which renames the ATCK101 CDC device as a ttyATCAn the udev rule is:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2122", MODE:="0777", SYMLINK+="ttyATCA%n"

Parameters
[in]halpointer to HAL specific data that is maintained by this HAL
[in]cfgpointer to HAL specific configuration data that is used to initialize this HAL
Returns
ATCA_STATUS
int i2c_bus_ref_ct = 0

total in-use count across buses

int i2c_bus_ref_ct = 0
int i2c_bus_ref_ct = 0
int i2c_bus_ref_ct = 0
int i2c_bus_ref_ct = 0
int i2c_bus_ref_ct = 0

Logical to physical bus mapping structure.

map logical, 0-based bus number to index

logical to physical bus mapping structure

logical to physical bus mapping structure

logical to physical bus mapping structure

Logical to physical bus mapping structure.

twi_master_options_t opt_twi_master
struct port_config pin_conf
int speed = B115200
int swi_bus_ref_ct = 0
int swi_bus_ref_ct = 0

total in-use count across buses

logical to physical bus mapping structure

Logical to physical bus mapping structure.

map logical, 0-based bus number to index