fsl_smartcard_emvsim.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_SMARTCARD_EMVSIM_H_
  9. #define _FSL_SMARTCARD_EMVSIM_H_
  10. #include "fsl_smartcard.h"
  11. /*!
  12. * @addtogroup smartcard_emvsim_driver
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. ******************************************************************************/
  18. /*! @brief EMV RX NACK interrupt generation threshold */
  19. #define SMARTCARD_EMV_RX_NACK_THRESHOLD (5u)
  20. /*! @brief EMV TX NACK interrupt generation threshold */
  21. #define SMARTCARD_EMV_TX_NACK_THRESHOLD (5u)
  22. /*! @brief Smart card Word Wait Timer adjustment value */
  23. #define SMARTCARD_WWT_ADJUSTMENT (160u)
  24. /*! @brief Smart card Character Wait Timer adjustment value */
  25. #define SMARTCARD_CWT_ADJUSTMENT (3u)
  26. /*! @brief General Purpose Counter clock selections */
  27. typedef enum _emvsim_gpc_clock_select
  28. {
  29. kEMVSIM_GPCClockDisable = 0u, /*!< Disabled */
  30. kEMVSIM_GPCCardClock = 1u, /*!< Card clock */
  31. kEMVSIM_GPCRxClock = 2u, /*!< Receive clock */
  32. kEMVSIM_GPCTxClock = 3u, /*!< Transmit ETU clock */
  33. } emvsim_gpc_clock_select_t;
  34. /*! @brief EMVSIM card presence detection edge control */
  35. typedef enum _presence_detect_edge
  36. {
  37. kEMVSIM_DetectOnFallingEdge = 0u, /*!< Presence detected on the falling edge */
  38. kEMVSIM_DetectOnRisingEdge = 1u, /*!< Presence detected on the rising edge */
  39. } emvsim_presence_detect_edge_t;
  40. /*! @brief EMVSIM card presence detection status */
  41. typedef enum _presence_detect_status
  42. {
  43. kEMVSIM_DetectPinIsLow = 0u, /*!< Presence detected pin is logic low */
  44. kEMVSIM_DetectPinIsHigh = 1u, /*!< Presence detected pin is logic high */
  45. } emvsim_presence_detect_status_t;
  46. /*******************************************************************************
  47. * API
  48. ******************************************************************************/
  49. #if defined(__cplusplus)
  50. extern "C" {
  51. #endif
  52. /*!
  53. * @name Smart card EMVSIM Driver
  54. * @{
  55. */
  56. /*!
  57. * @brief Fills in the smartcard_card_params structure with default values according to the EMV 4.3 specification.
  58. *
  59. * @param cardParams The configuration structure of type smartcard_interface_config_t.
  60. * Function fill in members:
  61. * Fi = 372;
  62. * Di = 1;
  63. * currentD = 1;
  64. * WI = 0x0A;
  65. * GTN = 0x00;
  66. * with default values.
  67. */
  68. void SMARTCARD_EMVSIM_GetDefaultConfig(smartcard_card_params_t *cardParams);
  69. /*!
  70. * @brief Initializes an EMVSIM peripheral for the Smart card/ISO-7816 operation.
  71. *
  72. * This function un-gates the EMVSIM clock, initializes the module to EMV default settings,
  73. * configures the IRQ, enables the module-level interrupt to the core and, initializes the driver context.
  74. *
  75. * @param base The EMVSIM peripheral base address.
  76. * @param context A pointer to the smart card driver context structure.
  77. * @param srcClock_Hz Smart card clock generation module source clock.
  78. *
  79. * @return An error code or kStatus_SMARTCARD_Success.
  80. */
  81. status_t SMARTCARD_EMVSIM_Init(EMVSIM_Type *base, smartcard_context_t *context, uint32_t srcClock_Hz);
  82. /*!
  83. * @brief This function disables the EMVSIM interrupts, disables the transmitter and receiver,
  84. * flushes the FIFOs, and gates EMVSIM clock in SIM.
  85. *
  86. * @param base The EMVSIM module base address.
  87. */
  88. void SMARTCARD_EMVSIM_Deinit(EMVSIM_Type *base);
  89. /*!
  90. * @brief Returns whether the previous EMVSIM transfer has finished.
  91. *
  92. * When performing an async transfer, call this function to ascertain the context of the
  93. * current transfer: in progress (or busy) or complete (success). If the
  94. * transfer is still in progress, the user can obtain the number of words that have not been
  95. * transferred.
  96. *
  97. * @param base The EMVSIM module base address.
  98. * @param context A pointer to a smart card driver context structure.
  99. *
  100. * @return The number of bytes not transferred.
  101. */
  102. int32_t SMARTCARD_EMVSIM_GetTransferRemainingBytes(EMVSIM_Type *base, smartcard_context_t *context);
  103. /*!
  104. * @brief Terminates an asynchronous EMVSIM transfer early.
  105. *
  106. * During an async EMVSIM transfer, the user can terminate the transfer early
  107. * if the transfer is still in progress.
  108. *
  109. * @param base The EMVSIM peripheral address.
  110. * @param context A pointer to a smart card driver context structure.
  111. * @retval kStatus_SMARTCARD_Success The transmit abort was successful.
  112. * @retval kStatus_SMARTCARD_NoTransmitInProgress No transmission is currently in progress.
  113. */
  114. status_t SMARTCARD_EMVSIM_AbortTransfer(EMVSIM_Type *base, smartcard_context_t *context);
  115. /*!
  116. * @brief Transfer data using interrupts.
  117. *
  118. * A non-blocking (also known as asynchronous) function means that the function returns
  119. * immediately after initiating the transfer function. The application has to get the
  120. * transfer status to see when the transfer is complete. In other words, after calling the non-blocking
  121. * (asynchronous) transfer function, the application must get the transfer status to check if the transmit
  122. * is completed or not.
  123. *
  124. * @param base The EMVSIM peripheral base address.
  125. * @param context A pointer to a smart card driver context structure.
  126. * @param xfer A pointer to the smart card transfer structure where the linked buffers and sizes are stored.
  127. *
  128. * @return An error code or kStatus_SMARTCARD_Success.
  129. */
  130. status_t SMARTCARD_EMVSIM_TransferNonBlocking(EMVSIM_Type *base, smartcard_context_t *context, smartcard_xfer_t *xfer);
  131. /*!
  132. * @brief Controls the EMVSIM module per different user request.
  133. *
  134. * @param base The EMVSIM peripheral base address.
  135. * @param context A pointer to a smart card driver context structure.
  136. * @param control Control type.
  137. * @param param Integer value of specific to control command.
  138. *
  139. * return kStatus_SMARTCARD_Success in success.
  140. * return kStatus_SMARTCARD_OtherError in case of error.
  141. */
  142. status_t SMARTCARD_EMVSIM_Control(EMVSIM_Type *base,
  143. smartcard_context_t *context,
  144. smartcard_control_t control,
  145. uint32_t param);
  146. /*!
  147. * @brief Handles EMVSIM module interrupts.
  148. *
  149. * @param base The EMVSIM peripheral base address.
  150. * @param context A pointer to a smart card driver context structure.
  151. */
  152. void SMARTCARD_EMVSIM_IRQHandler(EMVSIM_Type *base, smartcard_context_t *context);
  153. /*@}*/
  154. #if defined(__cplusplus)
  155. }
  156. #endif
  157. /*! @}*/
  158. #endif /* _FSL_SMARTCARD_EMVSIM_H_*/