|
1 | 1 | /**
|
2 | 2 | * \file
|
3 |
| - * \brief low-level HAL - methods used to setup indirection to physical layer interface. |
4 |
| - * this level does the dirty work of abstracting the higher level ATCAIFace methods from the |
5 |
| - * low-level physical interfaces. Its main goal is to keep low-level details from bleeding into |
| 3 | + * \brief low-level HAL - methods used to setup indirection to physical layer |
| 4 | + * interface. |
| 5 | + * this level does the dirty work of abstracting the higher level ATCAIFace |
| 6 | + * methods from the |
| 7 | + * low-level physical interfaces. Its main goal is to keep low-level details |
| 8 | + * from bleeding into |
6 | 9 | * the logical interface implemetation.
|
7 | 10 | *
|
8 | 11 | * \copyright (c) 2017 Microchip Technology Inc. and its subsidiaries.
|
|
32 | 35 | * TERMS.
|
33 | 36 | */
|
34 | 37 |
|
| 38 | +/* when incorporating ATCA HAL into your application, you need to adjust the |
| 39 | + * #defines in atca_hal.h to include |
| 40 | + * and exclude appropriate interfaces - this optimizes memory use when not using |
| 41 | + * a specific iface implementation in your application */ |
35 | 42 |
|
36 |
| -/* when incorporating ATCA HAL into your application, you need to adjust the #defines in atca_hal.h to include |
37 |
| - * and exclude appropriate interfaces - this optimizes memory use when not using a specific iface implementation in your application */ |
38 |
| - |
39 |
| -#include "cryptoauthlib.h" |
40 | 43 | #include "atca_hal.h"
|
| 44 | +#include "cryptoauthlib.h" |
| 45 | +#include "hal_i2c_stm32l475.h" |
| 46 | + |
| 47 | +#define ATCA_HAL_I2C |
| 48 | +void atca_delay_us(uint32_t delay) { HAL_Delay(0); } |
| 49 | +void atca_delay_10us(uint32_t delay) { HAL_Delay(0); } |
| 50 | +void atca_delay_ms(uint32_t delay) { HAL_Delay(0); } |
41 | 51 |
|
42 | 52 | /** \brief Standard HAL API for ATCA to initialize a physical interface
|
43 | 53 | * \param[in] cfg pointer to ATCAIfaceCfg object
|
44 | 54 | * \param[in] hal pointer to ATCAHAL_t intermediate data structure
|
45 | 55 | * \return ATCA_SUCCESS on success, otherwise an error code.
|
46 | 56 | */
|
47 | 57 |
|
48 |
| -ATCA_STATUS hal_iface_init(ATCAIfaceCfg *cfg, ATCAHAL_t *hal) |
49 |
| -{ |
50 |
| - // Because C isn't a real object oriented language or dynamically typed, some switch in the overall system is unavoidable |
51 |
| - // The key here is to provide the flexibility to include just the types of interfaces you want/need without breaking the |
52 |
| - // object model. The former is needed so in an embedded, constrained memory environment, you don't have to pay the price |
53 |
| - // (in terms of memory) for interfaces you don't use in your application. |
54 |
| - ATCA_STATUS status = ATCA_COMM_FAIL; |
| 58 | +ATCA_STATUS hal_iface_init(ATCAIfaceCfg *cfg, ATCAHAL_t *hal) { |
| 59 | + // Because C isn't a real object oriented language or dynamically typed, some |
| 60 | + // switch in the overall system is unavoidable |
| 61 | + // The key here is to provide the flexibility to include just the types of |
| 62 | + // interfaces you want/need without breaking the |
| 63 | + // object model. The former is needed so in an embedded, constrained memory |
| 64 | + // environment, you don't have to pay the price |
| 65 | + // (in terms of memory) for interfaces you don't use in your application. |
| 66 | + ATCA_STATUS status = ATCA_COMM_FAIL; |
55 | 67 |
|
56 |
| - switch (cfg->iface_type) |
57 |
| - { |
58 |
| - case ATCA_I2C_IFACE: |
59 |
| - #ifdef ATCA_HAL_I2C |
60 |
| - hal->halinit = &hal_i2c_init; |
61 |
| - hal->halpostinit = &hal_i2c_post_init; |
62 |
| - hal->halreceive = &hal_i2c_receive; |
63 |
| - hal->halsend = &hal_i2c_send; |
64 |
| - hal->halsleep = &hal_i2c_sleep; |
65 |
| - hal->halwake = &hal_i2c_wake; |
66 |
| - hal->halidle = &hal_i2c_idle; |
67 |
| - hal->halrelease = &hal_i2c_release; |
68 |
| - hal->hal_data = NULL; |
| 68 | + switch (cfg->iface_type) { |
| 69 | + case ATCA_I2C_IFACE: |
| 70 | +#ifdef ATCA_HAL_I2C |
| 71 | + hal->halinit = &hal_i2c_init; |
| 72 | + hal->halpostinit = &hal_i2c_post_init; |
| 73 | + hal->halreceive = &hal_i2c_receive; |
| 74 | + hal->halsend = &hal_i2c_send; |
| 75 | + hal->halsleep = &hal_i2c_sleep; |
| 76 | + hal->halwake = &hal_i2c_wake; |
| 77 | + hal->halidle = &hal_i2c_idle; |
| 78 | + hal->halrelease = &hal_i2c_release; |
| 79 | + hal->hal_data = NULL; |
69 | 80 |
|
70 |
| - status = ATCA_SUCCESS; |
71 |
| - #endif |
72 |
| - break; |
73 |
| - case ATCA_SWI_IFACE: |
74 |
| - #ifdef ATCA_HAL_SWI |
75 |
| - hal->halinit = &hal_swi_init; |
76 |
| - hal->halpostinit = &hal_swi_post_init; |
77 |
| - hal->halreceive = &hal_swi_receive; |
78 |
| - hal->halsend = &hal_swi_send; |
79 |
| - hal->halsleep = &hal_swi_sleep; |
80 |
| - hal->halwake = &hal_swi_wake; |
81 |
| - hal->halidle = &hal_swi_idle; |
82 |
| - hal->halrelease = &hal_swi_release; |
83 |
| - hal->hal_data = NULL; |
| 81 | + status = ATCA_SUCCESS; |
| 82 | +#endif |
| 83 | + break; |
| 84 | + case ATCA_SWI_IFACE: |
| 85 | +#ifdef ATCA_HAL_SWI |
| 86 | + hal->halinit = &hal_swi_init; |
| 87 | + hal->halpostinit = &hal_swi_post_init; |
| 88 | + hal->halreceive = &hal_swi_receive; |
| 89 | + hal->halsend = &hal_swi_send; |
| 90 | + hal->halsleep = &hal_swi_sleep; |
| 91 | + hal->halwake = &hal_swi_wake; |
| 92 | + hal->halidle = &hal_swi_idle; |
| 93 | + hal->halrelease = &hal_swi_release; |
| 94 | + hal->hal_data = NULL; |
84 | 95 |
|
85 |
| - status = ATCA_SUCCESS; |
86 |
| - #endif |
87 |
| - break; |
88 |
| - case ATCA_UART_IFACE: |
89 |
| - #ifdef ATCA_HAL_UART |
90 |
| - // TODO - initialize UART iface |
91 |
| - #endif |
92 |
| - #ifdef ATCA_HAL_KIT_CDC |
93 |
| - hal->halinit = &hal_kit_cdc_init; |
94 |
| - hal->halpostinit = &hal_kit_cdc_post_init; |
95 |
| - hal->halreceive = &hal_kit_cdc_receive; |
96 |
| - hal->halsend = &hal_kit_cdc_send; |
97 |
| - hal->halsleep = &hal_kit_cdc_sleep; |
98 |
| - hal->halwake = &hal_kit_cdc_wake; |
99 |
| - hal->halidle = &hal_kit_cdc_idle; |
100 |
| - hal->halrelease = &hal_kit_cdc_release; |
101 |
| - hal->hal_data = NULL; |
| 96 | + status = ATCA_SUCCESS; |
| 97 | +#endif |
| 98 | + break; |
| 99 | + case ATCA_UART_IFACE: |
| 100 | +#ifdef ATCA_HAL_UART |
| 101 | +// TODO - initialize UART iface |
| 102 | +#endif |
| 103 | +#ifdef ATCA_HAL_KIT_CDC |
| 104 | + hal->halinit = &hal_kit_cdc_init; |
| 105 | + hal->halpostinit = &hal_kit_cdc_post_init; |
| 106 | + hal->halreceive = &hal_kit_cdc_receive; |
| 107 | + hal->halsend = &hal_kit_cdc_send; |
| 108 | + hal->halsleep = &hal_kit_cdc_sleep; |
| 109 | + hal->halwake = &hal_kit_cdc_wake; |
| 110 | + hal->halidle = &hal_kit_cdc_idle; |
| 111 | + hal->halrelease = &hal_kit_cdc_release; |
| 112 | + hal->hal_data = NULL; |
102 | 113 |
|
103 |
| - status = ATCA_SUCCESS; |
104 |
| - #endif |
105 |
| - break; |
106 |
| - case ATCA_SPI_IFACE: |
107 |
| - #ifdef ATCA_HAL_SPI |
108 |
| - // TODO - initialize SPI iface |
109 |
| - #endif |
110 |
| - break; |
111 |
| - case ATCA_HID_IFACE: |
112 |
| - #ifdef ATCA_HAL_KIT_HID |
113 |
| - hal->halinit = &hal_kit_hid_init; |
114 |
| - hal->halpostinit = &hal_kit_hid_post_init; |
115 |
| - hal->halreceive = &hal_kit_hid_receive; |
116 |
| - hal->halsend = &hal_kit_hid_send; |
117 |
| - hal->halsleep = &hal_kit_hid_sleep; |
118 |
| - hal->halwake = &hal_kit_hid_wake; |
119 |
| - hal->halidle = &hal_kit_hid_idle; |
120 |
| - hal->halrelease = &hal_kit_hid_release; |
121 |
| - hal->hal_data = NULL; |
| 114 | + status = ATCA_SUCCESS; |
| 115 | +#endif |
| 116 | + break; |
| 117 | + case ATCA_SPI_IFACE: |
| 118 | +#ifdef ATCA_HAL_SPI |
| 119 | +// TODO - initialize SPI iface |
| 120 | +#endif |
| 121 | + break; |
| 122 | + case ATCA_HID_IFACE: |
| 123 | +#ifdef ATCA_HAL_KIT_HID |
| 124 | + hal->halinit = &hal_kit_hid_init; |
| 125 | + hal->halpostinit = &hal_kit_hid_post_init; |
| 126 | + hal->halreceive = &hal_kit_hid_receive; |
| 127 | + hal->halsend = &hal_kit_hid_send; |
| 128 | + hal->halsleep = &hal_kit_hid_sleep; |
| 129 | + hal->halwake = &hal_kit_hid_wake; |
| 130 | + hal->halidle = &hal_kit_hid_idle; |
| 131 | + hal->halrelease = &hal_kit_hid_release; |
| 132 | + hal->hal_data = NULL; |
122 | 133 |
|
123 |
| - status = ATCA_SUCCESS; |
124 |
| - #endif |
125 |
| - break; |
126 |
| - case ATCA_CUSTOM_IFACE: |
127 |
| - #ifdef ATCA_HAL_CUSTOM |
128 |
| - hal->halinit = cfg->atcacustom.halinit; |
129 |
| - hal->halpostinit = cfg->atcacustom.halpostinit; |
130 |
| - hal->halreceive = cfg->atcacustom.halreceive; |
131 |
| - hal->halsend = cfg->atcacustom.halsend; |
132 |
| - hal->halsleep = cfg->atcacustom.halsleep; |
133 |
| - hal->halwake = cfg->atcacustom.halwake; |
134 |
| - hal->halidle = cfg->atcacustom.halidle; |
135 |
| - hal->halrelease = cfg->atcacustom.halrelease; |
136 |
| - hal->hal_data = NULL; |
| 134 | + status = ATCA_SUCCESS; |
| 135 | +#endif |
| 136 | + break; |
| 137 | + case ATCA_CUSTOM_IFACE: |
| 138 | +#ifdef ATCA_HAL_CUSTOM |
| 139 | + hal->halinit = cfg->atcacustom.halinit; |
| 140 | + hal->halpostinit = cfg->atcacustom.halpostinit; |
| 141 | + hal->halreceive = cfg->atcacustom.halreceive; |
| 142 | + hal->halsend = cfg->atcacustom.halsend; |
| 143 | + hal->halsleep = cfg->atcacustom.halsleep; |
| 144 | + hal->halwake = cfg->atcacustom.halwake; |
| 145 | + hal->halidle = cfg->atcacustom.halidle; |
| 146 | + hal->halrelease = cfg->atcacustom.halrelease; |
| 147 | + hal->hal_data = NULL; |
137 | 148 |
|
138 |
| - status = ATCA_SUCCESS; |
139 |
| - #endif |
140 |
| - break; |
141 |
| - default: |
142 |
| - break; |
143 |
| - } |
144 |
| - return status; |
| 149 | + status = ATCA_SUCCESS; |
| 150 | +#endif |
| 151 | + break; |
| 152 | + default: |
| 153 | + break; |
| 154 | + } |
| 155 | + return status; |
145 | 156 | }
|
146 | 157 |
|
147 | 158 | /** \brief releases a physical interface, HAL knows how to interpret hal_data
|
148 | 159 | * \param[in] iface_type - the type of physical interface to release
|
149 |
| - * \param[in] hal_data - pointer to opaque hal data maintained by HAL implementation for this interface type |
| 160 | + * \param[in] hal_data - pointer to opaque hal data maintained by HAL |
| 161 | + * implementation for this interface type |
150 | 162 | * \return ATCA_SUCCESS on success, otherwise an error code.
|
151 | 163 | */
|
152 | 164 |
|
153 |
| -ATCA_STATUS hal_iface_release(ATCAIfaceType iface_type, void *hal_data) |
154 |
| -{ |
155 |
| - ATCA_STATUS status = ATCA_GEN_FAIL; |
| 165 | +ATCA_STATUS hal_iface_release(ATCAIfaceType iface_type, void *hal_data) { |
| 166 | + ATCA_STATUS status = ATCA_GEN_FAIL; |
156 | 167 |
|
157 |
| - switch (iface_type) |
158 |
| - { |
159 |
| - case ATCA_I2C_IFACE: |
| 168 | + switch (iface_type) { |
| 169 | + case ATCA_I2C_IFACE: |
160 | 170 | #ifdef ATCA_HAL_I2C
|
161 |
| - status = hal_i2c_release(hal_data); |
| 171 | + status = hal_i2c_release(hal_data); |
162 | 172 | #endif
|
163 |
| - break; |
164 |
| - case ATCA_SWI_IFACE: |
165 |
| - #ifdef ATCA_HAL_SWI |
166 |
| - status = hal_swi_release(hal_data); |
| 173 | + break; |
| 174 | + case ATCA_SWI_IFACE: |
| 175 | +#ifdef ATCA_HAL_SWI |
| 176 | + status = hal_swi_release(hal_data); |
167 | 177 | #endif
|
168 |
| - break; |
169 |
| - case ATCA_UART_IFACE: |
170 |
| - #ifdef ATCA_HAL_UART |
171 |
| - // TODO - release HAL UART |
| 178 | + break; |
| 179 | + case ATCA_UART_IFACE: |
| 180 | +#ifdef ATCA_HAL_UART |
| 181 | +// TODO - release HAL UART |
172 | 182 | #endif
|
173 | 183 | #ifdef ATCA_HAL_KIT_CDC
|
174 |
| - status = hal_kit_cdc_release(hal_data); |
| 184 | + status = hal_kit_cdc_release(hal_data); |
175 | 185 | #endif
|
176 |
| - break; |
177 |
| - case ATCA_SPI_IFACE: |
| 186 | + break; |
| 187 | + case ATCA_SPI_IFACE: |
178 | 188 | #ifdef ATCA_HAL_SPI
|
179 |
| - // TODO - release HAL SPI |
| 189 | +// TODO - release HAL SPI |
180 | 190 | #endif
|
181 |
| - break; |
182 |
| - case ATCA_HID_IFACE: |
| 191 | + break; |
| 192 | + case ATCA_HID_IFACE: |
183 | 193 | #ifdef ATCA_HAL_KIT_HID
|
184 |
| - status = hal_kit_hid_release(hal_data); |
| 194 | + status = hal_kit_hid_release(hal_data); |
185 | 195 | #endif
|
186 |
| - break; |
187 |
| - case ATCA_CUSTOM_IFACE: |
| 196 | + break; |
| 197 | + case ATCA_CUSTOM_IFACE: |
188 | 198 | #ifdef ATCA_HAL_CUSTOM
|
189 | 199 | #endif
|
190 |
| - break; |
191 |
| - default: |
192 |
| - break; |
193 |
| - } |
| 200 | + break; |
| 201 | + default: |
| 202 | + break; |
| 203 | + } |
194 | 204 |
|
195 |
| - return status; |
| 205 | + return status; |
196 | 206 | }
|
0 commit comments