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 /* Includes ------------------------------------------------------------------*/ 56 #include "gr55xx_ll_iso7816.h" 57 #include "gr55xx_hal_def.h" 58 59 #ifdef __cplusplus 60 extern "C" { 61 #endif 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 HAL_ISO7816_STATE_RESET = 0x00U, /**< Peripheral not initialized */ 76 HAL_ISO7816_STATE_READY = 0x20U, /**< Peripheral initialized and ready for use */ 77 HAL_ISO7816_STATE_BUSY = 0x24U, /**< An internal process is ongoing */ 78 HAL_ISO7816_STATE_BUSY_TX = 0x21U, /**< Data Transmission process is ongoing */ 79 HAL_ISO7816_STATE_BUSY_RX = 0x22U, /**< Data Reception process is ongoing */ 80 HAL_ISO7816_STATE_BUSY_TX_RX = 0x23U, /**< Data Transmission and Reception process is ongoing */ 81 HAL_ISO7816_STATE_ABORT = 0x08U, /**< Peripheral with abort request ongoing */ 82 HAL_ISO7816_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */ 83 HAL_ISO7816_STATE_ERROR = 0xE0U /**< Peripheral in error */ 84 } hal_iso7816_state_t; 85 /** @} */ 86 87 /** @} */ 88 89 /** @addtogroup HAL_ISO7816_STRUCTURES Structures 90 * @{ 91 */ 92 93 /** @defgroup ISO7816_Configuration ISO7816 Configuration 94 * @{ 95 */ 96 /** 97 * @brief ISO7816_init_structure ISO7816 init structure definition 98 */ 99 typedef struct { 100 uint32_t clk_div; /*!< clk_div is used for dividing the system clock, 101 and ISO7816 output clock is equal to (system clock)/(clk_div+1). */ 102 uint32_t wait_time; /*!< Specifies the guard time value in terms of number of baud clocks */ 103 uint16_t guard_time; /*!< Specifies the maximum card response time (leading edge to leading edge) */ 104 uint8_t detect_coding; /*!< Specifies whether automatically detect coding convention during 105 ATR receiption. */ 106 } iso7816_init_t; 107 /** @} */ 108 /** @} */ 109 110 /** @defgroup HAL_ISO7816_MACRO Defines 111 * @{ 112 */ 113 /** 114 * @brief ISO7816_default_config InitStruct default configuration 115 */ 116 #define ISO7816_DEFAULT_CONFIG \ 117 { \ 118 .clk_div = 0x2F, \ 119 .wait_time = 0x6B, \ 120 .guard_time = 0x00, \ 121 .detect_coding = ENABLE, \ 122 } 123 /** @} */ 124 125 /** @addtogroup HAL_ISO7816_STRUCTURES Structures 126 * @{ 127 */ 128 /** @defgroup ISO7816_handle Handle 129 * @{ 130 */ 131 132 /** 133 * @brief ISO7816 handle Structure definition 134 */ 135 typedef struct _iso7816_handle_t { 136 iso7816_regs_t *p_instance; /**< ISO7816 registers base address */ 137 iso7816_init_t init; /**< ISO7816 configuration parameters */ 138 uint8_t *p_tx_rx_buffer; /**< Pointer to ISO7816 Tx&Rx transfer Buffer */ 139 uint16_t buffer_size; /**< ISO7816 Tx Transfer size */ 140 uint16_t tx_xfer_size; /**< ISO7816 Tx Transfer size */ 141 __IO uint16_t tx_xfer_count; /**< ISO7816 Tx Transfer Counter */ 142 uint16_t rx_xfer_size; /**< ISO7816 Rx Transfer size */ 143 __IO uint16_t rx_xfer_count; /**< ISO7816 Rx Transfer Counter */ 144 __IO hal_lock_t lock; /**< Locking object */ 145 __IO hal_iso7816_state_t state; /**< ISO7816 communication state */ 146 __IO hal_iso7816_state_t tx_state; /**< ISO7816 state information related to Tx operations. */ 147 __IO hal_iso7816_state_t rx_state; /**< ISO7816 state information related to Rx operations. */ 148 __IO uint32_t previous_action; /**< ISO7816 previous_action */ 149 __IO uint32_t error_code; /**< ISO7816 error code */ 150 uint32_t retention[6]; /**< ISO7816 important register information. */ 151 } iso7816_handle_t; 152 /** @} */ 153 154 /** @} */ 155 156 /** @addtogroup HAL_ISO7816_CALLBACK_STRUCTURES Callback Structures 157 * @{ 158 */ 159 160 /** @defgroup ISO7816_Callback ISO7816 Callback 161 * @{ 162 */ 163 164 /** 165 * @brief HAL_ISO7816 Callback function definition 166 */ 167 168 typedef struct _iso7816_callback { 169 void (*iso7816_msp_init)(iso7816_handle_t *p_iso7816); /**< ISO7816 init MSP callback */ 170 void (*iso7816_msp_deinit)(iso7816_handle_t *p_iso7816); /**< ISO7816 de-init MSP callback */ 171 void (*iso7816_error_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 error callback */ 172 void (*iso7816_abort_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 abort completed callback */ 173 void (*iso7816_presence_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 card presence state 174 changed callback */ 175 void (*iso7816_atr_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 reseive atr completed callback */ 176 void (*iso7816_tx_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 rx transfer completed callback */ 177 void (*iso7816_rx_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 tx transfer completed callback */ 178 void (*iso7816_tx_rx_cplt_callback)(iso7816_handle_t *p_iso7816); /**< ISO7816 tx/rx transfer 179 completed callback */ 180 } iso7816_callback_t; 181 182 /** @} */ 183 184 /** @} */ 185 186 /** 187 * @defgroup HAL_ISO7816_MACRO Defines 188 * @{ 189 */ 190 191 /* Exported constants --------------------------------------------------------*/ 192 /** @defgroup ISO7816_Exported_Constants ISO7816 Exported Constants 193 * @{ 194 */ 195 196 /** @defgroup ISO7816_ACTION Action state 197 * @{ 198 */ 199 #define HAL_ISO7816_ACTION_NONE LL_ISO7816_ACTION_NONE /**< Do Nothing. */ 200 #define HAL_ISO7816_ACTION_OFF LL_ISO7816_ACTION_OFF /**< Switch Off. */ 201 #define HAL_ISO7816_ACTION_STOPCLK LL_ISO7816_ACTION_STOPCLK /**< Stop the clock. */ 202 #define HAL_ISO7816_ACTION_ON LL_ISO7816_ACTION_ON /**< Switch on and receive ATR. */ 203 #define HAL_ISO7816_ACTION_WARMRST LL_ISO7816_ACTION_WARMRST /**< Trigger warm reset and receive ATR. */ 204 #define HAL_ISO7816_ACTION_RX LL_ISO7816_ACTION_RX /**< Receive. */ 205 #define HAL_ISO7816_ACTION_TX LL_ISO7816_ACTION_TX /**< Transmit. */ 206 #define HAL_ISO7816_ACTION_TXRX LL_ISO7816_ACTION_TXRX /**< Transmit, followed by RX. */ 207 /** @} */ 208 209 /** @defgroup ISO7816_Interrupt_definition ISO7816 Interrupt Definition 210 * @{ 211 */ 212 #define HAL_ISO7816_INTR_TEST LL_ISO7816_INTR_TEST /**< Test interrupt */ 213 #define HAL_ISO7816_INTR_PRESENCE LL_ISO7816_INTR_PRESENCE /**< Source presence interrupt */ 214 #define HAL_ISO7816_INTR_STATE_ERR LL_ISO7816_INTR_STATE_ERR /**< Source state error interrupt */ 215 #define HAL_ISO7816_INTR_DMA_ERR LL_ISO7816_INTR_DMA_ERR /**< Source dma error interrupt */ 216 #define HAL_ISO7816_INTR_RETRY_ERR LL_ISO7816_INTR_RETRY_ERR /**< Source retry error interrupt */ 217 #define HAL_ISO7816_INTR_RX_ERR LL_ISO7816_INTR_RX_ERR /**< Source rx error interrupt */ 218 #define HAL_ISO7816_INTR_DONE LL_ISO7816_INTR_DONE /**< Source done error interrupt */ 219 /** @} */ 220 221 222 /** @defgroup ISO7816_HAL_CARD_PRESENCE Card Presence Defines 223 * @{ 224 */ 225 #define HAL_ISO7816_CARD_ABSENT LL_ISO7816_CARD_ABSENT /**< SIM Card is absent. */ 226 #define HAL_ISO7816_CARD_PRESENT LL_ISO7816_CARD_PRESENT /**< SIM Card is present. */ 227 /** @} */ 228 229 /** @defgroup ISO7816_HAL_IO_STATES IO States Defines 230 * @{ 231 */ 232 #define HAL_ISO7816_IO_STATE_OFF LL_ISO7816_IO_STATE_OFF /**< Off */ 233 #define HAL_ISO7816_IO_STATE_IDLE LL_ISO7816_IO_STATE_IDLE /**< Idle */ 234 #define HAL_ISO7816_IO_STATE_RX_WAIT LL_ISO7816_IO_STATE_RX_WAIT /**< Receive Wait */ 235 #define HAL_ISO7816_IO_STATE_RX LL_ISO7816_IO_STATE_RX /**< Receive */ 236 #define HAL_ISO7816_IO_STATE_TX LL_ISO7816_IO_STATE_TX /**< Transmit */ 237 #define HAL_ISO7816_IO_STATE_TX_GUARD LL_ISO7816_IO_STATE_TX_GUARD /**< Transmit Guard */ 238 /** @} */ 239 240 /** @defgroup ISO7816_HAL_PWR_STATES Power States Defines 241 * @{ 242 */ 243 #define HAL_ISO7816_PWR_STATE_OFF LL_ISO7816_PWR_STATE_OFF /**< Off */ 244 #define HAL_ISO7816_PWR_STATE_PWRUP_VCC LL_ISO7816_PWR_STATE_PWRUP_VCC /**< Power up VCC */ 245 #define HAL_ISO7816_PWR_STATE_PWRUP_RST LL_ISO7816_PWR_STATE_PWRUP_RST /**< Power up reset */ 246 #define HAL_ISO7816_PWR_STATE_PWRDN_RST LL_ISO7816_PWR_STATE_PWRDN_RST /**< Power Down reset */ 247 #define HAL_ISO7816_PWR_STATE_PWRDN_VCC LL_ISO7816_PWR_STATE_PWRDN_VCC /**< Power Down VCC */ 248 #define HAL_ISO7816_PWR_STATE_STOP_PRE LL_ISO7816_PWR_STATE_STOP_PRE /**< Preparing Clock Stop */ 249 #define HAL_ISO7816_PWR_STATE_STOP LL_ISO7816_PWR_STATE_STOP /**< Clock Stopped */ 250 #define HAL_ISO7816_PWR_STATE_STOP_POST LL_ISO7816_PWR_STATE_STOP_POST /**< Exiting Clock Stop */ 251 #define HAL_ISO7816_PWR_STATE_IDLE LL_ISO7816_PWR_STATE_IDLE /**< Idle */ 252 #define HAL_ISO7816_PWR_STATE_RX_TS0 LL_ISO7816_PWR_STATE_RX_TS0 /**< RX TS Character */ 253 #define HAL_ISO7816_PWR_STATE_RX_TS1 LL_ISO7816_PWR_STATE_RX_TS1 /**< RX TS Character */ 254 #define HAL_ISO7816_PWR_STATE_RX LL_ISO7816_PWR_STATE_RX /**< Receive */ 255 #define HAL_ISO7816_PWR_STATE_TX LL_ISO7816_PWR_STATE_TX /**< Transmit */ 256 #define HAL_ISO7816_PWR_STATE_TX_RX LL_ISO7816_PWR_STATE_TX_RX /**< Transmit and Receive */ 257 /** @} */ 258 259 /** @defgroup ISO7816_Error_Code ISO7816 Error Code 260 * @{ 261 */ 262 #define HAL_ISO7816_ERROR_NONE ((uint32_t)0x00000000) /**< No error */ 263 #define HAL_ISO7816_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */ 264 #define HAL_ISO7816_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */ 265 #define HAL_ISO7816_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /**< Invalid parameters error */ 266 /** @} */ 267 268 /** @} */ 269 270 /* Exported macro ------------------------------------------------------------*/ 271 /** @defgroup ISO7816_Exported_Macros ISO7816 Exported Macros 272 * @{ 273 */ 274 275 /** @brief Enable the specified ISO7816 interrupts. 276 * @param __HANDLE__ Specifies the ISO7816 Handle. 277 * @param __INTERRUPT__ Specifies the interrupt source to enable. 278 * This parameter can be one of the following values: 279 * @arg @ref HAL_ISO7816_INTR_TEST Test interrupt 280 * @arg @ref HAL_ISO7816_INTR_PRESENCE Presence interrupt 281 * @arg @ref HAL_ISO7816_INTR_STATE_ERR State error interrupt 282 * @arg @ref HAL_ISO7816_INTR_DMA_ERR DMA error interrupt 283 * @arg @ref HAL_ISO7816_INTR_RETRY_ERR Retry error interrupt 284 * @arg @ref HAL_ISO7816_INTR_RX_ERR Rx error interrupt 285 * @arg @ref HAL_ISO7816_INTR_DONE Done error interrupt 286 * @retval None 287 */ 288 #define HAL_ISO7816_ENABLE_IT(__HANDLE__, __INTERRUPT__) \ 289 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__) \ 305 CLEAR_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__)) 306 307 /** @brief Get the ISO7816 interrupt flags. 308 * @param __ISO7816_REGS ISO7816 Register. 309 * @retval ISO78116 Interrupt definitions. 310 */ 311 #define HAL_ISO7816_IT_GET_IT_FLAG(__ISO7816_REGS) ll_iso7816_get_it_flag(__ISO7816_REGS) 312 /** @} */ 313 /** @} */ 314 315 316 /* Exported functions --------------------------------------------------------*/ 317 /** @addtogroup HAL_ISO7816_DRIVER_FUNCTIONS Functions 318 * @{ 319 */ 320 /** 321 * @brief Transimit data in blocking mode 322 * 323 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information 324 * for the specified ISO7816. 325 * @param tx_size Bytes of data to transmit 326 * @param timeout Timeout duration 327 * @retval ::HAL_OK: Operation is OK. 328 * @retval ::HAL_ERROR: Parameter error or operation not supported. 329 * @retval ::HAL_BUSY: Driver is busy. 330 * @retval ::HAL_TIMEOUT: Timeout occurred. 331 */ 332 hal_status_t hal_iso7816_transmit(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint32_t timeout); 333 334 /** 335 * @brief Receive data in blocking mode 336 * 337 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information 338 * for the specified ISO7816. 339 * @param rx_size Bytes of data to receive 340 * @param timeout Timeout duration 341 * @retval ::HAL_OK: Operation is OK. 342 * @retval ::HAL_ERROR: Parameter error or operation not supported. 343 * @retval ::HAL_BUSY: Driver is busy. 344 * @retval ::HAL_TIMEOUT: Timeout occurred. 345 */ 346 hal_status_t hal_iso7816_receive(iso7816_handle_t *p_iso7816, uint16_t rx_size, uint32_t timeout); 347 348 /** 349 * @brief Transimit and receive data in blocking mode 350 * 351 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information 352 * for the specified ISO7816. 353 * @param tx_size Bytes of data to transmit 354 * @param rx_size Bytes of data to receive 355 * @param timeout Timeout duration 356 * @retval ::HAL_OK: Operation is OK. 357 * @retval ::HAL_ERROR: Parameter error or operation not supported. 358 * @retval ::HAL_BUSY: Driver is busy. 359 * @retval ::HAL_TIMEOUT: Timeout occurred. 360 */ 361 hal_status_t hal_iso7816_transmit_receive(iso7816_handle_t *p_iso7816, uint16_t tx_size, 362 uint16_t rx_size, uint32_t timeout); 363 364 /** 365 * @brief Transimit data in non-blocking mode with Interrupt 366 * 367 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information 368 * for the specified ISO7816. 369 * @param tx_size Bytes of data to transmit 370 * @retval ::HAL_OK: Operation is OK. 371 * @retval ::HAL_ERROR: Parameter error or operation not supported. 372 * @retval ::HAL_BUSY: Driver is busy. 373 * @retval ::HAL_TIMEOUT: Timeout occurred. 374 */ 375 hal_status_t hal_iso7816_transmit_it(iso7816_handle_t *p_iso7816, uint16_t tx_size); 376 377 /** 378 * @brief Receive data in non-blocking mode with Interrupt 379 * 380 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information 381 * for the specified ISO7816. 382 * @param rx_size Bytes of data to receive 383 * @retval ::HAL_OK: Operation is OK. 384 * @retval ::HAL_ERROR: Parameter error or operation not supported. 385 * @retval ::HAL_BUSY: Driver is busy. 386 * @retval ::HAL_TIMEOUT: Timeout occurred. 387 */ 388 hal_status_t hal_iso7816_receive_it(iso7816_handle_t *p_iso7816, uint16_t rx_size); 389 390 /** 391 * @brief Transimit and receive data in non-blocking mode with Interrupt 392 * 393 * @param p_iso7816: Pointer to an ISO7816 handle which contains the configuration information 394 * for the specified ISO7816. 395 * @param tx_size: Bytes of data to transfer. 396 * @param rx_size: Bytes of data to receive. 397 * @retval ::HAL_OK: Operation is OK. 398 * @retval ::HAL_ERROR: Parameter error or operation not supported. 399 * @retval ::HAL_BUSY: Driver is busy. 400 * @retval ::HAL_TIMEOUT: Timeout occurred. 401 */ 402 403 hal_status_t hal_iso7816_transmit_receive_it(iso7816_handle_t *p_iso7816, uint16_t tx_size, uint16_t rx_size); 404 405 /** 406 * @brief Transfer Abort functions 407 * 408 * @param p_iso7816 Pointer to an ISO7816 handle which contains the configuration information 409 * for the specified ISO7816. 410 * @retval ::HAL_OK: Operation is OK. 411 * @retval ::HAL_ERROR: Parameter error or operation not supported. 412 * @retval ::HAL_BUSY: Driver is busy. 413 * @retval ::HAL_TIMEOUT: Timeout occurred. 414 */ 415 hal_status_t hal_iso7816_abort(iso7816_handle_t *p_iso7816); 416 417 /** 418 **************************************************************************************** 419 * @brief Initializes the ISO7816 according to the specified parameters 420 * in the iso7816_init_t and initialize the associated handle. 421 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 422 * information for the specified ISO7816. 423 * @retval ::HAL_OK: Operation is OK. 424 * @retval ::HAL_ERROR: Parameter error or operation not supported. 425 * @retval ::HAL_BUSY: Driver is busy. 426 * @retval ::HAL_TIMEOUT: Timeout occurred. 427 **************************************************************************************** 428 */ 429 hal_status_t hal_iso7816_init(iso7816_handle_t *p_iso7816); 430 431 /** 432 **************************************************************************************** 433 * @brief De-initializes the ISO7816 according to the specified parameters 434 * in the iso7816_init_t and initialize the associated handle. 435 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 436 * information for the specified ISO7816. 437 * @retval ::HAL_OK: Operation is OK. 438 * @retval ::HAL_ERROR: Parameter error or operation not supported. 439 * @retval ::HAL_BUSY: Driver is busy. 440 * @retval ::HAL_TIMEOUT: Timeout occurred. 441 **************************************************************************************** 442 */ 443 hal_status_t hal_iso7816_deinit(iso7816_handle_t *p_iso7816); 444 445 /** 446 **************************************************************************************** 447 * @brief Initialize the ISO7816 MSP. 448 * @note This function should not be modified. When the callback is needed, 449 * the hal_iso7816_msp_init could be implemented in the user file. 450 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 451 * information for the specified ISO7816. 452 **************************************************************************************** 453 */ 454 void hal_iso7816_msp_init(iso7816_handle_t *p_iso7816); 455 456 /** 457 **************************************************************************************** 458 * @brief De-initialize the ISO7816 MSP. 459 * @note This function should not be modified. When the callback is needed, 460 * the hal_iso7816_msp_deinit could be implemented in the user file. 461 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 462 * information for the specified ISO7816. 463 **************************************************************************************** 464 */ 465 void hal_iso7816_msp_deinit(iso7816_handle_t *p_iso7816); 466 /** 467 **************************************************************************************** 468 * @brief Handle ISO7816 interrupt request. 469 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 470 * information for the specified ISO7816. 471 **************************************************************************************** 472 */ 473 void hal_iso7816_irq_handler(iso7816_handle_t *p_iso7816); 474 475 476 /** 477 **************************************************************************************** 478 * @brief Card presence state changed callback. 479 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 480 * information for the specified ISO7816. 481 **************************************************************************************** 482 */ 483 void hal_iso7816_presence_callback(iso7816_handle_t *p_iso7816); 484 485 /** 486 **************************************************************************************** 487 * @brief Receive completed callback. 488 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 489 * information for the specified ISO7816. 490 **************************************************************************************** 491 */ 492 void hal_iso7816_atr_cplt_callback(iso7816_handle_t *p_iso7816); 493 494 /** 495 **************************************************************************************** 496 * @brief Rx Transfer completed callback. 497 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 498 * information for the specified ISO7816. 499 **************************************************************************************** 500 */ 501 void hal_iso7816_rx_cplt_callback(iso7816_handle_t *p_iso7816); 502 503 /** 504 **************************************************************************************** 505 * @brief Tx Transfer completed callback. 506 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 507 * information for the specified ISO7816. 508 **************************************************************************************** 509 */ 510 void hal_iso7816_tx_cplt_callback(iso7816_handle_t *p_iso7816); 511 512 /** 513 **************************************************************************************** 514 * @brief Tx and Rx Transfer completed callback. 515 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 516 * information for the specified ISO7816. 517 **************************************************************************************** 518 */ 519 void hal_iso7816_tx_rx_cplt_callback(iso7816_handle_t *p_iso7816); 520 521 /** 522 **************************************************************************************** 523 * @brief ISO7816 error callback. 524 * @param[in] p_iso7816: Pointer to an ISO7816 handle which contains the configuration 525 * information for the specified ISO7816. 526 **************************************************************************************** 527 */ 528 void hal_iso7816_error_callback(iso7816_handle_t *p_iso7816); 529 530 /** 531 **************************************************************************************** 532 * @brief ISO7816 Abort Completed callback. 533 * @param[in] p_iso7816: ISO7816 handle. 534 **************************************************************************************** 535 */ 536 void hal_iso7816_abort_cplt_callback(iso7816_handle_t *p_iso7816); 537 538 /** 539 **************************************************************************************** 540 * @brief Return the ISO7816 handle state. 541 * @param[in] p_iso7816: ISO7816 handle. 542 * @retval ::HAL_ISO7816_STATE_RESET 543 * @retval ::HAL_ISO7816_STATE_READY 544 * @retval ::HAL_ISO7816_STATE_BUSY 545 * @retval ::HAL_ISO7816_STATE_BUSY_TX 546 * @retval ::HAL_ISO7816_STATE_BUSY_RX 547 * @retval ::HAL_ISO7816_STATE_BUSY_TX_RX 548 * @retval ::HAL_ISO7816_STATE_ABORT 549 * @retval ::HAL_ISO7816_STATE_TIMEOUT 550 * @retval ::HAL_ISO7816_STATE_ERROR 551 **************************************************************************************** 552 */ 553 hal_iso7816_state_t hal_iso7816_get_state(iso7816_handle_t *p_iso7816); 554 555 /** 556 * @brief Request ISO7816 to go to the next action. 557 * @param p_iso7816: ISO7816 handle. 558 * @param action: This parameter can be one of the following values: 559 * @arg @ref HAL_ISO7816_ACTION_NONE 560 * @arg @ref HAL_ISO7816_ACTION_OFF 561 * @arg @ref HAL_ISO7816_ACTION_STOPCLK 562 * @arg @ref HAL_ISO7816_ACTION_ON 563 * @arg @ref HAL_ISO7816_ACTION_WARMRST 564 * @arg @ref HAL_ISO7816_ACTION_RX 565 * @arg @ref HAL_ISO7816_ACTION_TX 566 * @arg @ref HAL_ISO7816_ACTION_TXRX 567 * @retval ::HAL_OK: Operation is OK. 568 * @retval ::HAL_ERROR: Parameter error or operation not supported. 569 * @retval ::HAL_BUSY: Driver is busy. 570 */ 571 hal_status_t hal_iso7816_set_action(iso7816_handle_t *p_iso7816, uint32_t action); 572 573 /** 574 * @brief Get ISO7816 Power States. 575 * @param p_iso7816: ISO7816 handle. 576 * @retval Returned value can be one of the following values: 577 * @arg @ref HAL_ISO7816_PWR_STATE_OFF 578 * @arg @ref HAL_ISO7816_PWR_STATE_PWRUP_VCC 579 * @arg @ref HAL_ISO7816_PWR_STATE_PWRUP_RST 580 * @arg @ref HAL_ISO7816_PWR_STATE_PWRDN_RST 581 * @arg @ref HAL_ISO7816_PWR_STATE_PWRDN_VCC 582 * @arg @ref HAL_ISO7816_PWR_STATE_STOP_PRE 583 * @arg @ref HAL_ISO7816_PWR_STATE_STOP 584 * @arg @ref HAL_ISO7816_PWR_STATE_STOP_POST 585 * @arg @ref HAL_ISO7816_PWR_STATE_IDLE 586 * @arg @ref HAL_ISO7816_PWR_STATE_RX_TS0 587 * @arg @ref HAL_ISO7816_PWR_STATE_RX_TS1 588 * @arg @ref HAL_ISO7816_PWR_STATE_RX 589 * @arg @ref HAL_ISO7816_PWR_STATE_TX 590 * @arg @ref HAL_ISO7816_PWR_STATE_TX_RX 591 */ 592 uint32_t hal_iso7816_get_power_states(iso7816_handle_t *p_iso7816); 593 594 /** 595 * @brief Set divide ISO7816 clock. 596 * @note Divide SIM clock by this value+1 to define ETU length. The reset value 597 * is the one, needed for theATR. 598 * @param p_iso7816: ISO7816 handle. 599 * @param divide This parameter should range between 0x0 and 0x3FF. 600 * @retval None. 601 */ 602 hal_status_t hal_iso7816_set_etudiv(iso7816_handle_t *p_iso7816, uint32_t divide); 603 604 /** 605 **************************************************************************************** 606 * @brief Return the ISO7816 error code. 607 * @param[in] p_iso7816: ISO7816 handle. 608 * @return ISO7816 Error Code 609 **************************************************************************************** 610 */ 611 uint32_t hal_iso7816_get_error(iso7816_handle_t *p_iso7816); 612 613 /** 614 **************************************************************************************** 615 * @brief Suspend some registers related to ISO7816 configuration before sleep. 616 * @param[in] p_iso7816: ISO7816 handle. 617 * @retval ::HAL_OK: Operation is OK. 618 * @retval ::HAL_ERROR: Parameter error or operation not supported. 619 * @retval ::HAL_BUSY: Driver is busy. 620 * @retval ::HAL_TIMEOUT: Timeout occurred. 621 **************************************************************************************** 622 */ 623 hal_status_t hal_iso7816_suspend_reg(iso7816_handle_t *p_iso7816); 624 625 /** 626 **************************************************************************************** 627 * @brief Restore some registers related to ISO7816 configuration after sleep. 628 * This function must be used in conjunction with the hal_iso7816_suspend_reg(). 629 * @param[in] p_iso7816: ISO7816 handle. 630 * @retval ::HAL_OK: Operation is OK. 631 * @retval ::HAL_ERROR: Parameter error or operation not supported. 632 * @retval ::HAL_BUSY: Driver is busy. 633 * @retval ::HAL_TIMEOUT: Timeout occurred. 634 **************************************************************************************** 635 */ 636 hal_status_t hal_iso7816_resume_reg(iso7816_handle_t *p_iso7816); 637 638 /** @} */ 639 640 #ifdef __cplusplus 641 } 642 #endif 643 644 #endif /* __GR55xx_HAL_ISO7816_H__ */ 645 646 /** @} */ 647 648 /** @} */ 649 650 /** @} */ 651