1 //***************************************************************************** 2 // 3 //! @file am_hal_scard.h 4 //! 5 //! @brief Functions for interfacing with the SCARD. 6 //! 7 //! @addtogroup scard3 SCARD - SCARD Functionality 8 //! @ingroup apollo3_hal 9 //! @{ 10 // 11 //***************************************************************************** 12 13 //***************************************************************************** 14 // 15 // Copyright (c) 2024, Ambiq Micro, Inc. 16 // All rights reserved. 17 // 18 // Redistribution and use in source and binary forms, with or without 19 // modification, are permitted provided that the following conditions are met: 20 // 21 // 1. Redistributions of source code must retain the above copyright notice, 22 // this list of conditions and the following disclaimer. 23 // 24 // 2. Redistributions in binary form must reproduce the above copyright 25 // notice, this list of conditions and the following disclaimer in the 26 // documentation and/or other materials provided with the distribution. 27 // 28 // 3. Neither the name of the copyright holder nor the names of its 29 // contributors may be used to endorse or promote products derived from this 30 // software without specific prior written permission. 31 // 32 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 33 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 36 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 37 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 40 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 41 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42 // POSSIBILITY OF SUCH DAMAGE. 43 // 44 // This is part of revision release_sdk_3_2_0-dd5f40c14b of the AmbiqSuite Development Package. 45 // 46 //***************************************************************************** 47 #ifndef AM_HAL_SCARD_H 48 #define AM_HAL_SCARD_H 49 50 #ifdef __cplusplus 51 extern "C" 52 { 53 #endif 54 55 //***************************************************************************** 56 // 57 //! CMSIS-style macro for handling a variable SCARD module number. 58 // 59 //***************************************************************************** 60 #define SCARDn(n) ((SCARD_Type*)(SCARD_BASE + (n * (SCARD_BASE - SCARD_BASE)))) 61 62 //***************************************************************************** 63 // 64 //! Initial character TS 65 // 66 //***************************************************************************** 67 #define AM_HAL_SCARD_DIR_MSB 0x3F //(H)LHHL LLL LLH, state L encodes value 1, msb 68 #define AM_HAL_SCARD_DIR_LSB 0x3B //(H)LHHL HHH LLH, state H encodes value 1, lsb 69 70 //***************************************************************************** 71 // 72 //! Informations provided by T0 73 // 74 //***************************************************************************** 75 #define AM_HAL_SCARD_T0_BIT_TA1_MASK (1 << 4) 76 #define AM_HAL_SCARD_T0_BIT_TB1_MASK (1 << 5) 77 #define AM_HAL_SCARD_T0_BIT_TC1_MASK (1 << 6) 78 #define AM_HAL_SCARD_T0_BIT_TD1_MASK (1 << 7) 79 80 #define AM_HAL_SCARD_TA1_PRESENCE(T0) (((T0) & AM_HAL_SCARD_T0_BIT_TA1_MASK) == AM_HAL_SCARD_T0_BIT_TA1_MASK) 81 #define AM_HAL_SCARD_TB1_PRESENCE(T0) (((T0) & AM_HAL_SCARD_T0_BIT_TB1_MASK) == AM_HAL_SCARD_T0_BIT_TB1_MASK) 82 #define AM_HAL_SCARD_TC1_PRESENCE(T0) (((T0) & AM_HAL_SCARD_T0_BIT_TC1_MASK) == AM_HAL_SCARD_T0_BIT_TC1_MASK) 83 #define AM_HAL_SCARD_TD1_PRESENCE(T0) (((T0) & AM_HAL_SCARD_T0_BIT_TD1_MASK) == AM_HAL_SCARD_T0_BIT_TD1_MASK) 84 85 #define AM_HAL_SCARD_HISTORY_LEN(T0) ((T0)&0x0F) 86 87 //***************************************************************************** 88 // 89 //! Protocol type T 90 // 91 //***************************************************************************** 92 #define AM_HAL_SCARD_PROTOCOL_T0 0 93 #define AM_HAL_SCARD_PROTOCOL_T1 1 94 #define AM_HAL_SCARD_PROTOCOL_T15 15 95 96 #define AM_HAL_SCARD_PROTOCOL_DEFAULT AM_HAL_SCARD_PROTOCOL_T0 97 98 //***************************************************************************** 99 // 100 //! Structure and content of PPS request and PPS confirm 101 // 102 //***************************************************************************** 103 #define AM_HAL_SCARD_CLA_PPS 0xFF 104 105 #define AM_HAL_SCARD_PPS1_PRESENCE(PPS0) (((PPS0) & (1 << 4)) == (1 << 4)) 106 #define AM_HAL_SCARD_PPS2_PRESENCE(PPS0) (((PPS0) & (1 << 5)) == (1 << 5)) 107 #define AM_HAL_SCARD_PPS3_PRESENCE(PPS0) (((PPS0) & (1 << 6)) == (1 << 6)) 108 109 //***************************************************************************** 110 // 111 //! Informations provided by TA1 112 // 113 //***************************************************************************** 114 #define AM_HAL_SCARD_FI(TA1) (((TA1) >> 4) & 0x0F) 115 #define AM_HAL_SCARD_DI(TA1) (((TA1) >> 0) & 0x0F) 116 117 #define AM_HAL_SCARD_FI_DI_DEFAULT 0x11 118 119 //***************************************************************************** 120 // 121 //! Informations provided by TDi 122 // 123 //***************************************************************************** 124 #define AM_HAL_SCARD_TDi_BIT_TAiP1_MASK (1 << 4) 125 #define AM_HAL_SCARD_TDi_BIT_TBiP1_MASK (1 << 5) 126 #define AM_HAL_SCARD_TDi_BIT_TCiP1_MASK (1 << 6) 127 #define AM_HAL_SCARD_TDi_BIT_TDiP1_MASK (1 << 7) 128 129 #define AM_HAL_SCARD_TAiP1_PRESENCE(TDi) (((TDi) & AM_HAL_SCARD_TDi_BIT_TAiP1_MASK) == AM_HAL_SCARD_TDi_BIT_TAiP1_MASK) 130 #define AM_HAL_SCARD_TBiP1_PRESENCE(TDi) (((TDi) & AM_HAL_SCARD_TDi_BIT_TBiP1_MASK) == AM_HAL_SCARD_TDi_BIT_TBiP1_MASK) 131 #define AM_HAL_SCARD_TCiP1_PRESENCE(TDi) (((TDi) & AM_HAL_SCARD_TDi_BIT_TCiP1_MASK) == AM_HAL_SCARD_TDi_BIT_TCiP1_MASK) 132 #define AM_HAL_SCARD_TDiP1_PRESENCE(TDi) (((TDi) & AM_HAL_SCARD_TDi_BIT_TDiP1_MASK) == AM_HAL_SCARD_TDi_BIT_TDiP1_MASK) 133 134 #define AM_HAL_SCARD_PROTOCOL_TYPE(TDi) ((TDi) & 0x0F) 135 136 #define AM_HAL_SCARD_MAX_ATR_LENGTH 33 //1+32 137 #define AM_HAL_SCARD_MAX_PPS_LENGTH 6 138 #define AM_HAL_SCARD_APDU_HEADER_LENGTH 5 139 #define AM_HAL_SCARD_SW_LENGTH 2 140 141 //***************************************************************************** 142 // 143 //! TypeDefs 144 // 145 //***************************************************************************** 146 typedef struct 147 { 148 uint8_t pps0; 149 uint8_t pps1; 150 uint8_t pps2; 151 uint8_t pps3; 152 }am_hal_scard_pps_t; 153 154 typedef struct 155 { 156 uint8_t cla; 157 uint8_t ins; 158 uint8_t p1; 159 uint8_t p2; 160 uint8_t p3; 161 }am_hal_scard_header_t; 162 163 typedef struct 164 { 165 am_hal_scard_header_t header; 166 uint8_t data[256]; 167 }am_hal_scard_tpdu_t; 168 169 typedef union 170 { 171 struct 172 { 173 uint8_t s0; 174 uint8_t s1; 175 }element; 176 177 uint16_t entirety; 178 }am_hal_scard_sw_t; 179 180 typedef enum 181 { 182 AM_HAL_SCARD_CONV_AUTO, 183 AM_HAL_SCARD_CONV_LSB_0X3B, 184 AM_HAL_SCARD_CONV_MSB_0X3F 185 }am_hal_scard_cardformat_e; 186 187 typedef enum 188 { 189 AM_HAL_SCARD_EVEN, 190 AM_HAL_SCARD_ODD 191 }am_hal_scard_parity_e; 192 193 typedef enum 194 { 195 AM_HAL_SCARD_APDU_CLA, 196 AM_HAL_SCARD_APDU_INS, 197 AM_HAL_SCARD_APDU_P1, 198 AM_HAL_SCARD_APDU_P2, 199 AM_HAL_SCARD_APDU_LC 200 }am_hal_scard_apdu_header_e; 201 202 //***************************************************************************** 203 // 204 // Definitions 205 // 206 //***************************************************************************** 207 #define SCARD_RST_LOW_TIME 42000 208 209 #define AM_HAL_SCARD_PARITY_ENABLE 0x10 210 211 //***************************************************************************** 212 // 213 //! SCARD configuration options. 214 // 215 //***************************************************************************** 216 typedef struct 217 { 218 // 219 //! Standard SCARD options. 220 // 221 uint32_t ui32Fidi; 222 uint32_t ui32Protocol; 223 uint32_t ui32Direction; 224 uint32_t ui32Parity; 225 uint32_t ui32GuardTime; 226 uint32_t ui32ClkLevel; 227 228 // 229 //! Timeouts 230 // 231 uint32_t ui32TxTimeout; 232 uint32_t ui32RxTimeout; 233 234 // 235 //! Buffers 236 // 237 uint8_t *pui8TxBuffer; 238 uint32_t ui32TxBufferSize; 239 uint8_t *pui8RxBuffer; 240 uint32_t ui32RxBufferSize; 241 } 242 am_hal_scard_config_t; 243 244 typedef enum 245 { 246 AM_HAL_SCARD_REQ_ACTIVATE = 0, 247 AM_HAL_SCARD_REQ_DEACTIVATE, 248 AM_HAL_SCARD_REQ_BAUDRATE, 249 AM_HAL_SCARD_REQ_CARD_FORMAT, 250 AM_HAL_SCARD_REQ_PARITY, 251 AM_HAL_SCARD_REQ_PROTOCOL, 252 AM_HAL_SCARD_REQ_GUARDTIME, 253 AM_HAL_SCARD_REQ_CLK_START, 254 AM_HAL_SCARD_REQ_CLK_STOP, 255 AM_HAL_SCARD_REQ_MAX 256 }am_hal_scard_request_e; 257 258 //***************************************************************************** 259 // 260 //! @brief SCARD transfer structure. 261 //! 262 //! This structure describes a SCARD transaction that can be performed by \e 263 //! am_hal_scard_transfer() 264 // 265 //***************************************************************************** 266 typedef struct 267 { 268 //! Determines whether data should be read or written. 269 //! 270 //! Should be either AM_HAL_SCARD_WRITE or AM_HAL_SCARD_READ 271 uint32_t ui32Direction; 272 273 //! Pointer to data to be sent, or space to fill with received data. 274 uint8_t *pui8Data; 275 276 //! Number of bytes to send or receive. 277 uint32_t ui32NumBytes; 278 279 //! Timeout in milliseconds. 280 //! 281 //! Given a timeout value, the \e am_hal_scard_transfer() function will keep 282 //! trying to transfer data until either the number of bytes is satisfied, 283 //! or the time runs out. If provided with a value of zero, the transfer 284 //! function will only send as much data as it can immediately deal with. 285 //! If provided with a timeout value of \e AM_HAL_SCARD_WAIT_FOREVER, the 286 //! function will block until either the final "read" byte is received or 287 //! the final "write" byte is placed in the output buffer. 288 uint32_t ui32TimeoutMs; 289 290 //! Number of bytes successfully transferred. 291 uint32_t *pui32BytesTransferred; 292 } 293 am_hal_scard_transfer_t; 294 295 //***************************************************************************** 296 // 297 //! Scard transfer options. 298 // 299 //***************************************************************************** 300 #define AM_HAL_SCARD_WRITE 1 301 #define AM_HAL_SCARD_READ 0 302 #define AM_HAL_SCARD_WAIT_MAX_TIME 0xFFFF 303 #define AM_HAL_SCARD_WAIT_FOREVER 0xFFFFFFFF 304 #define AM_HAL_SCARD_CLK_FREQ 3000000 305 306 //***************************************************************************** 307 // 308 //! SCARD interrupts. 309 // 310 //***************************************************************************** 311 #define AM_HAL_SCARD_INT_FHFEN SCARD_IER_FHFEN_Msk 312 #define AM_HAL_SCARD_INT_FT2RENDEN SCARD_IER_FT2RENDEN_Msk 313 #define AM_HAL_SCARD_INT_PEEN SCARD_IER_PEEN_Msk 314 #define AM_HAL_SCARD_INT_OVREN SCARD_IER_OVREN_Msk 315 #define AM_HAL_SCARD_INT_FEREN SCARD_IER_FEREN_Msk 316 #define AM_HAL_SCARD_INT_TBERBFEN SCARD_IER_TBERBFEN_Msk 317 #define AM_HAL_SCARD_INT_FNEEN SCARD_IER_FNEEN_Msk 318 #define AM_HAL_SCARD_INT_SYNCENDEN SCARD_IER1_SYNCENDEN_Msk 319 #define AM_HAL_SCARD_INT_PRLEN SCARD_IER1_PRLEN_Msk 320 #define AM_HAL_SCARD_INT_ECNTOVEREN SCARD_IER1_ECNTOVEREN_Msk 321 #define AM_HAL_SCARD_INT_ALL 0xFFFFFFFF 322 323 //***************************************************************************** 324 // 325 //! @brief Macro definitions for SCARD Status Register Bits. 326 //! @name SCARD Status Register 327 //! @{ 328 // 329 //***************************************************************************** 330 #define AM_HAL_SCARD_SR_TX_EMPTY (_VAL2FLD(SCARD_SR_TBERBF, 1)) 331 #define AM_HAL_SCARD_SR_RX_FULL (_VAL2FLD(SCARD_SR_TBERBF, 1)) 332 #define AM_HAL_SCARD_SR_RX_HALF_FULL (_VAL2FLD(SCARD_SR_FHF, 1)) 333 #define AM_HAL_SCARD_SR_RX_NOT_EMPTY (_VAL2FLD(SCARD_SR_FNE, 1)) 334 #define AM_HAL_SCARD_SR_FT2REND (_VAL2FLD(SCARD_SR_FT2REND, 1)) 335 #define AM_HAL_SCARD_SR_IDLE (_VAL2FLD(SCARD_SR1_IDLE, 1)) 336 //! @} end SCARD Status Register 337 338 //***************************************************************************** 339 // 340 //! SCC FIFO size for Apollo3. 341 // 342 //***************************************************************************** 343 #define AM_HAL_SCARD_FIFO_MAX 8 344 345 //***************************************************************************** 346 // 347 //! @brief Initialize the SCARD interface. 348 //! 349 //! @param ui32Module - the module number for the SCARD to initialize. 350 //! @param ppHandle - the location to write the SCARD handle. 351 //! 352 //! This function sets internal tracking variables associated with a specific 353 //! SCARD module. It should be the first SCARD API called for each SCARD module in 354 //! use. The handle can be used to interact with the SCARD 355 //! 356 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 357 // 358 //***************************************************************************** 359 extern uint32_t am_hal_scard_initialize(uint32_t ui32Module, void **ppHandle); 360 361 //***************************************************************************** 362 // 363 //! @brief Deinitialize the SCARD interface. 364 //! 365 //! @param pHandle - a previously initialized SCARD handle. 366 //! 367 //! This function effectively disables future calls to interact with the SCARD 368 //! refered to by \e pHandle. The user may call this function if SCARD operation 369 //! is no longer desired. 370 //! 371 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 372 // 373 //***************************************************************************** 374 extern uint32_t am_hal_scard_deinitialize(void *pHandle); 375 376 //***************************************************************************** 377 // 378 //! @brief Change the power state of the SCARD module. 379 //! 380 //! @param pHandle - the handle for the SCARD to operate on. 381 //! @param ePowerState - the desired power state of the SCARD. 382 //! @param bRetainState - a flag to ask the HAL to save SCARD registers. 383 //! 384 //! This function can be used to switch the power to the SCARD on or off. If \e 385 //! bRetainState is true during a powerdown operation, it will store the SCARD 386 //! configuration registers to SRAM, so it can restore them on power-up. 387 //! 388 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 389 // 390 //***************************************************************************** 391 extern uint32_t am_hal_scard_power_control(void *pHandle, 392 am_hal_sysctrl_power_state_e ePowerState, 393 bool bRetainState); 394 395 //***************************************************************************** 396 // 397 //! @brief Used to configure basic SCARD settings. 398 //! 399 //! @param pHandle - the handle for the SCARD to operate on. 400 //! @param psConfig - a structure of SCARD configuration options. 401 //! 402 //! This function takes the options from an \e am_hal_scard_config_t structure, 403 //! and applies them to the SCARD referred to by \e pHandle. 404 //! 405 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 406 // 407 //***************************************************************************** 408 extern uint32_t am_hal_scard_configure(void *pHandle, 409 am_hal_scard_config_t *psConfig); 410 411 //***************************************************************************** 412 // 413 //! @brief Transfer data through the SCARD interface. 414 //! 415 //! @param pHandle - the handle for the SCARD to operate on. 416 //! @param pTransfer - a structure describing the operation. 417 //! 418 //! This function executes a transaction as described by the \e 419 //! am_hal_scard_transfer_t structure. It can either read or write, and it will 420 //! take advantage of any buffer space provided by the \e 421 //! am_hal_scard_configure() function. 422 //! 423 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 424 // 425 //***************************************************************************** 426 extern uint32_t am_hal_scard_transfer(void *pHandle, 427 const am_hal_scard_transfer_t *pTransfer); 428 429 430 //***************************************************************************** 431 // 432 //! @brief Wait for the SCARD TX to become idle 433 //! 434 //! @param pHandle - The handle for the SCARD to operate on. 435 //! 436 //! This function waits (polling) for all data in the SCARD TX FIFO and SCARD TX 437 //! buffer (if configured) to be fully sent on the physical SCARD interface. 438 //! This is not the most power-efficient way to wait for SCARD idle, but it can be 439 //! useful in simpler applications, or where power-efficiency is less important. 440 //! 441 //! Once this function returns, the SCARD can be safely disabled without 442 //! interfering with any previous transmissions. 443 //! 444 //! @note For a more power-efficient way to shut down the SCARD, check the 445 //! \e am_hal_scard_interrupt_service() function. 446 //! 447 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 448 // 449 //***************************************************************************** 450 extern uint32_t am_hal_scard_tx_flush(void *pHandle); 451 452 //***************************************************************************** 453 // 454 //! @brief This function handles the SCARD buffers during SCARD interrupts. 455 //! 456 //! @param pHandle - The handle for the SCARD to operate on. 457 //! @param ui32Status - The interrupt status at the time of ISR entry. 458 //! @param pui32ScardTxIdle - Can be used to store the SCARD idle status. 459 //! 460 //! The main purpose of this function is to manage the SCARD buffer system. Any 461 //! buffers configured by \e am_hal_scard_buffer_configure will be managed by 462 //! this service routine. Data queued for transmit will be added to the SCARD TX 463 //! FIFO as space allows, and data stored in the SCARD RX FIFO will be copied 464 //! out and stored in the RX buffer. This function will skip this transfer for 465 //! any buffer that has not been configured. 466 //! 467 //! In addition, this function can be used to alert the caller when the SCARD 468 //! becomes idle via the optional \e pui32ScardTxIdle argument. This function 469 //! will set this variable any time it completes its operation and the SCARD TX 470 //! channel is no longer in use (including both the FIFO and any configured 471 //! buffer). 472 //! 473 //! For RTOS-enabled cases, this function does not necessarily need to be 474 //! called inside the actual ISR for the SCARD, but it should be called promptly 475 //! in response to the receipt of a SCARD TX, RX, or RX timeout interrupt. If 476 //! the service routine is not called quickly enough, the caller risks an RX 477 //! FIFO overflow (data can be lost here), or a TX FIFO underflow (usually not 478 //! harmful). 479 //! 480 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 481 // 482 //***************************************************************************** 483 extern uint32_t am_hal_scard_interrupt_service(void *pHandle, 484 uint32_t ui32Status, 485 uint32_t *pui32ScardTxIdle); 486 487 //***************************************************************************** 488 // 489 //! @brief Enable interrupts. 490 //! 491 //! @param pHandle - the handle for the SCARD to operate on. 492 //! @param ui32Index - IER(0) or IER1 493 //! @param ui32IntMask - is the bitmask of interrupts to enable. 494 //! 495 //! This function enables the SCARD interrupt(s) given by ui32IntMask. If 496 //! multiple interrupts are desired, they can be OR'ed together. 497 //! 498 //! @note This function need not be called for SCARD FIFO interrupts if the SCARD 499 //! buffer service provided by \e am_hal_scard_buffer_configure() and \e 500 //! am_hal_scard_interrupt_service() is already in use. Non-FIFO-related 501 //! interrupts do require the use of this function. 502 //! 503 //! The full list of interrupts is given by the following: 504 //! 505 //! @code 506 //! 507 //! AM_HAL_SCARD_INT_FHFEN 508 //! AM_HAL_SCARD_INT_FT2RENDEN 509 //! AM_HAL_SCARD_INT_PEEN 510 //! AM_HAL_SCARD_INT_OVREN 511 //! AM_HAL_SCARD_INT_FEREN 512 //! AM_HAL_SCARD_INT_TBERBFEN 513 //! AM_HAL_SCARD_INT_FNEEN 514 //! AM_HAL_SCARD_INT_SYNCENDEN 515 //! AM_HAL_SCARD_INT_PRLEN 516 //! AM_HAL_SCARD_INT_ECNTOVEREN 517 //! 518 //! @endcode 519 //! 520 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 521 // 522 //***************************************************************************** 523 extern uint32_t am_hal_scard_interrupt_enable(void *pHandle, uint32_t ui32Index, 524 uint32_t ui32IntMask); 525 526 //***************************************************************************** 527 // 528 //! @brief Disable interrupts. 529 //! 530 //! @param pHandle - the handle for the SCARD to operate on. 531 //! @param ui32Index - IER(0) or IER1 532 //! @param ui32IntMask - the bitmask of interrupts to disable. 533 //! 534 //! This function disables the SCARD interrupt(s) given by ui32IntMask. If 535 //! multiple interrupts need to be disabled, they can be OR'ed together. 536 //! 537 //! @note This function need not be called for SCARD FIFO interrupts if the SCARD 538 //! buffer service provided by \e am_hal_scard_buffer_configure() and \e 539 //! am_hal_scard_interrupt_service() is already in use. Non-FIFO-related 540 //! interrupts do require the use of this function. 541 //! 542 //! The full list of interrupts is given by the following: 543 //! 544 //! @code 545 //! 546 //! AM_HAL_SCARD_INT_FHFEN 547 //! AM_HAL_SCARD_INT_FT2RENDEN 548 //! AM_HAL_SCARD_INT_PEEN 549 //! AM_HAL_SCARD_INT_OVREN 550 //! AM_HAL_SCARD_INT_FEREN 551 //! AM_HAL_SCARD_INT_TBERBFEN 552 //! AM_HAL_SCARD_INT_FNEEN 553 //! AM_HAL_SCARD_INT_SYNCENDEN 554 //! AM_HAL_SCARD_INT_PRLEN 555 //! AM_HAL_SCARD_INT_ECNTOVEREN 556 //! 557 //! @endcode 558 //! 559 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 560 // 561 //***************************************************************************** 562 extern uint32_t am_hal_scard_interrupt_disable(void *pHandle, uint32_t ui32Index, 563 uint32_t ui32IntMask); 564 565 //***************************************************************************** 566 // 567 //! @brief Clear interrupt status. 568 //! 569 //! @param pHandle - the handle for the SCARD to operate on. 570 //! @param ui32Index - SR(0) or SR1 571 //! @param ui32IntMask - the bitmask of interrupts to clear. 572 //! 573 //! This function clears the SCARD interrupt(s) given by ui32IntMask. If 574 //! multiple interrupts need to be cleared, they can be OR'ed together. 575 //! 576 //! The full list of interrupts is given by the following: 577 //! 578 //! @code 579 //! 580 //! AM_HAL_SCARD_INT_FHFEN 581 //! AM_HAL_SCARD_INT_FT2RENDEN 582 //! AM_HAL_SCARD_INT_PEEN 583 //! AM_HAL_SCARD_INT_OVREN 584 //! AM_HAL_SCARD_INT_FEREN 585 //! AM_HAL_SCARD_INT_TBERBFEN 586 //! AM_HAL_SCARD_INT_FNEEN 587 //! AM_HAL_SCARD_INT_SYNCENDEN 588 //! AM_HAL_SCARD_INT_PRLEN 589 //! AM_HAL_SCARD_INT_ECNTOVEREN 590 //! 591 //! @endcode 592 //! 593 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 594 // 595 //***************************************************************************** 596 extern uint32_t am_hal_scard_interrupt_clear(void *pHandle, uint32_t ui32Index, 597 uint32_t ui32IntMask); 598 599 //***************************************************************************** 600 // 601 //! @brief Read interrupt status. 602 //! 603 //! @param pHandle - the handle for the SCARD to operate on. 604 //! @param ui32Index - SR(0) or SR1 605 //! @param pui32Status - the returned interrupt status (all bits OR'ed 606 //! together) 607 //! 608 //! This function reads the status the SCARD interrupt(s) if \e bEnabled is 609 //! true, it will only return the status of the enabled interrupts. Otherwise, 610 //! it will return the status of all interrupts, enabled or disabled. 611 //! 612 //! The full list of interrupts is given by the following: 613 //! 614 //! @code 615 //! 616 //! AM_HAL_SCARD_INT_FHFEN 617 //! AM_HAL_SCARD_INT_FT2RENDEN 618 //! AM_HAL_SCARD_INT_PEEN 619 //! AM_HAL_SCARD_INT_OVREN 620 //! AM_HAL_SCARD_INT_FEREN 621 //! AM_HAL_SCARD_INT_TBERBFEN 622 //! AM_HAL_SCARD_INT_FNEEN 623 //! AM_HAL_SCARD_INT_SYNCENDEN 624 //! AM_HAL_SCARD_INT_PRLEN 625 //! AM_HAL_SCARD_INT_ECNTOVEREN 626 //! 627 //! @endcode 628 //! 629 //! @return AM_HAL_STATUS_SUCCESS or applicable SCARD errors. 630 631 // 632 //***************************************************************************** 633 extern uint32_t am_hal_scard_interrupt_status_get(void *pHandle, uint32_t ui32Index, 634 uint32_t *pui32Status); 635 //***************************************************************************** 636 // 637 //! @brief SCARD control function 638 //! 639 //! @param pHandle - handle for the SCARD. 640 //! @param eReq - device specific special request code. 641 //! @param pArgs - pointer to the request specific arguments. 642 //! 643 //! This function allows advanced settings 644 //! 645 //! @return status - generic or interface specific status. 646 // 647 //***************************************************************************** 648 649 extern uint32_t am_hal_scard_control(void *pHandle, am_hal_scard_request_e eReq, void *pArgs); 650 651 typedef enum 652 { 653 AM_HAL_SCARD_STATUS_BUS_ERROR = AM_HAL_STATUS_MODULE_SPECIFIC_START, 654 AM_HAL_SCARD_STATUS_RX_QUEUE_FULL, 655 AM_HAL_SCARD_STATUS_PROTOCAL_NOT_SUPPORT, 656 } 657 am_hal_scard_errors_t; 658 659 #ifdef __cplusplus 660 } 661 #endif 662 663 #endif // AM_HAL_SCARD_H 664 //***************************************************************************** 665 // 666 // End Doxygen group. 667 //! @} 668 // 669 //***************************************************************************** 670