MCUXpresso SDK API Reference Manual  Rev 2.15.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Smart Card

Overview

The MCUXpresso SDK provides a peripheral drivers for the UART-ISO7816 and EMVSIM/USIM modules of MCUXpresso SDK devices.

Smart Card driver provides the necessary functions to access and control integrated circuit cards. The driver controls communication modules (UART/EMVSIM/USIM) and handles special ICC sequences, such as the activation/deactivation (using EMVSIM/USIM IP or external interface chip). The Smart Card driver consists of two IPs (SmartCard_Uart and SmartCard_EmvSim drivers) and three PHY drivers (smartcard_phy_emvsim, smartcard_phy_tda8035, and smartcard_phy_gpio drivers). These drivers can be combined, which means that the Smart Card driver wraps one IP (transmission) and one PHY (interface) driver.

The driver provides asynchronous functions to communicate with the Integrated Circuit Card (ICC). The driver contains RTOS adaptation layers which use semaphores as synchronization objects of synchronous transfers. The RTOS driver support also provides protection for multithreading.

SmartCard Driver Initialization

The Smart Card Driver is initialized by calling the SMARTCARD_Init() and SMARTCARD_PHY_Init() functions. The Smart Card Driver initialization configuration structure requires these settings:

The driver also supports user callbacks for assertion/de-assertion Smart Card events and transfer finish event. This feature is useful to detect the card presence or for handling transfer events, for example, in RTOS. The user should initialize the Smart Card driver, which consist of IP and PHY drivers.

SmartCard Call diagram

Because the call diagram is complex, the detailed use of the Smart Card driver is not described in this section. For details about using the Smart Card driver, see the Smart Card driver example which describes a simple use case.

PHY driver

The Smart Card interface driver is initialized by calling the function SMARTCARD_PHY_Init(). During the initialization phase, Smart Card clock is configured and all hardware pins for IC handling are configured.

Modules

 Smart Card EMVSIM Driver
 
 Smart Card PHY Driver
 
 Smart Card PHY EMVSIM Driver
 
 Smart Card PHY GPIO Driver
 
 Smart Card PHY TDA8035 Driver
 
 Smart Card PHY USIM W
 
 Smart Card UART Driver
 
 Smart Card USIM Driver
 

Data Structures

struct  _smartcard_card_params
 Defines card-specific parameters for Smart card driver. More...
 
struct  _smartcard_timers_state
 Smart card defines the state of the EMV timers in the Smart card driver. More...
 
struct  _smartcard_interface_config
 Defines user specified configuration of Smart card interface. More...
 
struct  _smartcard_xfer
 Defines user transfer structure used to initialize transfer. More...
 
struct  _smartcard_context
 Runtime state of the Smart card driver. More...
 

Macros

#define SMARTCARD_INIT_DELAY_CLOCK_CYCLES   (42000u)
 Smart card global define which specify number of clock cycles until initial 'TS' character has to be received.
 
#define SMARTCARD_EMV_ATR_DURATION_ETU   (20150u)
 Smart card global define which specify number of clock cycles during which ATR string has to be received.
 
#define SMARTCARD_TS_DIRECT_CONVENTION   (0x3Bu)
 Smart card specification initial TS character definition of direct convention.
 
#define SMARTCARD_TS_INVERSE_CONVENTION   (0x3Fu)
 Smart card specification initial TS character definition of inverse convention.
 

Typedefs

typedef enum _smartcard_control smartcard_control_t
 Control codes for the Smart card protocol timers and misc. More...
 
typedef enum
_smartcard_card_voltage_class 
smartcard_card_voltage_class_t
 Defines Smart card interface voltage class values.
 
typedef enum
_smartcard_transfer_state 
smartcard_transfer_state_t
 Defines Smart card I/O transfer states.
 
typedef enum _smartcard_reset_type smartcard_reset_type_t
 Defines Smart card reset types.
 
typedef enum
_smartcard_transport_type 
smartcard_transport_type_t
 Defines Smart card transport protocol types.
 
typedef enum _smartcard_parity_type smartcard_parity_type_t
 Defines Smart card data parity types.
 
typedef enum
_smartcard_card_convention 
smartcard_card_convention_t
 Defines data Convention format.
 
typedef enum
_smartcard_interface_control 
smartcard_interface_control_t
 Defines Smart card interface IC control types.
 
typedef enum _smartcard_direction smartcard_direction_t
 Defines transfer direction. More...
 
typedef void(* smartcard_interface_callback_t )(void *smartcardContext, void *param)
 Smart card interface interrupt callback function type.
 
typedef void(* smartcard_transfer_callback_t )(void *smartcardContext, void *param)
 Smart card transfer interrupt callback function type.
 
typedef void(* smartcard_time_delay_t )(uint32_t us)
 Time Delay function used to passive waiting using RTOS [us].
 
typedef struct
_smartcard_card_params 
smartcard_card_params_t
 Defines card-specific parameters for Smart card driver.
 
typedef struct
_smartcard_timers_state 
smartcard_timers_state_t
 Smart card defines the state of the EMV timers in the Smart card driver.
 
