| Nano100AN Series BSP V3.02.002 The Board Support Package for Nano100AN Series

sc.c
Go to the documentation of this file.
1 /**************************************************************************/
12 #include "Nano100Series.h"
13
14 // Below are variables used locally by SC driver and does not want to parse by doxygen unless HIDDEN_SYMBOLS is defined
16 static uint32_t u32CardStateIgnore[SC_INTERFACE_NUM] = {0, 0};
17 uint32_t u32CardPwrPolarity[SC_INTERFACE_NUM] = {0, 0}; // cannot be static. used by SC_SET_VCC_PIN defined in sc.h
19
40 uint32_t SC_IsCardInserted(SC_T *sc)
41 {
42 // put conditions into two variable to remove IAR compilation warning
43 uint32_t cond1 = ((sc->PINCSR & SC_PINCSR_CD_PIN_ST_Msk) >> SC_PINCSR_CD_PIN_ST_Pos);
44 uint32_t cond2 = ((sc->PINCSR & SC_PINCSR_CD_LEV_Msk) >> SC_PINCSR_CD_LEV_Pos);
45
46 if(sc == SC0 && u32CardStateIgnore[0] == 1)
47 return TRUE;
48 else if(sc == SC1 && u32CardStateIgnore[1] == 1)
49 return TRUE;
50 else if(cond1 != cond2)
51 return FALSE;
52 else
53 return TRUE;
54 }
55
61 void SC_ClearFIFO(SC_T *sc)
62 {
63 sc->ALTCTL |= (SC_ALTCTL_TX_RST_Msk | SC_ALTCTL_RX_RST_Msk);
64 }
65
71 void SC_Close(SC_T *sc)
72 {
73 sc->IER = 0;
74 sc->PINCSR = 0;
75 sc->ALTCTL = 0;
76 sc->CTL = 0;
77 }
78
91 void SC_Open(SC_T *sc, uint32_t u32CD, uint32_t u32PWR)
92 {
93 uint32_t u32Reg = 0, u32Intf;
94
95 if(sc == SC0)
96 u32Intf = 0;
97 else
98 u32Intf = 1;
99
100 if(u32CD != SC_PIN_STATE_IGNORE)
101 {
102 u32Reg = u32CD ? 0: SC_PINCSR_CD_LEV_Msk;
103 u32CardStateIgnore[u32Intf] = 0;
104 }
105 else
106 {
107 u32CardStateIgnore[u32Intf] = 1;
108 }
109 // Nano100AN does not have power inverse control bit
110 if(u32PWR == SC_PIN_STATE_LOW)
111 {
112 u32Reg |= SC_PINCSR_POW_EN_Msk;
113 u32CardPwrPolarity[u32Intf] = 0;
114 }
115 else
116 {
117 u32CardPwrPolarity[u32Intf] = 1;
118 }
119 sc->PINCSR = u32Reg;
120 sc->CTL = SC_CTL_SC_CEN_Msk;
121 }
122
128 void SC_ResetReader(SC_T *sc)
129 {
130 uint32_t u32Intf;
131
132 if(sc == SC0)
133 u32Intf = 0;
134 else
135 u32Intf = 1;
136
137 // Reset FIFO
138 sc->ALTCTL |= (SC_ALTCTL_TX_RST_Msk | SC_ALTCTL_RX_RST_Msk);
139 // Set Rx trigger level to 1 character, longest card detect debounce period, disable error retry (EMV ATR does not use error retry)
140 sc->CTL &= ~(SC_CTL_RX_FTRI_LEV_Msk |
141 SC_CTL_CD_DEB_SEL_Msk |
142 SC_CTL_TX_ERETRY_Msk |
143 SC_CTL_TX_ERETRY_EN_Msk |
144 SC_CTL_RX_ERETRY_Msk |
145 SC_CTL_RX_ERETRY_EN_Msk);
146 // Enable auto convention, and all three smartcard internal timers
147 sc->CTL |= SC_CTL_AUTO_CON_EN_Msk | SC_CTL_TMR_SEL_Msk;
148 // Disable Rx timeout
149 sc->RFTMR = 0;
150 // 372 clocks per ETU by default
151 sc->ETUCR = 371;
152 // Enable auto de-activation while card removal
153 sc->PINCSR |= SC_PINCSR_ADAC_CD_EN_Msk;
154
155 /* Enable necessary interrupt for smartcard operation */
156 if(u32CardStateIgnore[u32Intf]) // Do not enable card detect interrupt if card present state ignore
157 sc->IER = (SC_IER_RDA_IE_Msk |
158 SC_IER_TERR_IE_Msk |
159 SC_IER_TMR0_IE_Msk |
160 SC_IER_TMR1_IE_Msk |
161 SC_IER_TMR2_IE_Msk |
162 SC_IER_BGT_IE_Msk |
163 SC_IER_ACON_ERR_IE_Msk);
164 else
165 sc->IER = (SC_IER_RDA_IE_Msk |
166 SC_IER_TERR_IE_Msk |
167 SC_IER_TMR0_IE_Msk |
168 SC_IER_TMR1_IE_Msk |
169 SC_IER_TMR2_IE_Msk |
170 SC_IER_BGT_IE_Msk |
171 SC_IER_CD_IE_Msk |
172 SC_IER_ACON_ERR_IE_Msk);
173
174 return;
175 }
176
183 void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
184 {
185 sc->CTL = (sc->CTL & ~SC_CTL_BGT_Msk) | ((u32BGT - 1) << SC_CTL_BGT_Pos);
186 }
187
194 void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
195 {
196 u32CGT -= sc->CTL & SC_CTL_SLEN_Msk ? 11: 12;
197 sc->EGTR = u32CGT;
198 }
199
206 void SC_StopAllTimer(SC_T *sc)
207 {
208 sc->ALTCTL &= ~(SC_ALTCTL_TMR0_SEN_Msk | SC_ALTCTL_TMR1_SEN_Msk | SC_ALTCTL_TMR2_SEN_Msk);
209 }
210
231 void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount)
232 {
233 uint32_t reg = u32Mode | (SC_TMR0_CNT_Msk & (u32ETUCount - 1));
234
235 if(u32TimerNum == 0)
236 {
237 sc->TMR0 = reg;
238 sc->ALTCTL |= SC_ALTCTL_TMR0_SEN_Msk;
239 }
240 else if(u32TimerNum == 1)
241 {
242 sc->TMR1 = reg;
243 sc->ALTCTL |= SC_ALTCTL_TMR1_SEN_Msk;
244 }
245 else // timer 2
246 {
247 sc->TMR2 = reg;
248 sc->ALTCTL |= SC_ALTCTL_TMR2_SEN_Msk;
249 }
250 }
251
259 void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
260 {
261 if(u32TimerNum == 0)
262 sc->ALTCTL &= ~SC_ALTCTL_TMR0_SEN_Msk;
263 else if(u32TimerNum == 1)
264 sc->ALTCTL &= ~SC_ALTCTL_TMR1_SEN_Msk;
265 else // timer 2
266 sc->ALTCTL &= ~SC_ALTCTL_TMR2_SEN_Msk;
267 }
268
269
270 /* end of group NANO100_SC_EXPORTED_FUNCTIONS */
272 /* end of group NANO100_SC_Driver */
274 /* end of group NANO100_Device_Driver */
276
277 /*** (C) COPYRIGHT 2013-2015 Nuvoton Technology Corp. ***/
SC1
#define SC1
Pointer to SC1 register structure.
Definition: Nano100Series.h:10116
SC_CTL_RX_ERETRY_EN_Msk
#define SC_CTL_RX_ERETRY_EN_Msk
Definition: Nano100Series.h:7619
SC_StopAllTimer
void SC_StopAllTimer(SC_T *sc)
This function stop all smartcard timer of specified smartcard module.
Definition: sc.c:206
SC_CTL_TMR_SEL_Msk
#define SC_CTL_TMR_SEL_Msk
Definition: Nano100Series.h:7610
SC_CTL_TX_ERETRY_Msk
#define SC_CTL_TX_ERETRY_Msk
Definition: Nano100Series.h:7622
SC_CTL_SC_CEN_Msk
#define SC_CTL_SC_CEN_Msk
Definition: Nano100Series.h:7589
SC_T::ETUCR
__IO uint32_t ETUCR
Definition: Nano100Series.h:7248
SC_T
Definition: Nano100Series.h:6996
SC_CTL_SLEN_Msk
#define SC_CTL_SLEN_Msk
Definition: Nano100Series.h:7613
SC_PINCSR_CD_LEV_Msk
#define SC_PINCSR_CD_LEV_Msk
Definition: Nano100Series.h:7829
SC_T::TMR1
__IO uint32_t TMR1
Definition: Nano100Series.h:7531
SC_T::ALTCTL
__IO uint32_t ALTCTL
Definition: Nano100Series.h:7200
SC_CTL_RX_ERETRY_Msk
#define SC_CTL_RX_ERETRY_Msk
Definition: Nano100Series.h:7616
FALSE
#define FALSE
Boolean false, define to use in API parameters or return value.
Definition: Nano100Series.h:10287
SC_Close
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:71
SC_ALTCTL_TMR1_SEN_Msk
#define SC_ALTCTL_TMR1_SEN_Msk
Definition: Nano100Series.h:7649
SC0
#define SC0
Pointer to SC0 register structure.
Definition: Nano100Series.h:10115
SC_PIN_STATE_IGNORE
#define SC_PIN_STATE_IGNORE
Definition: sc.h:34
SC_IsCardInserted
uint32_t SC_IsCardInserted(SC_T *sc)
This function indicates specified smartcard slot status.
Definition: sc.c:40
SC_PINCSR_CD_PIN_ST_Msk
#define SC_PINCSR_CD_PIN_ST_Msk
Definition: Nano100Series.h:7814
SC_CTL_BGT_Pos
#define SC_CTL_BGT_Pos
Definition: Nano100Series.h:7606
SC_StopTimer
void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
This function stop a smartcard timer of specified smartcard module.
Definition: sc.c:259
SC_SetCharGuardTime
void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
This function character guard time (CGT) of specified smartcard module.
Definition: sc.c:194
Nano100Series.h
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
SC_T::EGTR
__IO uint32_t EGTR
Definition: Nano100Series.h:7213
SC_PINCSR_CD_PIN_ST_Pos
#define SC_PINCSR_CD_PIN_ST_Pos
Definition: Nano100Series.h:7813
SC_ALTCTL_TMR2_SEN_Msk
#define SC_ALTCTL_TMR2_SEN_Msk
Definition: Nano100Series.h:7652
SC_IER_TMR1_IE_Msk
#define SC_IER_TMR1_IE_Msk
Definition: Nano100Series.h:7694
SC_CTL_AUTO_CON_EN_Msk
#define SC_CTL_AUTO_CON_EN_Msk
Definition: Nano100Series.h:7598
SC_CTL_CD_DEB_SEL_Msk
#define SC_CTL_CD_DEB_SEL_Msk
Definition: Nano100Series.h:7628
SC_IER_TMR2_IE_Msk
#define SC_IER_TMR2_IE_Msk
Definition: Nano100Series.h:7697
SC_IER_TMR0_IE_Msk
#define SC_IER_TMR0_IE_Msk
Definition: Nano100Series.h:7691
SC_TMR0_CNT_Msk
#define SC_TMR0_CNT_Msk
Definition: Nano100Series.h:7835
SC_PINCSR_POW_EN_Msk
#define SC_PINCSR_POW_EN_Msk
Definition: Nano100Series.h:7802
SC_IER_ACON_ERR_IE_Msk
#define SC_IER_ACON_ERR_IE_Msk
Definition: Nano100Series.h:7712
SC_IER_BGT_IE_Msk
#define SC_IER_BGT_IE_Msk
Definition: Nano100Series.h:7700
SC_IER_TERR_IE_Msk
#define SC_IER_TERR_IE_Msk
Definition: Nano100Series.h:7688
SC_ALTCTL_TX_RST_Msk
#define SC_ALTCTL_TX_RST_Msk
Definition: Nano100Series.h:7631
SC_PINCSR_ADAC_CD_EN_Msk
#define SC_PINCSR_ADAC_CD_EN_Msk
Definition: Nano100Series.h:7820
SC_T::TMR0
__IO uint32_t TMR0
Definition: Nano100Series.h:7517
SC_CTL_TX_ERETRY_EN_Msk
#define SC_CTL_TX_ERETRY_EN_Msk
Definition: Nano100Series.h:7625
SC_CTL_RX_FTRI_LEV_Msk
#define SC_CTL_RX_FTRI_LEV_Msk
Definition: Nano100Series.h:7604
SC_T::TMR2
__IO uint32_t TMR2
Definition: Nano100Series.h:7545
SC_ALTCTL_TMR0_SEN_Msk
#define SC_ALTCTL_TMR0_SEN_Msk
Definition: Nano100Series.h:7646
SC_ClearFIFO
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:61
SC_T::RFTMR
__IO uint32_t RFTMR
Definition: Nano100Series.h:7228
SC_Open
void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR)
This function initialized smartcard module.
Definition: sc.c:91
SC_ResetReader
void SC_ResetReader(SC_T *sc)
This function reset specified smartcard module to its default state for activate smartcard.
Definition: sc.c:128
SC_INTERFACE_NUM
#define SC_INTERFACE_NUM
Definition: sc.h:31
SC_PIN_STATE_LOW
#define SC_PIN_STATE_LOW
Definition: sc.h:33
SC_CTL_BGT_Msk
#define SC_CTL_BGT_Msk
Definition: Nano100Series.h:7607
SC_PINCSR_CD_LEV_Pos
#define SC_PINCSR_CD_LEV_Pos
Definition: Nano100Series.h:7828
SC_SetBlockGuardTime
void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
This function block guard time (BGT) of specified smartcard module.
Definition: sc.c:183
TRUE
#define TRUE
Boolean true, define to use in API parameters or return value.
Definition: Nano100Series.h:10286
SC_IER_RDA_IE_Msk
#define SC_IER_RDA_IE_Msk
Definition: Nano100Series.h:7682
SC_ALTCTL_RX_RST_Msk
#define SC_ALTCTL_RX_RST_Msk
Definition: Nano100Series.h:7634
SC_T::PINCSR
__IO uint32_t PINCSR
Definition: Nano100Series.h:7503
SC_T::CTL
__IO uint32_t CTL
Definition: Nano100Series.h:7110
SC_StartTimer
void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount)
This function configure and start a smartcard timer of specified smartcard module.
Definition: sc.c:231
SC_IER_CD_IE_Msk
#define SC_IER_CD_IE_Msk
Definition: Nano100Series.h:7703
SC_T::IER
__IO uint32_t IER
Definition: Nano100Series.h:7309