CryptoAuthLib
Atmel CryptoAuthentication Library
atca_hal.h
Go to the documentation of this file.
1 
43 #ifndef ATCA_HAL_H_
44 #define ATCA_HAL_H_
45 
46 #include "atca_status.h"
47 #include "atca_iface.h"
48 #include "atca_start_config.h"
49 #include "atca_start_iface.h"
50 
63 typedef struct {
64  // interface is a group of function pointers to a specific HAL implementation for this interface type
65  // so these function pointers are initialized in the HAL layer in order to help keep the ATCAIface object
66  // from needing to know the low-level details, including global naming of HAL methods and physical implementation.
67  ATCA_STATUS (*halinit)(void *hal, ATCAIfaceCfg *cfg);
68  ATCA_STATUS (*halpostinit)(ATCAIface iface);
69  ATCA_STATUS (*halsend)(ATCAIface iface, uint8_t *txdata, int txlength);
70  ATCA_STATUS (*halreceive)(ATCAIface iface, uint8_t* rxdata, uint16_t* rxlength);
71  ATCA_STATUS (*halwake)(ATCAIface iface);
72  ATCA_STATUS (*halidle)(ATCAIface iface);
73  ATCA_STATUS (*halsleep)(ATCAIface iface);
74  ATCA_STATUS (*halrelease)(void* hal_data);
75 
76  void *hal_data; // points to whatever the HAL implementation for this interface wants it to, HAL manages.
77 } ATCAHAL_t;
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
84 extern ATCA_STATUS hal_iface_release(ATCAIfaceType, void* hal_data);
85 
86 // Added one or more of the following defines to your compiler's defines to include add support for
87 // that particular interface in your application. For example, if you're writing an I2C to SWI
88 // bridge, add both ATCA_HAL_I2C and ATCA_HAL_SWI defines to your compiler settings and then
89 // include implementations for both interfaces in the HAL.
90 
91 // At least one of these symbols will be defined in the project or makefile for each application
92 //#define ATCA_HAL_I2C
93 //#define ATCA_HAL_SWI
94 //#define ATCA_HAL_SPI
95 //#define ATCA_HAL_UART
96 //#define ATCA_HAL_KIT_HID
97 //#define ATCA_HAL_KIT_CDC
98 
99 // forward declare known physical layer APIs that must be implemented by the HAL layer (./hal/xyz) for this interface type
100 
101 #ifdef ATCA_HAL_I2C
102 ATCA_STATUS hal_i2c_init( void *hal, ATCAIfaceCfg *cfg);
104 ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength);
105 ATCA_STATUS hal_i2c_receive( ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
109 ATCA_STATUS hal_i2c_release(void *hal_data );
110 ATCA_STATUS hal_i2c_discover_buses(int i2c_buses[], int max_buses);
111 ATCA_STATUS hal_i2c_discover_devices(int busNum, ATCAIfaceCfg *cfg, int *found );
112 #endif
113 
114 #ifdef ATCA_HAL_SWI
115 ATCA_STATUS hal_swi_init(void *hal, ATCAIfaceCfg *cfg);
117 ATCA_STATUS hal_swi_send(ATCAIface iface, uint8_t *txdata, int txlength);
118 ATCA_STATUS hal_swi_receive( ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
122 ATCA_STATUS hal_swi_release(void *hal_data );
123 ATCA_STATUS hal_swi_discover_buses(int swi_buses[], int max_buses);
124 ATCA_STATUS hal_swi_discover_devices(int busNum, ATCAIfaceCfg *cfg, int *found);
125 #endif
126 
127 #ifdef ATCA_HAL_UART
128 ATCA_STATUS hal_uart_init(void *hal, ATCAIfaceCfg *cfg);
129 ATCA_STATUS hal_uart_post_init(ATCAIface iface);
130 ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t *txdata, int txlength);
131 ATCA_STATUS hal_uart_receive( ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
132 ATCA_STATUS hal_uart_wake(ATCAIface iface);
133 ATCA_STATUS hal_uart_idle(ATCAIface iface);
134 ATCA_STATUS hal_uart_sleep(ATCAIface iface);
135 ATCA_STATUS hal_uart_release(ATCAIface iface);
136 ATCA_STATUS hal_uart_discover_buses(int uart_buses[], int max_buses);
137 ATCA_STATUS hal_uart_discover_devices(int busNum, ATCAIfaceCfg *cfg, int *found);
138 #endif
139 
140 #ifdef ATCA_HAL_KIT_CDC
141 ATCA_STATUS hal_kit_cdc_init(void *hal, ATCAIfaceCfg *cfg);
143 ATCA_STATUS hal_kit_cdc_send(ATCAIface iface, uint8_t *txdata, int txlength);
144 ATCA_STATUS hal_kit_cdc_receive( ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
148 ATCA_STATUS hal_kit_cdc_release(void *hal_data);
149 ATCA_STATUS hal_kit_cdc_discover_buses(int i2c_buses[], int max_buses);
150 ATCA_STATUS hal_kit_cdc_discover_devices(int busNum, ATCAIfaceCfg *cfg, int *found);
151 #endif
152 
153 #ifdef ATCA_HAL_KIT_HID
154 ATCA_STATUS hal_kit_hid_init(void *hal, ATCAIfaceCfg *cfg);
156 ATCA_STATUS hal_kit_hid_send(ATCAIface iface, uint8_t *txdata, int txlength);
157 ATCA_STATUS hal_kit_hid_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
161 ATCA_STATUS hal_kit_hid_release(void *hal_data);
162 ATCA_STATUS hal_kit_hid_discover_buses(int i2c_buses[], int max_buses);
163 ATCA_STATUS hal_kit_hid_discover_devices(int busNum, ATCAIfaceCfg *cfg, int *found);
164 #endif
165 
167 void atca_delay_us(uint32_t delay);
168 void atca_delay_10us(uint32_t delay);
169 void atca_delay_ms(uint32_t delay);
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
177 #endif /* ATCA_HAL_H_ */
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 s...
Definition: hal_at88ck9000_timer.c:79
ATCA_STATUS hal_i2c_wake(ATCAIface iface)
Send Wake flag via I2C.
Definition: hal_i2c_bitbang.c:270
void * hal_data
Definition: atca_hal.h:76
ATCA_STATUS hal_kit_hid_sleep(ATCAIface iface)
Call the sleep for kit protocol.
Definition: hal_win_kit_hid.c:390
ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface)
HAL implementation of Kit HID post init.
Definition: hal_win_kit_hid.c:202
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 in...
Definition: hal_swi_bitbang.c:81
ATCA_STATUS hal_kit_cdc_init(void *hal, ATCAIfaceCfg *cfg)
Definition: hal_linux_kit_cdc.c:111
ATCA_STATUS hal_kit_cdc_discover_buses(int i2c_buses[], int max_buses)
Definition: hal_linux_kit_cdc.c:382
Definition: atca_iface.h:74
ATCA_STATUS hal_i2c_discover_devices(int busNum, ATCAIfaceCfg cfg[], int *found)
discover any CryptoAuth devices on a given logical bus number
Definition: hal_sam4s_i2c_asf.c:117
ATCA_STATUS hal_kit_cdc_release(void *hal_data)
Close the physical port for CDC.
Definition: hal_linux_kit_cdc.c:359
ATCA_STATUS hal_i2c_release(void *hal_data)
Manages reference count on given bus and releases resource if no more reference(s) exist...
Definition: hal_i2c_bitbang.c:370
ATCA_STATUS hal_iface_init(ATCAIfaceCfg *, ATCAHAL_t *hal)
Standard HAL API for ATCA to initialize a physical interface.
Definition: atca_hal.c:57
ATCA_STATUS hal_kit_cdc_idle(ATCAIface iface)
Call the idle for kit protocol.
Definition: hal_linux_kit_cdc.c:339
void atca_delay_us(uint32_t delay)
Timer API implemented at the HAL level.
Definition: hal_at88ck9000_timer.c:53
ATCA_STATUS hal_swi_idle(ATCAIface iface)
Send Idle flag via SWI.
Definition: hal_swi_bitbang.c:265
void atca_delay_10us(uint32_t delay)
This function delays for a number of tens of microseconds.
Definition: hal_at88ck9000_timer.c:64
atca_iface is the C object backing ATCAIface. See the atca_iface.h file for details on the ATCAIface ...
Definition: atca_iface.c:57
ATCA_STATUS hal_kit_cdc_send(ATCAIface iface, uint8_t *txdata, int txlength)
HAL implementation of kit protocol send over USB CDC.
Definition: hal_linux_kit_cdc.c:307
ATCAIfaceType
Definition: atca_iface.h:58
ATCA_STATUS hal_swi_post_init(ATCAIface iface)
HAL implementation of SWI post init.
Definition: hal_swi_bitbang.c:133
ATCA_STATUS hal_swi_send(ATCAIface iface, uint8_t *txdata, int txlength)
Send byte(s) via SWI.
Definition: hal_swi_bitbang.c:147
ATCA_STATUS hal_i2c_idle(ATCAIface iface)
Send Idle flag via I2C.
Definition: hal_i2c_bitbang.c:310
ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength)
Send byte(s) via I2C.
Definition: hal_i2c_bitbang.c:178
an intermediary data structure to allow the HAL layer to point the standard API functions used by the...
Definition: atca_hal.h:63
Atmel Crypto Auth hardware interface object.
ATCA_STATUS hal_kit_hid_idle(ATCAIface iface)
Call the idle for kit protocol.
Definition: hal_win_kit_hid.c:380
ATCA_STATUS hal_kit_hid_wake(ATCAIface iface)
Call the wake for kit protocol.
Definition: hal_win_kit_hid.c:370
ATCA_STATUS hal_kit_cdc_sleep(ATCAIface iface)
Call the sleep for kit protocol.
Definition: hal_linux_kit_cdc.c:349
ATCA_STATUS hal_kit_hid_release(void *hal_data)
Close the physical port for HID.
Definition: hal_win_kit_hid.c:400
ATCA_STATUS hal_kit_hid_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
HAL implementation of send over USB HID.
Definition: hal_win_kit_hid.c:360
Atmel Crypto Auth status codes.
ATCA_STATUS hal_kit_cdc_wake(ATCAIface iface)
Call the wake for kit protocol.
Definition: hal_linux_kit_cdc.c:329
ATCA_STATUS hal_kit_hid_send(ATCAIface iface, uint8_t *txdata, int txlength)
HAL implementation of kit protocol send over USB HID.
Definition: hal_win_kit_hid.c:348
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 mappi...
Definition: hal_swi_uart.c:88
ATCA_STATUS hal_i2c_sleep(ATCAIface iface)
Send Sleep flag via I2C.
Definition: hal_i2c_bitbang.c:339
ATCA_STATUS hal_swi_sleep(ATCAIface iface)
Send Sleep flag via SWI.
Definition: hal_swi_bitbang.c:286
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 in...
Definition: hal_i2c_bitbang.c:108
ATCA_STATUS hal_swi_release(void *hal_data)
Manages reference count on given bus and releases resource if no more reference(s) exist...
Definition: hal_swi_bitbang.c:309
ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)
Receive byte(s) via I2C.
Definition: hal_i2c_bitbang.c:222
ATCA_STATUS hal_swi_discover_devices(int busNum, ATCAIfaceCfg cfg[], int *found)
discover any CryptoAuth devices on a given logical bus number
Definition: hal_swi_uart.c:101
ATCA_STATUS hal_kit_hid_discover_devices(int busNum, ATCAIfaceCfg cfg[], int *found)
discover any CryptoAuth devices on a given logical bus number
Definition: hal_win_kit_hid.c:192
ATCA_STATUS
Definition: atca_status.h:55
ATCA_STATUS hal_kit_hid_init(void *hal, ATCAIfaceCfg *cfg)
HAL implementation of Kit USB HID init.
Definition: hal_win_kit_hid.c:71
ATCA_STATUS hal_kit_cdc_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
HAL implementation of send over USB CDC.
Definition: hal_linux_kit_cdc.c:319
ATCA_STATUS hal_iface_release(ATCAIfaceType, void *hal_data)
releases a physical interface, HAL knows how to interpret hal_data
Definition: atca_hal.c:143
ATCA_STATUS hal_kit_hid_discover_buses(int i2c_buses[], int max_buses)
Definition: hal_win_kit_hid.c:181
ATCA_STATUS hal_i2c_post_init(ATCAIface iface)
HAL implementation of I2C post init.
Definition: hal_i2c_bitbang.c:164
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.
Definition: hal_sam4s_i2c_asf.c:106
ATCA_STATUS hal_swi_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)
Receive byte(s) via SWI.
Definition: hal_swi_bitbang.c:179
ATCA_STATUS hal_kit_cdc_post_init(ATCAIface iface)
HAL implementation of Kit USB CDC post init.
Definition: hal_linux_kit_cdc.c:172
ATCA_STATUS hal_swi_wake(ATCAIface iface)
Send Wake flag via SWI.
Definition: hal_swi_bitbang.c:226
ATCA_STATUS hal_kit_cdc_discover_devices(int busNum, ATCAIfaceCfg *cfg, int *found)
Definition: hal_linux_kit_cdc.c:388