gr55xx_hal_iso7816.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_hal_iso7816.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of ISO7816 HAL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_ISO7816 ISO7816
47 * @brief ISO7816 HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_ISO7816_H__
53 #define __GR55xx_HAL_ISO7816_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_iso7816.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_ISO7816_ENUMERATIONS Enumerations
65 * @{
66 */
67
68 /** @defgroup HAL_ISO7816_state HAL ISO7816 State
69 * @{
70 */
71 /**
72 * @brief HAL ISO7816 State Enumerations definition
73 */
74 typedef enum
75 {
76 HAL_ISO7816_STATE_RESET = 0x00U, /**< Peripheral not initialized */
77 HAL_ISO7816_STATE_READY = 0x20U, /**< Peripheral initialized and ready for use */
78 HAL_ISO7816_STATE_BUSY = 0x24U, /**< An internal process is ongoing */
79 HAL_ISO7816_STATE_BUSY_TX = 0x21U, /**< Data Transmission process is ongoing */
80 HAL_ISO7816_STATE_BUSY_RX = 0x22U, /**< Data Reception process is ongoing */
81 HAL_ISO7816_STATE_BUSY_TX_RX = 0x23U, /**< Data Transmission and Reception process is ongoing */
82 HAL_ISO7816_STATE_ABORT = 0x08U, /**< Peripheral with abort request ongoing */
83 HAL_ISO7816_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */
84 HAL_ISO7816_STATE_ERROR = 0xE0U /**< Peripheral in error */
85 } hal_iso7816_state_t;
86 /** @} */
87
88 /** @} */
89
90 /** @addtogroup HAL_ISO7816_STRUCTURES Structures
91 * @{
92 */
93
94 /** @defgroup ISO7816_Configuration ISO7816 Configuration
95 * @{
96 */
97 /**
98 * @brief ISO7816_init_structure ISO7816 init structure definition
99 */
100 typedef struct
101 {
102 uint32_t clk_div; /*!< clk_div is used for dividing the system clock,
103 and ISO7816 output clock is equal to (system clock)/(clk_div+1).*/
104 uint32_t wait_time; /*!< Specifies the guard time value in terms of number of baud clocks */
105 uint16_t guard_time; /*!< Specifies the maximum card response time (leading edge to leading edge) */
106 uint8_t detect_coding; /*!< Specifies whether automatically detect coding convention during ATR receiption. */
107 } iso7816_init_t;
108 /** @} */
109 /** @} */
110
111 /** @defgroup HAL_ISO7816_MACRO Defines
112 * @{
113 */
114 /**
115 * @brief ISO7816_default_config InitStruct default configuration
116 */
117 #define ISO7816_DEFAULT_CONFIG \
118 { \
119 .clk_div = 0x2F, \
120 .wait_time = 0x6B, \
121 .guard_time = 0x00, \
122 .detect_coding = ENABLE, \
123 }
124 /** @} */
125
126 /** @addtogroup HAL_ISO7816_STRUCTURES Structures
127 * @{
128 */
129 /** @defgroup ISO7816_handle Handle
130 * @{
131 */
132
133 /**
134 * @brief ISO7816 handle Structure definition
135 */
136 typedef struct _iso7816_handle_t
137 {
138 iso7816_regs_t *p_instance; /**< ISO7816 registers base address */
139 iso7816_init_t init; /**< ISO7816 configuration parameters */
140 uint8_t *p_tx_rx_buffer; /**< Pointer to ISO7816 Tx&Rx transfer Buffer */
141 uint16_t buffer_size; /**< ISO7816 Tx Transfer size */
142 uint16_t tx_xfer_size; /**< ISO7816 Tx Transfer size */
143 __IO uint16_t tx_xfer_count; /**< ISO7816 Tx Transfer Counter */
144 uint16_t rx_xfer_size; /**< ISO7816 Rx Transfer size */
145 __IO uint16_t rx_xfer_count; /**< ISO7816 Rx Transfer Counter */
146 __IO hal_lock_t lock; /**< Locking object */
147 __IO hal_iso7816_state_t state; /**< ISO7816 communication state */
148 __IO hal_iso7816_state_t tx_state; /**< ISO7816 state information related to Tx operations. */
149 __IO hal_iso7816_state_t rx_state; /**< ISO7816 state information related to Rx operations. */
150 __IO uint32_t previous_action; /**< ISO7816 previous_action */
151 __IO uint32_t error_code; /**< ISO7816 error code */
152 uint32_t retention[6]; /**< ISO7816 important register information. */
153 } iso7816_handle_t;
154 /** @} */
155
156 /** @} */
157
158 /** @addtogroup HAL_ISO7816_CALLBACK_STRUCTURES Callback Structures
159 * @{
160 */
161
162 /** @defgroup ISO7816_Callback ISO7816 Callback
163 * @{
164 */
165
166 /**
167 * @brief HAL_ISO7816 Callback function definition
168 */
169
170 typedef struct _iso7816_callback
171 {
172 void (*iso7816_msp_init)(iso7816_handle_t *p_iso7816); /**< ISO7816 init MSP callback */
173 void (*iso7816_msp_deinit)(iso7816_handle_t *p_iso7816); /**< ISO7816 de-init MSP callback */
174 void (*iso7816_error_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 error callback */
175 void (*iso7816_abort_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 abort completed callback */
176 void (*iso7816_presence_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 card presence state changed callback */
177 void (*iso7816_atr_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 reseive atr completed callback */
178 void (*iso7816_tx_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 rx transfer completed callback */
179 void (*iso7816_rx_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 tx transfer completed callback */
180 void (*iso7816_tx_rx_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 tx/rx transfer completed callback */
181 } iso7816_callback_t;
182
183 /** @} */
184
185 /** @} */
186
187 /**
188 * @defgroup HAL_ISO7816_MACRO Defines
189 * @{
190 */
191
192 /* Exported constants --------------------------------------------------------*/
193 /** @defgroup ISO7816_Exported_Constants ISO7816 Exported Constants
194 * @{
195 */
196
197 /** @defgroup ISO7816_ACTION Action state
198 * @{
199 */
200 #define HAL_ISO7816_ACTION_NONE LL_ISO7816_ACTION_NONE /**< Do Nothing. */
201 #define HAL_ISO7816_ACTION_OFF LL_ISO7816_ACTION_OFF /**< Switch Off. */
202 #define HAL_ISO7816_ACTION_STOPCLK LL_ISO7816_ACTION_STOPCLK /**< Stop the clock. */
203 #define HAL_ISO7816_ACTION_ON LL_ISO7816_ACTION_ON /**< Switch on and receive ATR. */
204 #define HAL_ISO7816_ACTION_WARMRST LL_ISO7816_ACTION_WARMRST /**< Trigger warm reset and receive ATR.*/
205 #define HAL_ISO7816_ACTION_RX LL_ISO7816_ACTION_RX /**< Receive. */
206 #define HAL_ISO7816_ACTION_TX LL_ISO7816_ACTION_TX /**< Transmit. */
207 #define HAL_ISO7816_ACTION_TXRX LL_ISO7816_ACTION_TXRX /**< Transmit, followed by RX. */
208 /** @} */
209
210 /** @defgroup ISO7816_Interrupt_definition ISO7816 Interrupt Definition
211 * @{
212 */
213 #define HAL_ISO7816_INTR_TEST LL_ISO7816_INTR_TEST /**< Test interrupt */
214 #define HAL_ISO7816_INTR_PRESENCE LL_ISO7816_INTR_PRESENCE /**< Source presence interrupt */
215 #define HAL_ISO7816_INTR_STATE_ERR LL_ISO7816_INTR_STATE_ERR /**< Source state error interrupt */
216 #define HAL_ISO7816_INTR_DMA_ERR LL_ISO7816_INTR_DMA_ERR /**< Source dma error interrupt */
217 #define HAL_ISO7816_INTR_RETRY_ERR LL_ISO7816_INTR_RETRY_ERR /**< Source retry error interrupt */
218 #define HAL_ISO7816_INTR_RX_ERR LL_ISO7816_INTR_RX_ERR /**< Source rx error interrupt */
219 #define HAL_ISO7816_INTR_DONE LL_ISO7816_INTR_DONE /**< Source done error interrupt */
220 /** @} */
221
222
223 /** @defgroup ISO7816_HAL_CARD_PRESENCE Card Presence Defines
224 * @{
225 */
226 #define HAL_ISO7816_CARD_ABSENT LL_ISO7816_CARD_ABSENT /**< SIM Card is absent. */
227 #define HAL_ISO7816_CARD_PRESENT LL_ISO7816_CARD_PRESENT /**< SIM Card is present. */
228 /** @} */
229
230 /** @defgroup ISO7816_HAL_IO_STATES IO States Defines
231 * @{
232 */
233 #define HAL_ISO7816_IO_STATE_OFF LL_ISO7816_IO_STATE_OFF /**< Off */
234 #define HAL_ISO7816_IO_STATE_IDLE LL_ISO7816_IO_STATE_IDLE /**< Idle */
235 #define HAL_ISO7816_IO_STATE_RX_WAIT LL_ISO7816_IO_STATE_RX_WAIT /**< Receive Wait */
236 #define HAL_ISO7816_IO_STATE_RX LL_ISO7816_IO_STATE_RX /**< Receive */
237 #define HAL_ISO7816_IO_STATE_TX LL_ISO7816_IO_STATE_TX /**< Transmit */
238 #define HAL_ISO7816_IO_STATE_TX_GUARD LL_ISO7816_IO_STATE_TX_GUARD /**< Transmit Guard */
239 /** @} */
240
241 /** @defgroup ISO7816_HAL_PWR_STATES Power States Defines
242 * @{
243 */
244 #define HAL_ISO7816_PWR_STATE_OFF LL_ISO7816_PWR_STATE_OFF /**< Off */
245 #define HAL_ISO7816_PWR_STATE_PWRUP_VCC LL_ISO7816_PWR_STATE_PWRUP_VCC /**< Power up VCC */
246 #define HAL_ISO7816_PWR_STATE_PWRUP_RST LL_ISO7816_PWR_STATE_PWRUP_RST /**< Power up reset */
247 #define HAL_ISO7816_PWR_STATE_PWRDN_RST LL_ISO7816_PWR_STATE_PWRDN_RST /**< Power Down reset */
248 #define HAL_ISO7816_PWR_STATE_PWRDN_VCC LL_ISO7816_PWR_STATE_PWRDN_VCC /**< Power Down VCC */
249 #define HAL_ISO7816_PWR_STATE_STOP_PRE LL_ISO7816_PWR_STATE_STOP_PRE /**< Preparing Clock Stop */
250 #define HAL_ISO7816_PWR_STATE_STOP LL_ISO7816_PWR_STATE_STOP /**< Clock Stopped */
251 #define HAL_ISO7816_PWR_STATE_STOP_POST LL_ISO7816_PWR_STATE_STOP_POST /**< Exiting Clock Stop */
252 #define HAL_ISO7816_PWR_STATE_IDLE LL_ISO7816_PWR_STATE_IDLE /**< Idle */
253 #define HAL_ISO7816_PWR_STATE_RX_TS0 LL_ISO7816_PWR_STATE_RX_TS0 /**< RX TS Character */
254 #define HAL_ISO7816_PWR_STATE_RX_TS1 LL_ISO7816_PWR_STATE_RX_TS1 /**< RX TS Character */
255 #define HAL_ISO7816_PWR_STATE_RX LL_ISO7816_PWR_STATE_RX /**< Receive */
256 #define HAL_ISO7816_PWR_STATE_TX LL_ISO7816_PWR_STATE_TX /**< Transmit */
257 #define HAL_ISO7816_PWR_STATE_TX_RX LL_ISO7816_PWR_STATE_TX_RX /**< Transmit and Receive */
258 /** @} */
259
260 /** @defgroup ISO7816_Error_Code ISO7816 Error Code
261 * @{
262 */
263 #define HAL_ISO7816_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
264 #define HAL_ISO7816_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
265 #define HAL_ISO7816_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */
266 #define HAL_ISO7816_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /**< Invalid parameters error */
267 /** @} */
268
269 /** @} */
270
271 /* Exported macro ------------------------------------------------------------*/
272 /** @defgroup ISO7816_Exported_Macros ISO7816 Exported Macros
273 * @{
274 */
275
276 /** @brief Enable the specified ISO7816 interrupts.
277 * @param __HANDLE__ Specifies the ISO7816 Handle.
278 * @param __INTERRUPT__ Specifies the interrupt source to enable.
279 * This parameter can be one of the following values:
280 * @arg @ref HAL_ISO7816_INTR_TEST Test interrupt
281 * @arg @ref HAL_ISO7816_INTR_PRESENCE Presence interrupt
282 * @arg @ref HAL_ISO7816_INTR_STATE_ERR State error interrupt
283 * @arg @ref HAL_ISO7816_INTR_DMA_ERR DMA error interrupt
284 * @arg @ref HAL_ISO7816_INTR_RETRY_ERR Retry error interrupt
285 * @arg @ref HAL_ISO7816_INTR_RX_ERR Rx error interrupt
286 * @arg @ref HAL_ISO7816_INTR_DONE Done error interrupt
287 * @retval None
288 */
289 #define __HAL_ISO7816_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
290
291 /** @brief Disable the specified ISO7816 interrupts.
292 * @param __HANDLE__ Specifies the ISO7816 handle.
293 * @param __INTERRUPT__ Specifies the interrupt source to disable.
294 * This parameter can be one of the following values:
295 * @arg @ref HAL_ISO7816_INTR_TEST Test interrupt
296 * @arg @ref HAL_ISO7816_INTR_PRESENCE Presence interrupt
297 * @arg @ref HAL_ISO7816_INTR_STATE_ERR State error interrupt
298 * @arg @ref HAL_ISO7816_INTR_DMA_ERR DMA error interrupt
299 * @arg @ref HAL_ISO7816_INTR_RETRY_ERR Retry error interrupt
300 * @arg @ref HAL_ISO7816_INTR_RX_ERR Rx error interrupt
301 * @arg @ref HAL_ISO7816_INTR_DONE Done error interrupt
302 * @retval None
303 */
304 #define __HAL_ISO7816_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
305
306 /** @brief Get the ISO7816 interrupt flags.
307 * @param __ISO7816_REGS ISO7816 Register.
308 * @retval ISO78116 Interrupt definitions.
309 */
310 #define __HAL_ISO7816_IT_GET_IT_FLAG(__ISO7816_REGS) ll_iso7816_get_it_flag(__ISO7816_REGS)
311 /** @} */
312 /** @} */
313
314
315 /* Exported functions --------------------------------------------------------*/
316 /** @addtogroup HAL_ISO7816_DRIVER_FUNCTIONS Functions
317 * @{
318 */
319 /**
320 * @brief Transimit data in blocking mode
321 *
322 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
323 * @param tx_size Bytes of data to transmit
324 * @param timeout Timeout duration
325 * @retval ::HAL_OK: Operation is OK.
326 * @retval ::HAL_ERROR: Parameter error or operation not supported.
327 * @retval ::HAL_BUSY: Driver is busy.
328 * @retval ::HAL_TIMEOUT: Timeout occurred.
329 */
330 hal_status_t hal_iso7816_transmit(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint32_t timeout);
331
332 /**
333 * @brief Receive data in blocking mode
334 *
335 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
336 * @param rx_size Bytes of data to receive
337 * @param timeout Timeout duration
338 * @retval ::HAL_OK: Operation is OK.
339 * @retval ::HAL_ERROR: Parameter error or operation not supported.
340 * @retval ::HAL_BUSY: Driver is busy.
341 * @retval ::HAL_TIMEOUT: Timeout occurred.
342 */
343 hal_status_t hal_iso7816_receive(iso7816_handle_t *p_iso7816, uint16_t rx_size, uint32_t timeout);
344
345 /**
346 * @brief Transimit and receive data in blocking mode
347 *
348 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
349 * @param tx_size Bytes of data to transmit
350 * @param rx_size Bytes of data to receive
351 * @param timeout Timeout duration
352 * @retval ::HAL_OK: Operation is OK.
353 * @retval ::HAL_ERROR: Parameter error or operation not supported.
354 * @retval ::HAL_BUSY: Driver is busy.
355 * @retval ::HAL_TIMEOUT: Timeout occurred.
356 */
357 hal_status_t hal_iso7816_transmit_receive(iso7816_handle_t *p_iso7816, uint16_t tx_size,uint16_t rx_size, uint32_t timeout);
358
359 /**
360 * @brief Transimit data in non-blocking mode with Interrupt
361 *
362 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
363 * @param tx_size Bytes of data to transmit
364 * @retval ::HAL_OK: Operation is OK.
365 * @retval ::HAL_ERROR: Parameter error or operation not supported.
366 * @retval ::HAL_BUSY: Driver is busy.
367 * @retval ::HAL_TIMEOUT: Timeout occurred.
368 */
369 hal_status_t hal_iso7816_transmit_it(iso7816_handle_t *p_iso7816, uint16_t tx_size);
370
371 /**
372 * @brief Receive data in non-blocking mode with Interrupt
373 *
374 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
375 * @param rx_size Bytes of data to receive
376 * @retval ::HAL_OK: Operation is OK.
377 * @retval ::HAL_ERROR: Parameter error or operation not supported.
378 * @retval ::HAL_BUSY: Driver is busy.
379 * @retval ::HAL_TIMEOUT: Timeout occurred.
380 */
381 hal_status_t hal_iso7816_receive_it(iso7816_handle_t *p_iso7816, uint16_t rx_size);
382
383 /**
384 * @brief Transimit and receive data in non-blocking mode with Interrupt
385 *
386 * @param p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
387 * @param tx_size: Bytes of data to transfer.
388 * @param rx_size: Bytes of data to receive.
389 * @retval ::HAL_OK: Operation is OK.
390 * @retval ::HAL_ERROR: Parameter error or operation not supported.
391 * @retval ::HAL_BUSY: Driver is busy.
392 * @retval ::HAL_TIMEOUT: Timeout occurred.
393 */
394
395 hal_status_t hal_iso7816_transmit_receive_it(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint16_t rx_size);
396
397 /**
398 * @brief Transfer Abort functions
399 *
400 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
401 * @retval ::HAL_OK: Operation is OK.
402 * @retval ::HAL_ERROR: Parameter error or operation not supported.
403 * @retval ::HAL_BUSY: Driver is busy.
404 * @retval ::HAL_TIMEOUT: Timeout occurred.
405 */
406 hal_status_t hal_iso7816_abort(iso7816_handle_t *p_iso7816);
407
408 /**
409 ****************************************************************************************
410 * @brief Initializes the ISO7816 according to the specified parameters
411 * in the iso7816_init_t and initialize the associated handle.
412 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration
413 * information for the specified ISO7816.
414 * @retval ::HAL_OK: Operation is OK.
415 * @retval ::HAL_ERROR: Parameter error or operation not supported.
416 * @retval ::HAL_BUSY: Driver is busy.
417 * @retval ::HAL_TIMEOUT: Timeout occurred.
418 ****************************************************************************************
419 */
420 hal_status_t hal_iso7816_init(iso7816_handle_t *p_iso7816);
421
422 /**
423 ****************************************************************************************
424 * @brief De-initializes the ISO7816 according to the specified parameters
425 * in the iso7816_init_t and initialize the associated handle.
426 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration
427 * information for the specified ISO7816.
428 * @retval ::HAL_OK: Operation is OK.
429 * @retval ::HAL_ERROR: Parameter error or operation not supported.
430 * @retval ::HAL_BUSY: Driver is busy.
431 * @retval ::HAL_TIMEOUT: Timeout occurred.
432 ****************************************************************************************
433 */
434 hal_status_t hal_iso7816_deinit(iso7816_handle_t *p_iso7816);
435
436 /**
437 ****************************************************************************************
438 * @brief Initialize the ISO7816 MSP.
439 * @note This function should not be modified. When the callback is needed,
440 * the hal_iso7816_msp_init could be implemented in the user file.
441 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
442 ****************************************************************************************
443 */
444 void hal_iso7816_msp_init(iso7816_handle_t *p_iso7816);
445
446 /**
447 ****************************************************************************************
448 * @brief De-initialize the ISO7816 MSP.
449 * @note This function should not be modified. When the callback is needed,
450 * the hal_iso7816_msp_deinit could be implemented in the user file.
451 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
452 ****************************************************************************************
453 */
454 void hal_iso7816_msp_deinit(iso7816_handle_t *p_iso7816);
455 /**
456 ****************************************************************************************
457 * @brief Handle ISO7816 interrupt request.
458 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816.
459 ****************************************************************************************
460 */
461 void hal_iso7816_irq_handler(iso7816_handle_t *p_iso7816);
462
463
464 /**
465 ****************************************************************************************
466 * @brief Card presence state changed callback.
467 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816 module.
468 ****************************************************************************************
469 */
470 void hal_iso7816_presence_callback(iso7816_handle_t *p_iso7816);
471
472 /**
473 ****************************************************************************************
474 * @brief Receive ART completed callback.
475 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816 module.
476 ****************************************************************************************
477 */
478 void hal_iso7816_atr_cplt_callback(iso7816_handle_t *p_iso7816);
479
480 /**
481 ****************************************************************************************
482 * @brief Rx Transfer completed callback.
483 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816 module.
484 ****************************************************************************************
485 */
486 void hal_iso7816_rx_cplt_callback(iso7816_handle_t *p_iso7816);
487
488 /**
489 ****************************************************************************************
490 * @brief Tx Transfer completed callback.
491 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816 module.
492 ****************************************************************************************
493 */
494 void hal_iso7816_tx_cplt_callback(iso7816_handle_t *p_iso7816);
495
496 /**
497 ****************************************************************************************
498 * @brief Tx and Rx Transfer completed callback.
499 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816 module.
500 ****************************************************************************************
501 */
502 void hal_iso7816_tx_rx_cplt_callback(iso7816_handle_t *p_iso7816);
503
504 /**
505 ****************************************************************************************
506 * @brief ISO7816 error callback.
507 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration information for the specified ISO7816 module.
508 ****************************************************************************************
509 */
510 void hal_iso7816_error_callback(iso7816_handle_t *p_iso7816);
511
512 /**
513 ****************************************************************************************
514 * @brief ISO7816 Abort Completed callback.
515 * @param[in] p_iso7816: ISO7816 handle.
516 ****************************************************************************************
517 */
518 void hal_iso7816_abort_cplt_callback(iso7816_handle_t *p_iso7816);
519
520 /**
521 ****************************************************************************************
522 * @brief Return the ISO7816 handle state.
523 * @param[in] p_iso7816: ISO7816 handle.
524 * @retval ::HAL_ISO7816_STATE_RESET
525 * @retval ::HAL_ISO7816_STATE_READY
526 * @retval ::HAL_ISO7816_STATE_BUSY
527 * @retval ::HAL_ISO7816_STATE_BUSY_TX
528 * @retval ::HAL_ISO7816_STATE_BUSY_RX
529 * @retval ::HAL_ISO7816_STATE_BUSY_TX_RX
530 * @retval ::HAL_ISO7816_STATE_ABORT
531 * @retval ::HAL_ISO7816_STATE_TIMEOUT
532 * @retval ::HAL_ISO7816_STATE_ERROR
533 ****************************************************************************************
534 */
535 hal_iso7816_state_t hal_iso7816_get_state(iso7816_handle_t *p_iso7816);
536
537 /**
538 * @brief Request ISO7816 to go to the next action.
539 * @param p_iso7816: ISO7816 handle.
540 * @param action: This parameter can be one of the following values:
541 * @arg @ref HAL_ISO7816_ACTION_NONE
542 * @arg @ref HAL_ISO7816_ACTION_OFF
543 * @arg @ref HAL_ISO7816_ACTION_STOPCLK
544 * @arg @ref HAL_ISO7816_ACTION_ON
545 * @arg @ref HAL_ISO7816_ACTION_WARMRST
546 * @arg @ref HAL_ISO7816_ACTION_RX
547 * @arg @ref HAL_ISO7816_ACTION_TX
548 * @arg @ref HAL_ISO7816_ACTION_TXRX
549 * @retval ::HAL_OK: Operation is OK.
550 * @retval ::HAL_ERROR: Parameter error or operation not supported.
551 * @retval ::HAL_BUSY: Driver is busy.
552 */
553 hal_status_t hal_iso7816_set_action(iso7816_handle_t *p_iso7816, uint32_t action);
554
555 /**
556 * @brief Get ISO7816 Power States.
557 * @param p_iso7816: ISO7816 handle.
558 * @retval Returned value can be one of the following values:
559 * @arg @ref HAL_ISO7816_PWR_STATE_OFF
560 * @arg @ref HAL_ISO7816_PWR_STATE_PWRUP_VCC
561 * @arg @ref HAL_ISO7816_PWR_STATE_PWRUP_RST
562 * @arg @ref HAL_ISO7816_PWR_STATE_PWRDN_RST
563 * @arg @ref HAL_ISO7816_PWR_STATE_PWRDN_VCC
564 * @arg @ref HAL_ISO7816_PWR_STATE_STOP_PRE
565 * @arg @ref HAL_ISO7816_PWR_STATE_STOP
566 * @arg @ref HAL_ISO7816_PWR_STATE_STOP_POST
567 * @arg @ref HAL_ISO7816_PWR_STATE_IDLE
568 * @arg @ref HAL_ISO7816_PWR_STATE_RX_TS0
569 * @arg @ref HAL_ISO7816_PWR_STATE_RX_TS1
570 * @arg @ref HAL_ISO7816_PWR_STATE_RX
571 * @arg @ref HAL_ISO7816_PWR_STATE_TX
572 * @arg @ref HAL_ISO7816_PWR_STATE_TX_RX
573 */
574 uint32_t hal_iso7816_get_power_states(iso7816_handle_t *p_iso7816);
575
576 /**
577 * @brief Set divide ISO7816 clock.
578 * @note Divide SIM clock by this value+1 to define ETU length. The reset value
579 * is the one, needed for theATR.
580 * @param p_iso7816: ISO7816 handle.
581 * @param divide This parameter should range between 0x0 and 0x3FF.
582 * @retval None.
583 */
584 hal_status_t hal_iso7816_set_etudiv(iso7816_handle_t *p_iso7816, uint32_t divide);
585
586 /**
587 ****************************************************************************************
588 * @brief Return the ISO7816 error code.
589 * @param[in] p_iso7816: ISO7816 handle.
590 * @return ISO7816 Error Code
591 ****************************************************************************************
592 */
593 uint32_t hal_iso7816_get_error(iso7816_handle_t *p_iso7816);
594
595 /**
596 ****************************************************************************************
597 * @brief Suspend some registers related to ISO7816 configuration before sleep.
598 * @param[in] p_iso7816: ISO7816 handle.
599 * @retval ::HAL_OK: Operation is OK.
600 * @retval ::HAL_ERROR: Parameter error or operation not supported.
601 * @retval ::HAL_BUSY: Driver is busy.
602 * @retval ::HAL_TIMEOUT: Timeout occurred.
603 ****************************************************************************************
604 */
605 hal_status_t hal_iso7816_suspend_reg(iso7816_handle_t *p_iso7816);
606
607 /**
608 ****************************************************************************************
609 * @brief Restore some registers related to ISO7816 configuration after sleep.
610 * This function must be used in conjunction with the hal_iso7816_suspend_reg().
611 * @param[in] p_iso7816: ISO7816 handle.
612 * @retval ::HAL_OK: Operation is OK.
613 * @retval ::HAL_ERROR: Parameter error or operation not supported.
614 * @retval ::HAL_BUSY: Driver is busy.
615 * @retval ::HAL_TIMEOUT: Timeout occurred.
616 ****************************************************************************************
617 */
618 hal_status_t hal_iso7816_resume_reg(iso7816_handle_t *p_iso7816);
619
620
621 /** @} */
622
623
624 #ifdef __cplusplus
625 }
626 #endif
627
628 #endif /* __GR55xx_HAL_ISO7816_H__ */
629
630 /** @} */
631
632 /** @} */
633
634 /** @} */
hal_iso7816_suspend_reg
hal_status_t hal_iso7816_suspend_reg(iso7816_handle_t *p_iso7816)
Suspend some registers related to ISO7816 configuration before sleep.
hal_iso7816_transmit_receive_it
hal_status_t hal_iso7816_transmit_receive_it(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint16_t rx_size)
Transimit and receive data in non-blocking mode with Interrupt.
iso7816_init_t::clk_div
uint32_t clk_div
Definition: gr55xx_hal_iso7816.h:102
hal_iso7816_abort_cplt_callback
void hal_iso7816_abort_cplt_callback(iso7816_handle_t *p_iso7816)
ISO7816 Abort Completed callback.
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
hal_iso7816_get_error
uint32_t hal_iso7816_get_error(iso7816_handle_t *p_iso7816)
Return the ISO7816 error code.
_iso7816_callback::iso7816_presence_callback
void(* iso7816_presence_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:176
_iso7816_handle_t
ISO7816 handle Structure definition.
Definition: gr55xx_hal_iso7816.h:137
_iso7816_handle_t::rx_state
__IO hal_iso7816_state_t rx_state
Definition: gr55xx_hal_iso7816.h:149
_iso7816_callback
HAL_ISO7816 Callback function definition.
Definition: gr55xx_hal_iso7816.h:171
hal_iso7816_receive
hal_status_t hal_iso7816_receive(iso7816_handle_t *p_iso7816, uint16_t rx_size, uint32_t timeout)
Receive data in blocking mode.
hal_iso7816_transmit_it
hal_status_t hal_iso7816_transmit_it(iso7816_handle_t *p_iso7816, uint16_t tx_size)
Transimit data in non-blocking mode with Interrupt.
iso7816_init_t::detect_coding
uint8_t detect_coding
Definition: gr55xx_hal_iso7816.h:106
hal_iso7816_get_power_states
uint32_t hal_iso7816_get_power_states(iso7816_handle_t *p_iso7816)
Get ISO7816 Power States.
_iso7816_callback::iso7816_tx_cplt_callback
void(* iso7816_tx_cplt_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:178
hal_iso7816_resume_reg
hal_status_t hal_iso7816_resume_reg(iso7816_handle_t *p_iso7816)
Restore some registers related to ISO7816 configuration after sleep. This function must be used in co...
hal_iso7816_receive_it
hal_status_t hal_iso7816_receive_it(iso7816_handle_t *p_iso7816, uint16_t rx_size)
Receive data in non-blocking mode with Interrupt.
_iso7816_handle_t::buffer_size
uint16_t buffer_size
Definition: gr55xx_hal_iso7816.h:141
HAL_ISO7816_STATE_READY
@ HAL_ISO7816_STATE_READY
Definition: gr55xx_hal_iso7816.h:77
_iso7816_callback::iso7816_error_callback
void(* iso7816_error_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:174
hal_iso7816_msp_deinit
void hal_iso7816_msp_deinit(iso7816_handle_t *p_iso7816)
De-initialize the ISO7816 MSP.
HAL_ISO7816_STATE_ERROR
@ HAL_ISO7816_STATE_ERROR
Definition: gr55xx_hal_iso7816.h:84
_iso7816_handle_t::state
__IO hal_iso7816_state_t state
Definition: gr55xx_hal_iso7816.h:147
HAL_ISO7816_STATE_ABORT
@ HAL_ISO7816_STATE_ABORT
Definition: gr55xx_hal_iso7816.h:82
iso7816_callback_t
struct _iso7816_callback iso7816_callback_t
HAL_ISO7816 Callback function definition.
hal_iso7816_get_state
hal_iso7816_state_t hal_iso7816_get_state(iso7816_handle_t *p_iso7816)
Return the ISO7816 handle state.
hal_iso7816_abort
hal_status_t hal_iso7816_abort(iso7816_handle_t *p_iso7816)
Transfer Abort functions.
_iso7816_handle_t::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_iso7816.h:151
_iso7816_callback::iso7816_tx_rx_cplt_callback
void(* iso7816_tx_rx_cplt_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:180
hal_iso7816_msp_init
void hal_iso7816_msp_init(iso7816_handle_t *p_iso7816)
Initialize the ISO7816 MSP.
hal_iso7816_atr_cplt_callback
void hal_iso7816_atr_cplt_callback(iso7816_handle_t *p_iso7816)
Receive ART completed callback.
hal_iso7816_transmit_receive
hal_status_t hal_iso7816_transmit_receive(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint16_t rx_size, uint32_t timeout)
Transimit and receive data in blocking mode.
HAL_ISO7816_STATE_TIMEOUT
@ HAL_ISO7816_STATE_TIMEOUT
Definition: gr55xx_hal_iso7816.h:83
hal_iso7816_irq_handler
void hal_iso7816_irq_handler(iso7816_handle_t *p_iso7816)
Handle ISO7816 interrupt request.
gr55xx_ll_iso7816.h
Header file containing functions prototypes of ISO7816 LL library.
_iso7816_callback::iso7816_msp_deinit
void(* iso7816_msp_deinit)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:173
hal_iso7816_init
hal_status_t hal_iso7816_init(iso7816_handle_t *p_iso7816)
Initializes the ISO7816 according to the specified parameters in the iso7816_init_t and initialize th...
iso7816_init_t::guard_time
uint16_t guard_time
Definition: gr55xx_hal_iso7816.h:105
HAL_ISO7816_STATE_BUSY_TX_RX
@ HAL_ISO7816_STATE_BUSY_TX_RX
Definition: gr55xx_hal_iso7816.h:81
HAL_ISO7816_STATE_BUSY_RX
@ HAL_ISO7816_STATE_BUSY_RX
Definition: gr55xx_hal_iso7816.h:80
HAL_ISO7816_STATE_BUSY
@ HAL_ISO7816_STATE_BUSY
Definition: gr55xx_hal_iso7816.h:78
_iso7816_handle_t::retention
uint32_t retention[6]
Definition: gr55xx_hal_iso7816.h:152
_iso7816_callback::iso7816_atr_cplt_callback
void(* iso7816_atr_cplt_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:177
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_iso7816_handle_t::lock
__IO hal_lock_t lock
Definition: gr55xx_hal_iso7816.h:146
_iso7816_handle_t::previous_action
__IO uint32_t previous_action
Definition: gr55xx_hal_iso7816.h:150
hal_iso7816_set_etudiv
hal_status_t hal_iso7816_set_etudiv(iso7816_handle_t *p_iso7816, uint32_t divide)
Set divide ISO7816 clock.
iso7816_init_t::wait_time
uint32_t wait_time
Definition: gr55xx_hal_iso7816.h:104
_iso7816_handle_t::tx_xfer_size
uint16_t tx_xfer_size
Definition: gr55xx_hal_iso7816.h:142
hal_iso7816_rx_cplt_callback
void hal_iso7816_rx_cplt_callback(iso7816_handle_t *p_iso7816)
Rx Transfer completed callback.
_iso7816_handle_t::init
iso7816_init_t init
Definition: gr55xx_hal_iso7816.h:139
_iso7816_handle_t::rx_xfer_size
uint16_t rx_xfer_size
Definition: gr55xx_hal_iso7816.h:144
hal_iso7816_deinit
hal_status_t hal_iso7816_deinit(iso7816_handle_t *p_iso7816)
De-initializes the ISO7816 according to the specified parameters in the iso7816_init_t and initialize...
_iso7816_handle_t::tx_xfer_count
__IO uint16_t tx_xfer_count
Definition: gr55xx_hal_iso7816.h:143
_iso7816_callback::iso7816_rx_cplt_callback
void(* iso7816_rx_cplt_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:179
hal_iso7816_tx_cplt_callback
void hal_iso7816_tx_cplt_callback(iso7816_handle_t *p_iso7816)
Tx Transfer completed callback.
hal_iso7816_state_t
hal_iso7816_state_t
HAL ISO7816 State Enumerations definition.
Definition: gr55xx_hal_iso7816.h:75
_iso7816_handle_t::tx_state
__IO hal_iso7816_state_t tx_state
Definition: gr55xx_hal_iso7816.h:148
hal_iso7816_presence_callback
void hal_iso7816_presence_callback(iso7816_handle_t *p_iso7816)
Card presence state changed callback.
_iso7816_callback::iso7816_abort_cplt_callback
void(* iso7816_abort_cplt_callback)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:175
HAL_ISO7816_STATE_RESET
@ HAL_ISO7816_STATE_RESET
Definition: gr55xx_hal_iso7816.h:76
_iso7816_handle_t::rx_xfer_count
__IO uint16_t rx_xfer_count
Definition: gr55xx_hal_iso7816.h:145
hal_iso7816_tx_rx_cplt_callback
void hal_iso7816_tx_rx_cplt_callback(iso7816_handle_t *p_iso7816)
Tx and Rx Transfer completed callback.
_iso7816_callback::iso7816_msp_init
void(* iso7816_msp_init)(iso7816_handle_t *p_iso7816)
Definition: gr55xx_hal_iso7816.h:172
iso7816_init_t
ISO7816_init_structure ISO7816 init structure definition.
Definition: gr55xx_hal_iso7816.h:101
hal_iso7816_transmit
hal_status_t hal_iso7816_transmit(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint32_t timeout)
Transimit data in blocking mode.
_iso7816_handle_t::p_tx_rx_buffer
uint8_t * p_tx_rx_buffer
Definition: gr55xx_hal_iso7816.h:140
_iso7816_handle_t::p_instance
iso7816_regs_t * p_instance
Definition: gr55xx_hal_iso7816.h:138
HAL_ISO7816_STATE_BUSY_TX
@ HAL_ISO7816_STATE_BUSY_TX
Definition: gr55xx_hal_iso7816.h:79
hal_iso7816_error_callback
void hal_iso7816_error_callback(iso7816_handle_t *p_iso7816)
ISO7816 error callback.
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
iso7816_handle_t
struct _iso7816_handle_t iso7816_handle_t
ISO7816 handle Structure definition.
hal_iso7816_set_action
hal_status_t hal_iso7816_set_action(iso7816_handle_t *p_iso7816, uint32_t action)
Request ISO7816 to go to the next action.