NUC472_NUC442_BSP V3.03.004
The Board Support Package for NUC472/NUC442
sc.c
Go to the documentation of this file.
1/**************************************************************************/
12#include "NUC472_442.h"
13
14// Below are variables used locally by SC driver and does not want to parse by doxygen unless HIDDEN_SYMBOLS is defined
16static uint32_t u32CardStateIgnore[SC_INTERFACE_NUM] = {0, 0, 0, 0, 0, 0};
17
19
41{
42 // put conditions into two variable to remove IAR compilation warning
43 uint32_t cond1 = ((sc->STATUS & SC_STATUS_CDPINSTS_Msk) >> SC_STATUS_CDPINSTS_Pos);
44 uint32_t cond2 = ((sc->CTL & SC_CTL_CDLV_Msk) >> SC_CTL_CDLV_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(sc == SC2 && u32CardStateIgnore[2] == 1)
51 return TRUE;
52 else if(sc == SC3 && u32CardStateIgnore[3] == 1)
53 return TRUE;
54 else if(sc == SC4 && u32CardStateIgnore[4] == 1)
55 return TRUE;
56 else if(sc == SC5 && u32CardStateIgnore[5] == 1)
57 return TRUE;
58 else if(cond1 != cond2)
59 return FALSE;
60 else
61 return TRUE;
62}
63
70{
72}
73
79void SC_Close(SC_T *sc)
80{
81 sc->INTEN = 0;
82 while(sc->PINCTL & SC_PINCTL_SYNC_Msk);
83 sc->PINCTL = 0;
84 sc->ALTCTL = 0;
85 while(sc->CTL & SC_CTL_SYNC_Msk);
86 sc->CTL = 0;
87}
88
101void SC_Open(SC_T *sc, uint32_t u32CD, uint32_t u32PWR)
102{
103 uint32_t u32Reg = 0, u32Intf;
104
105 if(sc == SC0)
106 u32Intf = 0;
107 else if(sc == SC1)
108 u32Intf = 1;
109 else if(sc == SC2)
110 u32Intf = 2;
111 else if(sc == SC3)
112 u32Intf = 3;
113 else if(sc == SC4)
114 u32Intf = 4;
115 else
116 u32Intf = 5;
117
118 if(u32CD != SC_PIN_STATE_IGNORE)
119 {
120 u32Reg = u32CD ? 0: SC_CTL_CDLV_Msk;
121 u32CardStateIgnore[u32Intf] = 0;
122 }
123 else
124 {
125 u32CardStateIgnore[u32Intf] = 1;
126 }
127 sc->PINCTL = u32PWR ? 0 : SC_PINCTL_PWRINV_Msk;
128 while(sc->CTL & SC_CTL_SYNC_Msk);
129 sc->CTL = SC_CTL_SCEN_Msk | u32Reg;
130}
131
138{
139 uint32_t u32Intf;
140
141 if(sc == SC0)
142 u32Intf = 0;
143 else if(sc == SC1)
144 u32Intf = 1;
145 else if(sc == SC2)
146 u32Intf = 2;
147 else if(sc == SC3)
148 u32Intf = 3;
149 else if(sc == SC4)
150 u32Intf = 4;
151 else
152 u32Intf = 5;
153
154 // Reset FIFO, enable auto de-activation while card removal
156 // Set Rx trigger level to 1 character, longest card detect debounce period, disable error retry (EMV ATR does not use error retry)
157 while(sc->CTL & SC_CTL_SYNC_Msk);
158 sc->CTL &= ~(SC_CTL_RXTRGLV_Msk |
164 while(sc->CTL & SC_CTL_SYNC_Msk);
165 // Enable auto convention, and all three smartcard internal timers
167 // Disable Rx timeout
168 sc->RXTOUT = 0;
169 // 372 clocks per ETU by default
170 sc->ETUCTL= 371;
171
172
173 /* Enable necessary interrupt for smartcard operation */
174 if(u32CardStateIgnore[u32Intf]) // Do not enable card detect interrupt if card present state ignore
182 else
191
192 return;
193}
194
201void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
202{
203 sc->CTL = (sc->CTL & ~SC_CTL_BGT_Msk) | ((u32BGT - 1) << SC_CTL_BGT_Pos);
204}
205
212void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
213{
214 u32CGT -= sc->CTL & SC_CTL_NSB_Msk ? 11: 12;
215 sc->EGT = u32CGT;
216}
217
225{
227}
228
250void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount)
251{
252 uint32_t reg = u32Mode | (SC_TMRCTL0_CNT_Msk & (u32ETUCount - 1));
253
254 if(u32TimerNum == 0)
255 {
256 sc->TMRCTL0 = reg;
258 }
259 else if(u32TimerNum == 1)
260 {
261 sc->TMRCTL1 = reg;
263 }
264 else // timer 2
265 {
266 sc->TMRCTL2 = reg;
268 }
269}
270
278void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
279{
280 if(u32TimerNum == 0)
281 sc->ALTCTL &= ~SC_ALTCTL_CNTEN0_Msk;
282 else if(u32TimerNum == 1)
283 sc->ALTCTL &= ~SC_ALTCTL_CNTEN1_Msk;
284 else // timer 2
285 sc->ALTCTL &= ~SC_ALTCTL_CNTEN2_Msk;
286}
287
288
289 /* end of group NUC472_442_SC_EXPORTED_FUNCTIONS */
291 /* end of group NUC472_442_SC_Driver */
293 /* end of group NUC472_442_Device_Driver */
295
296/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
NUC472/NUC442 peripheral access layer header file. This file contains all the peripheral register's d...
#define SC_INTEN_TMR2IEN_Msk
Definition: NUC472_442.h:21870
#define SC_STATUS_CDPINSTS_Pos
Definition: NUC472_442.h:21953
#define SC_INTEN_ACERRIEN_Msk
Definition: NUC472_442.h:21885
#define SC_INTEN_CDIEN_Msk
Definition: NUC472_442.h:21876
#define SC_PINCTL_PWRINV_Msk
Definition: NUC472_442.h:21993
#define SC_CTL_TXRTYEN_Msk
Definition: NUC472_442.h:21789
#define SC_CTL_RXRTYEN_Msk
Definition: NUC472_442.h:21783
#define SC_STATUS_CDPINSTS_Msk
Definition: NUC472_442.h:21954
#define SC_INTEN_TMR1IEN_Msk
Definition: NUC472_442.h:21867
#define SC_CTL_NSB_Msk
Definition: NUC472_442.h:21777
#define SC_CTL_CDLV_Pos
Definition: NUC472_442.h:21794
#define SC_ALTCTL_CNTEN1_Msk
Definition: NUC472_442.h:21819
#define SC_INTEN_TMR0IEN_Msk
Definition: NUC472_442.h:21864
#define SC_CTL_CDLV_Msk
Definition: NUC472_442.h:21795
#define SC_CTL_SYNC_Msk
Definition: NUC472_442.h:21798
#define SC_PINCTL_SYNC_Msk
Definition: NUC472_442.h:22005
#define SC_CTL_CDDBSEL_Msk
Definition: NUC472_442.h:21792
#define SC_ALTCTL_ADACEN_Msk
Definition: NUC472_442.h:21828
#define SC_CTL_TMRSEL_Msk
Definition: NUC472_442.h:21774
#define SC_ALTCTL_CNTEN2_Msk
Definition: NUC472_442.h:21822
#define SC_CTL_BGT_Pos
Definition: NUC472_442.h:21770
#define SC_INTEN_BGTIEN_Msk
Definition: NUC472_442.h:21873
#define SC_CTL_SCEN_Msk
Definition: NUC472_442.h:21753
#define SC_INTEN_RDAIEN_Msk
Definition: NUC472_442.h:21855
#define SC_ALTCTL_TXRST_Msk
Definition: NUC472_442.h:21801
#define SC_TMRCTL0_CNT_Msk
Definition: NUC472_442.h:22008
#define SC_ALTCTL_CNTEN0_Msk
Definition: NUC472_442.h:21816
#define SC_ALTCTL_RXRST_Msk
Definition: NUC472_442.h:21804
#define SC_CTL_RXTRGLV_Msk
Definition: NUC472_442.h:21768
#define SC_CTL_RXRTY_Msk
Definition: NUC472_442.h:21780
#define SC_INTEN_TERRIEN_Msk
Definition: NUC472_442.h:21861
#define SC_CTL_AUTOCEN_Msk
Definition: NUC472_442.h:21762
#define SC_CTL_TXRTY_Msk
Definition: NUC472_442.h:21786
#define SC4
Definition: NUC472_442.h:28868
#define SC5
Definition: NUC472_442.h:28869
#define SC2
Definition: NUC472_442.h:28866
#define SC1
Definition: NUC472_442.h:28865
#define SC3
Definition: NUC472_442.h:28867
#define SC0
Definition: NUC472_442.h:28864
#define SC_INTERFACE_NUM
Definition: sc.h:32
#define SC_PIN_STATE_IGNORE
Definition: sc.h:35
void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
This function block guard time (BGT) of specified smartcard module.
Definition: sc.c:201
void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
This function character guard time (CGT) of specified smartcard module.
Definition: sc.c:212
void SC_ResetReader(SC_T *sc)
This function reset specified smartcard module to its default state for activate smartcard.
Definition: sc.c:137
void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR)
This function initialized smartcard module.
Definition: sc.c:101
void SC_StopAllTimer(SC_T *sc)
This function stop all smartcard timer of specified smartcard module.
Definition: sc.c:224
uint32_t SC_IsCardInserted(SC_T *sc)
This function indicates specified smartcard slot status.
Definition: sc.c:40
void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
This function stop a smartcard timer of specified smartcard module.
Definition: sc.c:278
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:250
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:69
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:79
__IO uint32_t TMRCTL2
Definition: NUC472_442.h:21684
__IO uint32_t ALTCTL
Definition: NUC472_442.h:21325
__IO uint32_t CTL
Definition: NUC472_442.h:21226
__IO uint32_t EGT
Definition: NUC472_442.h:21338
__IO uint32_t PINCTL
Definition: NUC472_442.h:21639
__IO uint32_t STATUS
Definition: NUC472_442.h:21569
#define TRUE
Boolean true, define to use in API parameters or return value.
Definition: NUC472_442.h:29021
#define FALSE
Boolean false, define to use in API parameters or return value.
Definition: NUC472_442.h:29022
__IO uint32_t RXTOUT
Definition: NUC472_442.h:21353
__IO uint32_t TMRCTL0
Definition: NUC472_442.h:21654
__IO uint32_t INTEN
Definition: NUC472_442.h:21427
__IO uint32_t ETUCTL
Definition: NUC472_442.h:21372
__IO uint32_t TMRCTL1
Definition: NUC472_442.h:21669