typedef struct
_smartcard_interface_config 
smartcard_interface_config_t
 Defines user specified configuration of Smart card interface.
 
typedef struct _smartcard_xfer smartcard_xfer_t
 Defines user transfer structure used to initialize transfer.
 
typedef struct _smartcard_context smartcard_context_t
 Runtime state of the Smart card driver.
 

Enumerations

enum  {
  kStatus_SMARTCARD_Success = MAKE_STATUS(kStatusGroup_SMARTCARD, 0),
  kStatus_SMARTCARD_TxBusy = MAKE_STATUS(kStatusGroup_SMARTCARD, 1),
  kStatus_SMARTCARD_RxBusy = MAKE_STATUS(kStatusGroup_SMARTCARD, 2),
  kStatus_SMARTCARD_NoTransferInProgress = MAKE_STATUS(kStatusGroup_SMARTCARD, 3),
  kStatus_SMARTCARD_Timeout = MAKE_STATUS(kStatusGroup_SMARTCARD, 4),
  kStatus_SMARTCARD_Initialized,
  kStatus_SMARTCARD_PhyInitialized,
  kStatus_SMARTCARD_CardNotActivated = MAKE_STATUS(kStatusGroup_SMARTCARD, 7),
  kStatus_SMARTCARD_InvalidInput,
  kStatus_SMARTCARD_OtherError = MAKE_STATUS(kStatusGroup_SMARTCARD, 9)
}
 Smart card Error codes. More...
 
enum  _smartcard_control
 Control codes for the Smart card protocol timers and misc. More...
 
enum  _smartcard_card_voltage_class
 Defines Smart card interface voltage class values.
 
enum  _smartcard_transfer_state
 Defines Smart card I/O transfer states.
 
enum  _smartcard_reset_type
 Defines Smart card reset types.
 
enum  _smartcard_transport_type
 Defines Smart card transport protocol types.
 
enum  _smartcard_parity_type
 Defines Smart card data parity types.
 
enum  _smartcard_card_convention
 Defines data Convention format.
 
enum  _smartcard_interface_control
 Defines Smart card interface IC control types.
 
enum  _smartcard_direction
 Defines transfer direction. More...
 

Driver version

#define FSL_SMARTCARD_DRIVER_VERSION   (MAKE_VERSION(2, 3, 0))
 Smart card driver version 2.3.0.
 

Data Structure Documentation

struct _smartcard_card_params

Data Fields

uint16_t Fi
 4 bits Fi - clock rate conversion integer
 
uint8_t fMax
 Maximum Smart card frequency in MHz.
 
uint8_t WI
 8 bits WI - work wait time integer
 
uint8_t Di
 4 bits DI - baud rate divisor
 
uint8_t BWI
 4 bits BWI - block wait time integer
 
uint8_t CWI
 4 bits CWI - character wait time integer
 
uint8_t BGI
 4 bits BGI - block guard time integer
 
uint8_t GTN
 8 bits GTN - extended guard time integer
 
uint8_t IFSC
 Indicates IFSC value of the card.
 
uint8_t modeNegotiable
 Indicates if the card acts in negotiable or a specific mode. More...
 
uint8_t currentD
 4 bits DI - current baud rate divisor
 
uint8_t status
 Indicates smart card status.
 
bool t0Indicated
 Indicates ff T=0 indicated in TD1 byte.
 
bool t1Indicated
 Indicates if T=1 indicated in TD2 byte.
 
bool atrComplete
 Indicates whether the ATR received from the card was complete or not.
 
bool atrValid
 Indicates whether the ATR received from the card was valid or not.
 
bool present
 Indicates if a smart card is present.
 
bool active
 Indicates if the smart card is activated.
 
bool faulty
 Indicates whether smart card/interface is faulty.
 
smartcard_card_convention_t convention
 Card convention, kSMARTCARD_DirectConvention for direct convention, kSMARTCARD_InverseConvention for inverse convention.
 

Field Documentation

uint8_t _smartcard_card_params::modeNegotiable
struct _smartcard_timers_state

Data Fields

volatile bool adtExpired
 Indicates whether ADT timer expired.
 
volatile bool wwtExpired
 Indicates whether WWT timer expired.
 
volatile bool cwtExpired
 Indicates whether CWT timer expired.
 
volatile bool bwtExpired
 Indicates whether BWT timer expired.
 
volatile bool initCharTimerExpired
 
                         Indicates whether reception timer

for initialization character (TS) after the RST has expired

 
struct _smartcard_interface_config

Data Fields

uint32_t smartCardClock
 Smart card interface clock [Hz].
 
uint32_t clockToResetDelay
 Indicates clock to RST apply delay [smart card clock cycles].
 
uint8_t clockModule
 Smart card clock module number.
 
uint8_t clockModuleChannel
 Smart card clock module channel number.
 
uint8_t clockModuleSourceClock
 Smart card clock module source clock [e.g., BusClk].
 
smartcard_card_voltage_class_t vcc
 Smart card voltage class.
 
uint8_t controlPort
 Smart card PHY control port instance.
 
uint8_t controlPin
 Smart card PHY control pin instance.
 
