RTEMS 6.1-rc1
fsl_smartcard.h
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
9#ifndef _FSL_SMARTCARD_H_
10#define _FSL_SMARTCARD_H_
11
12#include "fsl_common.h"
13
19/*******************************************************************************
20 * Definitions
21 ******************************************************************************/
22
27#define FSL_SMARTCARD_DRIVER_VERSION (MAKE_VERSION(2, 2, 2))
32#define SMARTCARD_INIT_DELAY_CLOCK_CYCLES (42000u)
33
35#define SMARTCARD_EMV_ATR_DURATION_ETU (20150u)
36
38#define SMARTCARD_TS_DIRECT_CONVENTION (0x3Bu)
39
41#define SMARTCARD_TS_INVERSE_CONVENTION (0x3Fu)
42
44enum
45{
59};
60
63{
64 kSMARTCARD_EnableADT = 0x0u,
65 kSMARTCARD_DisableADT = 0x1u,
66 kSMARTCARD_EnableGTV = 0x2u,
67 kSMARTCARD_DisableGTV = 0x3u,
68 kSMARTCARD_ResetWWT = 0x4u,
69 kSMARTCARD_EnableWWT = 0x5u,
70 kSMARTCARD_DisableWWT = 0x6u,
71 kSMARTCARD_ResetCWT = 0x7u,
72 kSMARTCARD_EnableCWT = 0x8u,
73 kSMARTCARD_DisableCWT = 0x9u,
74 kSMARTCARD_ResetBWT = 0xAu,
75 kSMARTCARD_EnableBWT = 0xBu,
76 kSMARTCARD_DisableBWT = 0xCu,
77 kSMARTCARD_EnableInitDetect = 0xDu,
78 kSMARTCARD_EnableAnack = 0xEu,
79 kSMARTCARD_DisableAnack = 0xFu,
80 kSMARTCARD_ConfigureBaudrate = 0x10u,
81 kSMARTCARD_SetupATRMode = 0x11u,
82 kSMARTCARD_SetupT0Mode = 0x12u,
83 kSMARTCARD_SetupT1Mode = 0x13u,
84 kSMARTCARD_EnableReceiverMode = 0x14u,
85 kSMARTCARD_DisableReceiverMode = 0x15u,
86 kSMARTCARD_EnableTransmitterMode = 0x16u,
87 kSMARTCARD_DisableTransmitterMode = 0x17u,
88 kSMARTCARD_ResetWaitTimeMultiplier = 0x18u,
90
93{
94 kSMARTCARD_VoltageClassUnknown = 0x0u,
95 kSMARTCARD_VoltageClassA5_0V = 0x1u,
96 kSMARTCARD_VoltageClassB3_3V = 0x2u,
97 kSMARTCARD_VoltageClassC1_8V = 0x3u
99
102{
103 kSMARTCARD_IdleState = 0x0u,
104 kSMARTCARD_WaitingForTSState = 0x1u,
105 kSMARTCARD_InvalidTSDetecetedState = 0x2u,
106 kSMARTCARD_ReceivingState = 0x3u,
107 kSMARTCARD_TransmittingState = 0x4u,
109
112{
113 kSMARTCARD_ColdReset = 0x0u,
114 kSMARTCARD_WarmReset = 0x1u,
115 kSMARTCARD_NoColdReset = 0x2u,
116 kSMARTCARD_NoWarmReset = 0x3u,
118
121{
122 kSMARTCARD_T0Transport = 0x0u,
123 kSMARTCARD_T1Transport = 0x1u
125
128{
129 kSMARTCARD_EvenParity = 0x0u,
130 kSMARTCARD_OddParity = 0x1u
132
135{
136 kSMARTCARD_DirectConvention = 0x0u,
137 kSMARTCARD_InverseConvention = 0x1u
139
142{
143 kSMARTCARD_InterfaceSetVcc = 0x00u,
144 kSMARTCARD_InterfaceSetClockToResetDelay = 0x01u,
145 kSMARTCARD_InterfaceReadStatus = 0x02u
147
150{
151 kSMARTCARD_Receive = 0u,
152 kSMARTCARD_Transmit = 1u
154
156typedef void (*smartcard_interface_callback_t)(void *smartcardContext, void *param);
158typedef void (*smartcard_transfer_callback_t)(void *smartcardContext, void *param);
159
161typedef void (*smartcard_time_delay_t)(uint32_t us);
162
165{
166 /* ISO7816/EMV4.3 specification variables */
167 uint16_t Fi;
168 uint8_t fMax;
169 uint8_t WI;
170 uint8_t Di;
171 uint8_t BWI;
172 uint8_t CWI;
173 uint8_t BGI;
174 uint8_t GTN;
175 uint8_t IFSC;
177 uint8_t currentD;
178 /* Driver-specific variables */
179 uint8_t status;
183 bool atrValid;
184 bool present;
185 bool active;
186 bool faulty;
190
193{
194 volatile bool adtExpired;
195 volatile bool wwtExpired;
196 volatile bool cwtExpired;
197 volatile bool bwtExpired;
198 volatile bool initCharTimerExpired;
201
204{
205 uint32_t smartCardClock;
207 uint8_t clockModule;
211 uint8_t controlPort;
212 uint8_t controlPin;
213 uint8_t irqPort;
214 uint8_t irqPin;
215 uint8_t resetPort;
216 uint8_t resetPin;
217 uint8_t vsel0Port;
218 uint8_t vsel0Pin;
219 uint8_t vsel1Port;
220 uint8_t vsel1Pin;
221 uint8_t dataPort;
222 uint8_t dataPin;
223 uint8_t dataPinMux;
224 uint8_t tsTimerId;
226
228typedef struct _smartcard_xfer
229{
231 uint8_t *buff;
232 size_t size;
234
238typedef struct _smartcard_context
239{
240 /* Xfer part */
241 void *base;
243 uint8_t *xBuff;
244 volatile size_t xSize;
245 volatile bool xIsBusy;
248 /* Smart card Interface part */
256 /* Smart card State part */
261 uint8_t IFSD;
263 volatile bool rxtCrossed;
264 volatile bool txtCrossed;
265 volatile bool wtxRequested;
266 volatile bool parityError;
267 uint8_t statusBytes[2];
268 /* Configuration part */
272
274#endif /* _FSL_SMARTCARD_H_*/
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:47
@ kStatusGroup_SMARTCARD
Definition: fsl_common.h:119
volatile bool initCharTimerExpired
Definition: fsl_smartcard.h:198
volatile bool wtxRequested
Definition: fsl_smartcard.h:265
struct _smartcard_timers_state smartcard_timers_state_t
Smart card defines the state of the EMV timers in the Smart card driver.
uint8_t irqPin
Definition: fsl_smartcard.h:214
smartcard_direction_t direction
Definition: fsl_smartcard.h:230
void * interfaceCallbackParam
Definition: fsl_smartcard.h:251
bool faulty
Definition: fsl_smartcard.h:186
void(* smartcard_transfer_callback_t)(void *smartcardContext, void *param)
Smart card transfer interrupt callback function type.
Definition: fsl_smartcard.h:158
smartcard_card_convention_t convention
Definition: fsl_smartcard.h:187
smartcard_interface_callback_t interfaceCallback
Definition: fsl_smartcard.h:249
size_t size
Definition: fsl_smartcard.h:232
uint8_t vsel0Port
Definition: fsl_smartcard.h:217
smartcard_card_voltage_class_t vcc
Definition: fsl_smartcard.h:210
uint8_t dataPort
Definition: fsl_smartcard.h:221
_smartcard_interface_control
Defines Smart card interface IC control types.
Definition: fsl_smartcard.h:142
_smartcard_transfer_state
Defines Smart card I/O transfer states.
Definition: fsl_smartcard.h:102
uint8_t resetPin
Definition: fsl_smartcard.h:216
uint8_t resetPort
Definition: fsl_smartcard.h:215
uint8_t modeNegotiable
Definition: fsl_smartcard.h:176
uint8_t txFifoEntryCount
Definition: fsl_smartcard.h:246
_smartcard_direction
Defines transfer direction.
Definition: fsl_smartcard.h:150
enum _smartcard_transfer_state smartcard_transfer_state_t
Defines Smart card I/O transfer states.
void * transferCallbackParam
Definition: fsl_smartcard.h:252
uint8_t dataPin
Definition: fsl_smartcard.h:222
uint8_t vsel0Pin
Definition: fsl_smartcard.h:218
void(* smartcard_time_delay_t)(uint32_t us)
Time Delay function used to passive waiting using RTOS [us].
Definition: fsl_smartcard.h:161
enum _smartcard_card_convention smartcard_card_convention_t
Defines data Convention format.
uint8_t dataPinMux
Definition: fsl_smartcard.h:223
_smartcard_reset_type
Defines Smart card reset types.
Definition: fsl_smartcard.h:112
smartcard_time_delay_t timeDelay
Definition: fsl_smartcard.h:253
_smartcard_parity_type
Defines Smart card data parity types.
Definition: fsl_smartcard.h:128
uint8_t WI
Definition: fsl_smartcard.h:169
bool t1Indicated
Definition: fsl_smartcard.h:181
smartcard_parity_type_t parity
Definition: fsl_smartcard.h:262
uint8_t rxFifoThreshold
Definition: fsl_smartcard.h:247
volatile bool adtExpired
Definition: fsl_smartcard.h:194
uint8_t status
Definition: fsl_smartcard.h:179
smartcard_reset_type_t resetType
Definition: fsl_smartcard.h:254
uint8_t fMax
Definition: fsl_smartcard.h:168
smartcard_direction_t direction
Definition: fsl_smartcard.h:242
uint8_t GTN
Definition: fsl_smartcard.h:174
bool active
Definition: fsl_smartcard.h:185
enum _smartcard_direction smartcard_direction_t
Defines transfer direction.
uint8_t tsTimerId
Definition: fsl_smartcard.h:224
volatile bool wwtExpired
Definition: fsl_smartcard.h:195
volatile bool txtCrossed
Definition: fsl_smartcard.h:264
uint8_t controlPort
Definition: fsl_smartcard.h:211
uint8_t IFSC
Definition: fsl_smartcard.h:175
struct _smartcard_interface_config smartcard_interface_config_t
Defines user specified configuration of Smart card interface.
enum _smartcard_interface_control smartcard_interface_control_t
Defines Smart card interface IC control types.
_smartcard_control
Control codes for the Smart card protocol timers and misc.
Definition: fsl_smartcard.h:63
uint8_t vsel1Pin
Definition: fsl_smartcard.h:220
uint8_t BWI
Definition: fsl_smartcard.h:171
smartcard_transfer_callback_t transferCallback
Definition: fsl_smartcard.h:250
uint8_t * xBuff
Definition: fsl_smartcard.h:243
uint8_t Di
Definition: fsl_smartcard.h:170
struct _smartcard_context smartcard_context_t
Runtime state of the Smart card driver.
volatile smartcard_transfer_state_t transferState
Definition: fsl_smartcard.h:257
uint8_t controlPin
Definition: fsl_smartcard.h:212
uint8_t CWI
Definition: fsl_smartcard.h:172
_smartcard_card_convention
Defines data Convention format.
Definition: fsl_smartcard.h:135
volatile bool xIsBusy
Definition: fsl_smartcard.h:245
bool present
Definition: fsl_smartcard.h:184
volatile bool rxtCrossed
Definition: fsl_smartcard.h:263
enum _smartcard_card_voltage_class smartcard_card_voltage_class_t
Defines Smart card interface voltage class values.
enum _smartcard_transport_type smartcard_transport_type_t
Defines Smart card transport protocol types.
_smartcard_card_voltage_class
Defines Smart card interface voltage class values.
Definition: fsl_smartcard.h:93
smartcard_interface_config_t interfaceConfig
Definition: fsl_smartcard.h:269
void * base
Definition: fsl_smartcard.h:241
uint8_t BGI
Definition: fsl_smartcard.h:173
uint8_t clockModuleSourceClock
Definition: fsl_smartcard.h:209
enum _smartcard_reset_type smartcard_reset_type_t
Defines Smart card reset types.
smartcard_card_params_t cardParams
Definition: fsl_smartcard.h:260
enum _smartcard_parity_type smartcard_parity_type_t
Defines Smart card data parity types.
volatile bool bwtExpired
Definition: fsl_smartcard.h:197
enum _smartcard_control smartcard_control_t
Control codes for the Smart card protocol timers and misc.
uint8_t clockModule
Definition: fsl_smartcard.h:207
uint8_t statusBytes[2]
Definition: fsl_smartcard.h:267
smartcard_transport_type_t tType
Definition: fsl_smartcard.h:255
volatile size_t xSize
Definition: fsl_smartcard.h:244
volatile bool parityError
Definition: fsl_smartcard.h:266
uint8_t IFSD
Definition: fsl_smartcard.h:261
smartcard_timers_state_t timersState
Definition: fsl_smartcard.h:258
_smartcard_transport_type
Defines Smart card transport protocol types.
Definition: fsl_smartcard.h:121
volatile bool cwtExpired
Definition: fsl_smartcard.h:196
struct _smartcard_xfer smartcard_xfer_t
Defines user transfer structure used to initialize transfer.
uint32_t smartCardClock
Definition: fsl_smartcard.h:205
uint8_t vsel1Port
Definition: fsl_smartcard.h:219
bool abortTransfer
Definition: fsl_smartcard.h:270
uint32_t clockToResetDelay
Definition: fsl_smartcard.h:206
uint8_t clockModuleChannel
Definition: fsl_smartcard.h:208
bool atrComplete
Definition: fsl_smartcard.h:182
bool atrValid
Definition: fsl_smartcard.h:183
uint16_t Fi
Definition: fsl_smartcard.h:167
uint8_t * buff
Definition: fsl_smartcard.h:231
struct _smartcard_card_params smartcard_card_params_t
Defines card-specific parameters for Smart card driver.
uint8_t irqPort
Definition: fsl_smartcard.h:213
void(* smartcard_interface_callback_t)(void *smartcardContext, void *param)
Smart card interface interrupt callback function type.
Definition: fsl_smartcard.h:156
uint8_t currentD
Definition: fsl_smartcard.h:177
bool t0Indicated
Definition: fsl_smartcard.h:180
@ kStatus_SMARTCARD_TxBusy
Definition: fsl_smartcard.h:47
@ kStatus_SMARTCARD_InvalidInput
Definition: fsl_smartcard.h:56
@ kStatus_SMARTCARD_RxBusy
Definition: fsl_smartcard.h:48
@ kStatus_SMARTCARD_Initialized
Definition: fsl_smartcard.h:51
@ kStatus_SMARTCARD_NoTransferInProgress
Definition: fsl_smartcard.h:49
@ kStatus_SMARTCARD_OtherError
Definition: fsl_smartcard.h:58
@ kStatus_SMARTCARD_CardNotActivated
Definition: fsl_smartcard.h:55
@ kStatus_SMARTCARD_Timeout
Definition: fsl_smartcard.h:50
@ kStatus_SMARTCARD_PhyInitialized
Definition: fsl_smartcard.h:53
@ kStatus_SMARTCARD_Success
Definition: fsl_smartcard.h:46
Defines card-specific parameters for Smart card driver.
Definition: fsl_smartcard.h:165
Runtime state of the Smart card driver.
Definition: fsl_smartcard.h:239
Defines user specified configuration of Smart card interface.
Definition: fsl_smartcard.h:204
Smart card defines the state of the EMV timers in the Smart card driver.
Definition: fsl_smartcard.h:193
Defines user transfer structure used to initialize transfer.
Definition: fsl_smartcard.h:229