CryptoAuthLib
Microchip CryptoAuthentication Library
atca_hal.h
Go to the documentation of this file.
1 
29 #ifndef ATCA_HAL_H_
30 #define ATCA_HAL_H_
31 
32 #include "atca_status.h"
33 #include "atca_iface.h"
34 #include "atca_start_config.h"
35 #include "atca_start_iface.h"
36 
49 typedef struct
50 {
51  // interface is a group of function pointers to a specific HAL implementation for this interface type
52  // so these function pointers are initialized in the HAL layer in order to help keep the ATCAIface object
53  // from needing to know the low-level details, including global naming of HAL methods and physical implementation.
54  ATCA_STATUS (*halinit)(void *hal, ATCAIfaceCfg *cfg);
55  ATCA_STATUS (*halpostinit)(ATCAIface iface);
56  ATCA_STATUS (*halsend)(ATCAIface iface, uint8_t *txdata, int txlength);
57  ATCA_STATUS (*halreceive)(ATCAIface iface, uint8_t* rxdata, uint16_t* rxlength);
58  ATCA_STATUS (*halwake)(ATCAIface iface);
59  ATCA_STATUS (*halidle)(ATCAIface iface);
60  ATCA_STATUS (*halsleep)(ATCAIface iface);
61  ATCA_STATUS (*halrelease)(void* hal_data);
62 
63  void *hal_data; // points to whatever the HAL implementation for this interface wants it to, HAL manages.
64 } ATCAHAL_t;
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
71 extern ATCA_STATUS hal_iface_release(ATCAIfaceType, void* hal_data);
72 
73 ATCA_STATUS hal_check_wake(const uint8_t* response, int response_size);
74 
75 // Added one or more of the following defines to your compiler's defines to include add support for
76 // that particular interface in your application. For example, if you're writing an I2C to SWI
77 // bridge, add both ATCA_HAL_I2C and ATCA_HAL_SWI defines to your compiler settings and then
78 // include implementations for both interfaces in the HAL.
79 
80 // At least one of these symbols will be defined in the project or makefile for each application
81 //#define ATCA_HAL_I2C
82 //#define ATCA_HAL_SWI
83 //#define ATCA_HAL_SPI
84 //#define ATCA_HAL_UART
85 //#define ATCA_HAL_KIT_HID
86 //#define ATCA_HAL_KIT_CDC
87 
88 // forward declare known physical layer APIs that must be implemented by the HAL layer (./hal/xyz) for this interface type
89 
90 #ifdef ATCA_HAL_I2C
91 ATCA_STATUS hal_i2c_init(void *hal, ATCAIfaceCfg *cfg);
93 ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength);
94 ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
98 ATCA_STATUS hal_i2c_release(void *hal_data);
99 ATCA_STATUS hal_i2c_discover_buses(int i2c_buses[], int max_buses);
100 ATCA_STATUS hal_i2c_discover_devices(int bus_num, ATCAIfaceCfg *cfg, int *found);
101 #endif
102 
103 #ifdef ATCA_HAL_SWI
104 ATCA_STATUS hal_swi_init(void *hal, ATCAIfaceCfg *cfg);
106 ATCA_STATUS hal_swi_send(ATCAIface iface, uint8_t *txdata, int txlength);
107 ATCA_STATUS hal_swi_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
111 ATCA_STATUS hal_swi_release(void *hal_data);
112 ATCA_STATUS hal_swi_discover_buses(int swi_buses[], int max_buses);
113 ATCA_STATUS hal_swi_discover_devices(int bus_num, ATCAIfaceCfg *cfg, int *found);
114 #endif
115 
116 #ifdef ATCA_HAL_UART
117 ATCA_STATUS hal_uart_init(void *hal, ATCAIfaceCfg *cfg);
118 ATCA_STATUS hal_uart_post_init(ATCAIface iface);
119 ATCA_STATUS hal_uart_send(ATCAIface iface, uint8_t *txdata, int txlength);
120 ATCA_STATUS hal_uart_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
121 ATCA_STATUS hal_uart_wake(ATCAIface iface);
122 ATCA_STATUS hal_uart_idle(ATCAIface iface);
123 ATCA_STATUS hal_uart_sleep(ATCAIface iface);
124 ATCA_STATUS hal_uart_release(ATCAIface iface);
125 ATCA_STATUS hal_uart_discover_buses(int uart_buses[], int max_buses);
126 ATCA_STATUS hal_uart_discover_devices(int bus_num, ATCAIfaceCfg *cfg, int *found);
127 #endif
128 
129 #ifdef ATCA_HAL_KIT_CDC
130 ATCA_STATUS hal_kit_cdc_init(void *hal, ATCAIfaceCfg *cfg);
132 ATCA_STATUS hal_kit_cdc_send(ATCAIface iface, uint8_t *txdata, int txlength);
133 ATCA_STATUS hal_kit_cdc_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
137 ATCA_STATUS hal_kit_cdc_release(void *hal_data);
138 ATCA_STATUS hal_kit_cdc_discover_buses(int cdc_buses[], int max_buses);
139 ATCA_STATUS hal_kit_cdc_discover_devices(int bus_num, ATCAIfaceCfg *cfg, int *found);
140 #endif
141 
142 #ifdef ATCA_HAL_KIT_HID
143 ATCA_STATUS hal_kit_hid_init(void *hal, ATCAIfaceCfg *cfg);
145 ATCA_STATUS hal_kit_hid_send(ATCAIface iface, uint8_t *txdata, int txlength);
146 ATCA_STATUS hal_kit_hid_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength);
150 ATCA_STATUS hal_kit_hid_release(void *hal_data);
151 ATCA_STATUS hal_kit_hid_discover_buses(int hid_buses[], int max_buses);
152 ATCA_STATUS hal_kit_hid_discover_devices(int bus_num, ATCAIfaceCfg *cfg, int *found);
153 #endif
154 
156 void atca_delay_us(uint32_t delay);
157 void atca_delay_10us(uint32_t delay);
158 void atca_delay_ms(uint32_t delay);
159 
161 ATCA_STATUS hal_create_mutex(void ** ppMutex, char* pName);
162 ATCA_STATUS hal_destroy_mutex(void * pMutex);
163 ATCA_STATUS hal_lock_mutex(void * pMutex);
164 ATCA_STATUS hal_unlock_mutex(void * pMutex);
165 
167 #ifdef ATCA_USE_RTOS_TIMER
168 void atca_delay_ms_internal(uint32_t delay);
169 #endif
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
177 #endif /* ATCA_HAL_H_ */
ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface)
HAL implementation of Kit HID post init.
Definition: hal_all_platforms_kit_hidapi.c:150
ATCA_STATUS hal_i2c_wake(ATCAIface iface)
wake up CryptoAuth device using I2C bus
Definition: hal_at90usb1287_i2c_asf.c:392
ATCA_STATUS hal_swi_idle(ATCAIface iface)
Send Idle flag via SWI.
Definition: hal_swi_bitbang.c:239
Definition: atca_iface.h:66
ATCA_STATUS hal_i2c_post_init(ATCAIface iface)
HAL implementation of I2C post init.
Definition: hal_at90usb1287_i2c_asf.c:254
ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength)
HAL implementation of I2C send over ASF.
Definition: hal_at90usb1287_i2c_asf.c:266
ATCA_STATUS hal_i2c_init(void *hal, ATCAIfaceCfg *cfg)
initialize an I2C interface using given config
Definition: hal_at90usb1287_i2c_asf.c:215
ATCA_STATUS hal_swi_sleep(ATCAIface iface)
Send Sleep flag via SWI.
Definition: hal_swi_bitbang.c:258
ATCA_STATUS
Definition: atca_status.h:41
ATCA_STATUS hal_kit_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 mappi...
Definition: hal_linux_kit_cdc.c:406
ATCA_STATUS hal_kit_hid_wake(ATCAIface iface)
Call the wake for kit protocol.
Definition: hal_all_platforms_kit_hidapi.c:341
ATCA_STATUS hal_lock_mutex(void *pMutex)
Definition: hal_freertos.c:100
ATCA_STATUS hal_swi_send(ATCAIface iface, uint8_t *txdata, int txlength)
Send byte(s) via SWI.
Definition: hal_swi_bitbang.c:141
void atca_delay_10us(uint32_t delay)
This function delays for a number of tens of microseconds.
Definition: hal_at90usb1287_timer_asf.c:54
ATCA_STATUS hal_swi_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *found)
discover any CryptoAuth devices on a given logical bus number.This function is curently not supported...
Definition: hal_swi_bitbang.c:65
ATCA_STATUS hal_kit_cdc_wake(ATCAIface iface)
Call the wake for kit protocol over USB CDC.
Definition: hal_linux_kit_cdc.c:340
ATCAIfaceType
Definition: atca_iface.h:44
ATCA_STATUS hal_kit_cdc_post_init(ATCAIface iface)
HAL implementation of Kit USB CDC post init.
Definition: hal_linux_kit_cdc.c:167
ATCA_STATUS hal_swi_post_init(ATCAIface iface)
HAL implementation of SWI post init.
Definition: hal_swi_bitbang.c:128
ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)
HAL implementation of I2C receive function for ASF I2C.
Definition: hal_at90usb1287_i2c_asf.c:302
ATCA_STATUS hal_i2c_sleep(ATCAIface iface)
sleep CryptoAuth device using I2C bus
Definition: hal_at90usb1287_i2c_asf.c:476
ATCA_STATUS hal_kit_cdc_discover_devices(int bus_num, ATCAIfaceCfg *cfg, int *found)
discover any CryptoAuth devices on a given logical bus number
Definition: hal_linux_kit_cdc.c:419
ATCA_STATUS hal_kit_cdc_init(void *hal, ATCAIfaceCfg *cfg)
HAL implementation of Kit USB CDC init.
Definition: hal_linux_kit_cdc.c:102
ATCA_STATUS hal_kit_hid_sleep(ATCAIface iface)
Call the sleep for kit protocol.
Definition: hal_all_platforms_kit_hidapi.c:361
void atca_delay_ms(uint32_t delay)
This function delays for a number of milliseconds.
Definition: hal_at90usb1287_timer_asf.c:69
ATCA_STATUS hal_swi_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength)
Receive byte(s) via SWI.
Definition: hal_swi_bitbang.c:167
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_bitbang.c:54
void * hal_data
Definition: atca_hal.h:63
ATCA_STATUS hal_kit_cdc_idle(ATCAIface iface)
Call the idle for kit protocol over USB CDC.
Definition: hal_linux_kit_cdc.c:350
ATCA_STATUS hal_swi_wake(ATCAIface iface)
Send Wake flag via SWI.
Definition: hal_swi_bitbang.c:207
ATCA_STATUS hal_kit_hid_idle(ATCAIface iface)
Call the idle for kit protocol.
Definition: hal_all_platforms_kit_hidapi.c:351
ATCA_STATUS hal_kit_cdc_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
HAL implementation of kit protocol receive over USB CDC.
Definition: hal_linux_kit_cdc.c:330
ATCA_STATUS hal_i2c_release(void *hal_data)
manages reference count on given bus and releases resource if no more refences exist ...
Definition: hal_at90usb1287_i2c_asf.c:503
ATCA_STATUS hal_kit_hid_send(ATCAIface iface, uint8_t *txdata, int txlength)
HAL implementation of kit protocol send over USB HID.
Definition: hal_all_platforms_kit_hidapi.c:319
an intermediary data structure to allow the HAL layer to point the standard API functions used by the...
Definition: atca_hal.h:49
ATCA_STATUS hal_i2c_idle(ATCAIface iface)
idle CryptoAuth device using I2C bus
Definition: hal_at90usb1287_i2c_asf.c:448
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:279
ATCA_STATUS hal_i2c_discover_buses(int i2c_buses[], int max_buses)
discover i2c buses available for this hardware this maintains a list of logical to physical bus mappi...
Definition: hal_at90usb1287_i2c_asf.c:61
Microchip Crypto Auth hardware interface object.
ATCA_STATUS hal_kit_cdc_sleep(ATCAIface iface)
Call the sleep for kit protocol over USB CDC.
Definition: hal_linux_kit_cdc.c:360
ATCA_STATUS hal_unlock_mutex(void *pMutex)
Definition: hal_freertos.c:117
ATCA_STATUS hal_check_wake(const uint8_t *response, int response_size)
Utility function for hal_wake to check the reply.
Definition: atca_hal.c:203
ATCA_STATUS hal_iface_init(ATCAIfaceCfg *, ATCAHAL_t *hal)
Standard HAL API for ATCA to initialize a physical interface.
Definition: atca_hal.c:44
ATCA_STATUS hal_kit_hid_init(void *hal, ATCAIfaceCfg *cfg)
HAL implementation of Kit USB HID init.
Definition: hal_all_platforms_kit_hidapi.c:76
atca_iface is the C object backing ATCAIface. See the atca_iface.h file for details on the ATCAIface ...
Definition: atca_iface.h:129
ATCA_STATUS hal_kit_cdc_release(void *hal_data)
Close the physical port for CDC over USB CDC.
Definition: hal_linux_kit_cdc.c:370
ATCA_STATUS hal_iface_release(ATCAIfaceType, void *hal_data)
releases a physical interface, HAL knows how to interpret hal_data
Definition: atca_hal.c:149
ATCA_STATUS hal_kit_hid_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *found)
discover any CryptoAuth devices on a given logical bus number
Definition: hal_all_platforms_kit_hidapi.c:66
ATCA_STATUS hal_kit_hid_receive(ATCAIface iface, uint8_t *rxdata, uint16_t *rxsize)
HAL implementation of send over USB HID.
Definition: hal_all_platforms_kit_hidapi.c:331
Microchip Crypto Auth status codes.
ATCA_STATUS hal_kit_hid_release(void *hal_data)
Close the physical port for HID.
Definition: hal_all_platforms_kit_hidapi.c:371
ATCA_STATUS hal_destroy_mutex(void *pMutex)
Definition: hal_freertos.c:88
ATCA_STATUS hal_create_mutex(void **ppMutex, char *pName)
Optional hal interfaces.
Definition: hal_freertos.c:69
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:88
ATCA_STATUS hal_kit_hid_discover_buses(int i2c_buses[], int max_buses)
discover cdc buses available for this hardware this maintains a list of logical to physical bus mappi...
Definition: hal_all_platforms_kit_hidapi.c:56
ATCA_STATUS hal_i2c_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *found)
discover any CryptoAuth devices on a given logical bus number
Definition: hal_at90usb1287_i2c_asf.c:82
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:317
void atca_delay_us(uint32_t delay)
Timer API implemented at the HAL level.
Definition: hal_at90usb1287_timer_asf.c:44