gr55xx_hal_iso7816.h
Go to the documentation of this file.
1
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 ------------------------------------------------------------*/
74 typedef enum
75 {
76 HAL_ISO7816_STATE_RESET = 0x00U,
77 HAL_ISO7816_STATE_READY = 0x20U,
78 HAL_ISO7816_STATE_BUSY = 0x24U,
79 HAL_ISO7816_STATE_BUSY_TX = 0x21U,
80 HAL_ISO7816_STATE_BUSY_RX = 0x22U,
81 HAL_ISO7816_STATE_BUSY_TX_RX = 0x23U,
82 HAL_ISO7816_STATE_ABORT = 0x08U,
83 HAL_ISO7816_STATE_TIMEOUT = 0xA0U,
84 HAL_ISO7816_STATE_ERROR = 0xE0U
85 } hal_iso7816_state_t;
100 typedef struct
101 {
102 uint32_t clk_div;
104 uint32_t wait_time;
105 uint16_t guard_time;
106 uint8_t detect_coding;
107 } iso7816_init_t;
117 #define ISO7816_DEFAULT_CONFIG \
118 { \
119 .clk_div = 0x2F, \
120 .wait_time = 0x6B, \
121 .guard_time = 0x00, \
122 .detect_coding = ENABLE, \
123 }
124
136 typedef struct _iso7816_handle_t
137 {
138 iso7816_regs_t *p_instance;
139 iso7816_init_t init;
140 uint8_t *p_tx_rx_buffer;
141 uint16_t buffer_size;
142 uint16_t tx_xfer_size;
143 __IO uint16_t tx_xfer_count;
144 uint16_t rx_xfer_size;
145 __IO uint16_t rx_xfer_count;
146 __IO hal_lock_t lock;
147 __IO hal_iso7816_state_t state;
148 __IO hal_iso7816_state_t tx_state;
149 __IO hal_iso7816_state_t rx_state;
150 __IO uint32_t previous_action;
151 __IO uint32_t error_code;
152 uint32_t retention[6];
153 } iso7816_handle_t;
170 typedef struct _iso7816_callback
171 {
172 void (*iso7816_msp_init)(iso7816_handle_t *p_iso7816);
173 void (*iso7816_msp_deinit)(iso7816_handle_t *p_iso7816);
174 void (*iso7816_error_callback)(iso7816_handle_t *p_iso7816);
175 void (*iso7816_abort_cplt_callback)(iso7816_handle_t *p_iso7816);
176 void (*iso7816_presence_callback)(iso7816_handle_t *p_iso7816);
177 void (*iso7816_atr_cplt_callback)(iso7816_handle_t *p_iso7816);
178 void (*iso7816_tx_cplt_callback)(iso7816_handle_t *p_iso7816);
179 void (*iso7816_rx_cplt_callback)(iso7816_handle_t *p_iso7816);
180 void (*iso7816_tx_rx_cplt_callback)(iso7816_handle_t *p_iso7816);
181 } iso7816_callback_t;
182
192 /* Exported constants --------------------------------------------------------*/
200 #define HAL_ISO7816_ACTION_NONE LL_ISO7816_ACTION_NONE
201 #define HAL_ISO7816_ACTION_OFF LL_ISO7816_ACTION_OFF
202 #define HAL_ISO7816_ACTION_STOPCLK LL_ISO7816_ACTION_STOPCLK
203 #define HAL_ISO7816_ACTION_ON LL_ISO7816_ACTION_ON
204 #define HAL_ISO7816_ACTION_WARMRST LL_ISO7816_ACTION_WARMRST
205 #define HAL_ISO7816_ACTION_RX LL_ISO7816_ACTION_RX
206 #define HAL_ISO7816_ACTION_TX LL_ISO7816_ACTION_TX
207 #define HAL_ISO7816_ACTION_TXRX LL_ISO7816_ACTION_TXRX
213 #define HAL_ISO7816_INTR_TEST LL_ISO7816_INTR_TEST
214 #define HAL_ISO7816_INTR_PRESENCE LL_ISO7816_INTR_PRESENCE
215 #define HAL_ISO7816_INTR_STATE_ERR LL_ISO7816_INTR_STATE_ERR
216 #define HAL_ISO7816_INTR_DMA_ERR LL_ISO7816_INTR_DMA_ERR
217 #define HAL_ISO7816_INTR_RETRY_ERR LL_ISO7816_INTR_RETRY_ERR
218 #define HAL_ISO7816_INTR_RX_ERR LL_ISO7816_INTR_RX_ERR
219 #define HAL_ISO7816_INTR_DONE LL_ISO7816_INTR_DONE
226 #define HAL_ISO7816_CARD_ABSENT LL_ISO7816_CARD_ABSENT
227 #define HAL_ISO7816_CARD_PRESENT LL_ISO7816_CARD_PRESENT
233 #define HAL_ISO7816_IO_STATE_OFF LL_ISO7816_IO_STATE_OFF
234 #define HAL_ISO7816_IO_STATE_IDLE LL_ISO7816_IO_STATE_IDLE
235 #define HAL_ISO7816_IO_STATE_RX_WAIT LL_ISO7816_IO_STATE_RX_WAIT
236 #define HAL_ISO7816_IO_STATE_RX LL_ISO7816_IO_STATE_RX
237 #define HAL_ISO7816_IO_STATE_TX LL_ISO7816_IO_STATE_TX
238 #define HAL_ISO7816_IO_STATE_TX_GUARD LL_ISO7816_IO_STATE_TX_GUARD
244 #define HAL_ISO7816_PWR_STATE_OFF LL_ISO7816_PWR_STATE_OFF
245 #define HAL_ISO7816_PWR_STATE_PWRUP_VCC LL_ISO7816_PWR_STATE_PWRUP_VCC
246 #define HAL_ISO7816_PWR_STATE_PWRUP_RST LL_ISO7816_PWR_STATE_PWRUP_RST
247 #define HAL_ISO7816_PWR_STATE_PWRDN_RST LL_ISO7816_PWR_STATE_PWRDN_RST
248 #define HAL_ISO7816_PWR_STATE_PWRDN_VCC LL_ISO7816_PWR_STATE_PWRDN_VCC
249 #define HAL_ISO7816_PWR_STATE_STOP_PRE LL_ISO7816_PWR_STATE_STOP_PRE
250 #define HAL_ISO7816_PWR_STATE_STOP LL_ISO7816_PWR_STATE_STOP
251 #define HAL_ISO7816_PWR_STATE_STOP_POST LL_ISO7816_PWR_STATE_STOP_POST
252 #define HAL_ISO7816_PWR_STATE_IDLE LL_ISO7816_PWR_STATE_IDLE
253 #define HAL_ISO7816_PWR_STATE_RX_TS0 LL_ISO7816_PWR_STATE_RX_TS0
254 #define HAL_ISO7816_PWR_STATE_RX_TS1 LL_ISO7816_PWR_STATE_RX_TS1
255 #define HAL_ISO7816_PWR_STATE_RX LL_ISO7816_PWR_STATE_RX
256 #define HAL_ISO7816_PWR_STATE_TX LL_ISO7816_PWR_STATE_TX
257 #define HAL_ISO7816_PWR_STATE_TX_RX LL_ISO7816_PWR_STATE_TX_RX
263 #define HAL_ISO7816_ERROR_NONE ((uint32_t)0x00000000)
264 #define HAL_ISO7816_ERROR_TIMEOUT ((uint32_t)0x00000001)
265 #define HAL_ISO7816_ERROR_TRANSFER ((uint32_t)0x00000002)
266 #define HAL_ISO7816_ERROR_INVALID_PARAM ((uint32_t)0x00000008)
271 /* Exported macro ------------------------------------------------------------*/
272
289 #define __HAL_ISO7816_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
290
304 #define __HAL_ISO7816_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
305
310 #define __HAL_ISO7816_IT_GET_IT_FLAG(__ISO7816_REGS) ll_iso7816_get_it_flag(__ISO7816_REGS)
311
315 /* Exported functions --------------------------------------------------------*/
330 hal_status_t hal_iso7816_transmit(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint32_t timeout);
331
343 hal_status_t hal_iso7816_receive(iso7816_handle_t *p_iso7816, uint16_t rx_size, uint32_t timeout);
344
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
369 hal_status_t hal_iso7816_transmit_it(iso7816_handle_t *p_iso7816, uint16_t tx_size);
370
381 hal_status_t hal_iso7816_receive_it(iso7816_handle_t *p_iso7816, uint16_t rx_size);
382
395 hal_status_t hal_iso7816_transmit_receive_it(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint16_t rx_size);
396
406 hal_status_t hal_iso7816_abort(iso7816_handle_t *p_iso7816);
407
420 hal_status_t hal_iso7816_init(iso7816_handle_t *p_iso7816);
421
434 hal_status_t hal_iso7816_deinit(iso7816_handle_t *p_iso7816);
435
444 void hal_iso7816_msp_init(iso7816_handle_t *p_iso7816);
445
454 void hal_iso7816_msp_deinit(iso7816_handle_t *p_iso7816);
461 void hal_iso7816_irq_handler(iso7816_handle_t *p_iso7816);
462
463
470 void hal_iso7816_presence_callback(iso7816_handle_t *p_iso7816);
471
478 void hal_iso7816_atr_cplt_callback(iso7816_handle_t *p_iso7816);
479
486 void hal_iso7816_rx_cplt_callback(iso7816_handle_t *p_iso7816);
487
494 void hal_iso7816_tx_cplt_callback(iso7816_handle_t *p_iso7816);
495
502 void hal_iso7816_tx_rx_cplt_callback(iso7816_handle_t *p_iso7816);
503
510 void hal_iso7816_error_callback(iso7816_handle_t *p_iso7816);
511
518 void hal_iso7816_abort_cplt_callback(iso7816_handle_t *p_iso7816);
519
535 hal_iso7816_state_t hal_iso7816_get_state(iso7816_handle_t *p_iso7816);
536
553 hal_status_t hal_iso7816_set_action(iso7816_handle_t *p_iso7816, uint32_t action);
554
574 uint32_t hal_iso7816_get_power_states(iso7816_handle_t *p_iso7816);
575
584 hal_status_t hal_iso7816_set_etudiv(iso7816_handle_t *p_iso7816, uint32_t divide);
585
593 uint32_t hal_iso7816_get_error(iso7816_handle_t *p_iso7816);
594
605 hal_status_t hal_iso7816_suspend_reg(iso7816_handle_t *p_iso7816);
606
618 hal_status_t hal_iso7816_resume_reg(iso7816_handle_t *p_iso7816);
619
620
624 #ifdef __cplusplus
625 }
626 #endif
627
628 #endif /* __GR55xx_HAL_ISO7816_H__ */
629
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.