uint8_t irqPort
 Smart card PHY Interrupt port instance.
 
uint8_t irqPin
 Smart card PHY Interrupt pin instance.
 
uint8_t resetPort
 Smart card reset port instance.
 
uint8_t resetPin
 Smart card reset pin instance.
 
uint8_t vsel0Port
 Smart card PHY Vsel0 control port instance.
 
uint8_t vsel0Pin
 Smart card PHY Vsel0 control pin instance.
 
uint8_t vsel1Port
 Smart card PHY Vsel1 control port instance.
 
uint8_t vsel1Pin
 Smart card PHY Vsel1 control pin instance.
 
uint8_t dataPort
 Smart card PHY data port instance.
 
uint8_t dataPin
 Smart card PHY data pin instance.
 
uint8_t dataPinMux
 Smart card PHY data pin mux option.
 
uint8_t tsTimerId
 Numerical identifier of the External HW timer for Initial character detection.
 
struct _smartcard_xfer

Data Fields

smartcard_direction_t direction
 Direction of communication. More...
 
uint8_t * buff
 The buffer of data. More...
 
size_t size
 The number of transferred units. More...
 

Field Documentation

smartcard_direction_t _smartcard_xfer::direction

(RX/TX)

uint8_t* _smartcard_xfer::buff
size_t _smartcard_xfer::size
struct _smartcard_context

Data Fields

void * base
 Smart card module base address.
 
smartcard_direction_t direction
 Direction of communication. More...
 
uint8_t * xBuff
 The buffer of data being transferred. More...
 
volatile size_t xSize
 The number of bytes to be transferred. More...
 
volatile bool xIsBusy
 True if there is an active transfer. More...
 
uint8_t txFifoEntryCount
 Number of data word entries in transmit FIFO. More...
 
uint8_t rxFifoThreshold
 The max value of the receiver FIFO threshold. More...
 
smartcard_interface_callback_t interfaceCallback
 Callback to invoke after interface IC raised interrupt. More...
 
smartcard_transfer_callback_t transferCallback
 Callback to invoke after transfer event occur. More...
 
void * interfaceCallbackParam
 Interface callback parameter pointer. More...
 
void * transferCallbackParam
 Transfer callback parameter pointer. More...
 
smartcard_time_delay_t timeDelay
 Function which handles time delay defined by user or RTOS. More...
 
smartcard_reset_type_t resetType
 Indicates whether a Cold reset or Warm reset was requested. More...
 
smartcard_transport_type_t tType
 Indicates current transfer protocol (T0 or T1)
 
volatile smartcard_transfer_state_t transferState
 Indicates the current transfer state.
 
smartcard_timers_state_t timersState
 Indicates the state of different protocol timers used in driver.
 
smartcard_card_params_t cardParams
 Smart card parameters(ATR and current) and interface slots states(ATR and current)
 
uint8_t IFSD
 Indicates the terminal IFSD.
 
smartcard_parity_type_t parity
 Indicates current parity even/odd.
 
volatile bool rxtCrossed
 Indicates whether RXT thresholds has been crossed.
 
volatile bool txtCrossed
 Indicates whether TXT thresholds has been crossed.
 
volatile bool wtxRequested
 Indicates whether WTX has been requested or not.
 
volatile bool parityError
 Indicates whether a parity error has been detected.
 
uint8_t statusBytes [2]
 Used to store Status bytes SW1, SW2 of the last executed card command response.
 
smartcard_interface_config_t interfaceConfig
 Smart card interface configuration structure.
 
bool abortTransfer
 Used to abort transfer. More...
 

Field Documentation

smartcard_direction_t _smartcard_context::direction

(RX/TX)

uint8_t* _smartcard_context::xBuff
volatile size_t _smartcard_context::xSize
volatile bool _smartcard_context::xIsBusy
uint8_t _smartcard_context::txFifoEntryCount
uint8_t _smartcard_context::rxFifoThreshold
smartcard_interface_callback_t _smartcard_context::interfaceCallback
smartcard_transfer_callback_t _smartcard_context::transferCallback
void* _smartcard_context::interfaceCallbackParam
void* _smartcard_context::transferCallbackParam
smartcard_time_delay_t _smartcard_context::timeDelay
smartcard_reset_type_t _smartcard_context::resetType
bool _smartcard_context::abortTransfer

Typedef Documentation

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_SMARTCARD_Success 

Transfer ends successfully.

kStatus_SMARTCARD_TxBusy 

Transmit in progress.

kStatus_SMARTCARD_RxBusy 

Receiving in progress.

kStatus_SMARTCARD_NoTransferInProgress 

No transfer in progress.

kStatus_SMARTCARD_Timeout 

Transfer ends with time-out.

kStatus_SMARTCARD_Initialized 

Smart card driver is already initialized.

kStatus_SMARTCARD_PhyInitialized 

Smart card PHY drive is already initialized.

kStatus_SMARTCARD_CardNotActivated 

Smart card is not activated.

kStatus_SMARTCARD_InvalidInput 

Function called with invalid input arguments.

kStatus_SMARTCARD_OtherError 

Some other error occur.