fsl_smartcard_emvsim.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_SMARTCARD_EMVSIM_H_
  35. #define _FSL_SMARTCARD_EMVSIM_H_
  36. #include "fsl_smartcard.h"
  37. /*!
  38. * @addtogroup smartcard_emvsim_driver
  39. * @{
  40. */
  41. /*******************************************************************************
  42. * Definitions
  43. ******************************************************************************/
  44. /*! @brief EMV RX NACK interrupt generation threshold */
  45. #define SMARTCARD_EMV_RX_NACK_THRESHOLD (5u)
  46. /*! @brief EMV TX NACK interrupt generation threshold */
  47. #define SMARTCARD_EMV_TX_NACK_THRESHOLD (5u)
  48. /*! @brief Smart card Word Wait Timer adjustment value */
  49. #define SMARTCARD_WWT_ADJUSTMENT (160u)
  50. /*! @brief Smart card Character Wait Timer adjustment value */
  51. #define SMARTCARD_CWT_ADJUSTMENT (3u)
  52. /*! @brief General Purpose Counter clock selections */
  53. typedef enum _emvsim_gpc_clock_select
  54. {
  55. kEMVSIM_GPCClockDisable = 0u, /*!< Disabled */
  56. kEMVSIM_GPCCardClock = 1u, /*!< Card clock */
  57. kEMVSIM_GPCRxClock = 2u, /*!< Receive clock */
  58. kEMVSIM_GPCTxClock = 3u, /*!< Transmit ETU clock */
  59. } emvsim_gpc_clock_select_t;
  60. /*! @brief EMVSIM card presence detection edge control */
  61. typedef enum _presence_detect_edge
  62. {
  63. kEMVSIM_DetectOnFallingEdge = 0u, /*!< Presence detected on the falling edge */
  64. kEMVSIM_DetectOnRisingEdge = 1u, /*!< Presence detected on the rising edge */
  65. } emvsim_presence_detect_edge_t;
  66. /*! @brief EMVSIM card presence detection status */
  67. typedef enum _presence_detect_status
  68. {
  69. kEMVSIM_DetectPinIsLow = 0u, /*!< Presence detected pin is logic low */
  70. kEMVSIM_DetectPinIsHigh = 1u, /*!< Presence detected pin is logic high */
  71. } emvsim_presence_detect_status_t;
  72. /*******************************************************************************
  73. * API
  74. ******************************************************************************/
  75. #if defined(__cplusplus)
  76. extern "C" {
  77. #endif
  78. /*!
  79. * @name Smart card EMVSIM Driver
  80. * @{
  81. */
  82. /*!
  83. * @brief Fills in the smartcard_card_params structure with default values according to the EMV 4.3 specification.
  84. *
  85. * @param cardParams The configuration structure of type smartcard_interface_config_t.
  86. * Function fill in members:
  87. * Fi = 372;
  88. * Di = 1;
  89. * currentD = 1;
  90. * WI = 0x0A;
  91. * GTN = 0x00;
  92. * with default values.
  93. */
  94. void SMARTCARD_EMVSIM_GetDefaultConfig(smartcard_card_params_t *cardParams);
  95. /*!
  96. * @brief Initializes an EMVSIM peripheral for the Smart card/ISO-7816 operation.
  97. *
  98. * This function un-gates the EMVSIM clock, initializes the module to EMV default settings,
  99. * configures the IRQ, enables the module-level interrupt to the core and, initializes the driver context.
  100. *
  101. * @param base The EMVSIM peripheral base address.
  102. * @param context A pointer to the smart card driver context structure.
  103. * @param srcClock_Hz Smart card clock generation module source clock.
  104. *
  105. * @return An error code or kStatus_SMARTCARD_Success.
  106. */
  107. status_t SMARTCARD_EMVSIM_Init(EMVSIM_Type *base, smartcard_context_t *context, uint32_t srcClock_Hz);
  108. /*!
  109. * @brief This function disables the EMVSIM interrupts, disables the transmitter and receiver,
  110. * flushes the FIFOs, and gates EMVSIM clock in SIM.
  111. *
  112. * @param base The EMVSIM module base address.
  113. */
  114. void SMARTCARD_EMVSIM_Deinit(EMVSIM_Type *base);
  115. /*!
  116. * @brief Returns whether the previous EMVSIM transfer has finished.
  117. *
  118. * When performing an async transfer, call this function to ascertain the context of the
  119. * current transfer: in progress (or busy) or complete (success). If the
  120. * transfer is still in progress, the user can obtain the number of words that have not been
  121. * transferred.
  122. *
  123. * @param base The EMVSIM module base address.
  124. * @param context A pointer to a smart card driver context structure.
  125. *
  126. * @return The number of bytes not transferred.
  127. */
  128. int32_t SMARTCARD_EMVSIM_GetTransferRemainingBytes(EMVSIM_Type *base, smartcard_context_t *context);
  129. /*!
  130. * @brief Terminates an asynchronous EMVSIM transfer early.
  131. *
  132. * During an async EMVSIM transfer, the user can terminate the transfer early
  133. * if the transfer is still in progress.
  134. *
  135. * @param base The EMVSIM peripheral address.
  136. * @param context A pointer to a smart card driver context structure.
  137. * @retval kStatus_SMARTCARD_Success The transmit abort was successful.
  138. * @retval kStatus_SMARTCARD_NoTransmitInProgress No transmission is currently in progress.
  139. */
  140. status_t SMARTCARD_EMVSIM_AbortTransfer(EMVSIM_Type *base, smartcard_context_t *context);
  141. /*!
  142. * @brief Transfer data using interrupts.
  143. *
  144. * A non-blocking (also known as asynchronous) function means that the function returns
  145. * immediately after initiating the transfer function. The application has to get the
  146. * transfer status to see when the transfer is complete. In other words, after calling the non-blocking
  147. * (asynchronous) transfer function, the application must get the transfer status to check if the transmit
  148. * is completed or not.
  149. *
  150. * @param base The EMVSIM peripheral base address.
  151. * @param context A pointer to a smart card driver context structure.
  152. * @param xfer A pointer to the smart card transfer structure where the linked buffers and sizes are stored.
  153. *
  154. * @return An error code or kStatus_SMARTCARD_Success.
  155. */
  156. status_t SMARTCARD_EMVSIM_TransferNonBlocking(EMVSIM_Type *base, smartcard_context_t *context, smartcard_xfer_t *xfer);
  157. /*!
  158. * @brief Controls the EMVSIM module per different user request.
  159. *
  160. * @param base The EMVSIM peripheral base address.
  161. * @param context A pointer to a smart card driver context structure.
  162. * @param control Control type.
  163. * @param param Integer value of specific to control command.
  164. *
  165. * return kStatus_SMARTCARD_Success in success.
  166. * return kStatus_SMARTCARD_OtherError in case of error.
  167. */
  168. status_t SMARTCARD_EMVSIM_Control(EMVSIM_Type *base,
  169. smartcard_context_t *context,
  170. smartcard_control_t control,
  171. uint32_t param);
  172. /*!
  173. * @brief Handles EMVSIM module interrupts.
  174. *
  175. * @param base The EMVSIM peripheral base address.
  176. * @param context A pointer to a smart card driver context structure.
  177. */
  178. void SMARTCARD_EMVSIM_IRQHandler(EMVSIM_Type *base, smartcard_context_t *context);
  179. /*@}*/
  180. #if defined(__cplusplus)
  181. }
  182. #endif
  183. /*! @}*/
  184. #endif /* _FSL_SMARTCARD_EMVSIM_H_*/