Nano100BN Series BSP  V3.03.002
The Board Support Package for Nano100BN 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, 0};
17 
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(sc == SC2 && u32CardStateIgnore[2] == 1)
51  return TRUE;
52  else if(cond1 != cond2)
53  return FALSE;
54  else
55  return TRUE;
56 }
57 
63 void SC_ClearFIFO(SC_T *sc)
64 {
66 }
67 
73 void SC_Close(SC_T *sc)
74 {
75  sc->IER = 0;
76  sc->PINCSR = 0;
77  sc->ALTCTL = 0;
78  sc->CTL = 0;
79 }
80 
93 void SC_Open(SC_T *sc, uint32_t u32CD, uint32_t u32PWR)
94 {
95  uint32_t u32Reg = 0, u32Intf;
96 
97  if(sc == SC0)
98  u32Intf = 0;
99  else if(sc == SC1)
100  u32Intf = 1;
101  else
102  u32Intf = 2;
103 
104  if(u32CD != SC_PIN_STATE_IGNORE)
105  {
106  u32Reg = u32CD ? 0: SC_PINCSR_CD_LEV_Msk;
107  u32CardStateIgnore[u32Intf] = 0;
108  }
109  else
110  {
111  u32CardStateIgnore[u32Intf] = 1;
112  }
113  u32Reg |= u32PWR ? 0 : SC_PINCSR_POW_INV_Msk;
114  sc->PINCSR = u32Reg;
115  sc->CTL = SC_CTL_SC_CEN_Msk;
116 }
117 
124 {
125  uint32_t u32Intf;
126 
127  if(sc == SC0)
128  u32Intf = 0;
129  else if(sc == SC1)
130  u32Intf = 1;
131  else
132  u32Intf = 2;
133 
134  // Reset FIFO
136  // Set Rx trigger level to 1 character, longest card detect debounce period, disable error retry (EMV ATR does not use error retry)
137  sc->CTL &= ~(SC_CTL_RX_FTRI_LEV_Msk |
143  // Enable auto convention, and all three smartcard internal timers
145  // Disable Rx timeout
146  sc->RFTMR = 0;
147  // 372 clocks per ETU by default
148  sc->ETUCR = 371;
149  // Enable auto de-activation while card removal
151 
152  /* Enable necessary interrupt for smartcard operation */
153  if(u32CardStateIgnore[u32Intf]) // Do not enable card detect interrupt if card present state ignore
154  sc->IER = (SC_IER_RDA_IE_Msk |
161  else
162  sc->IER = (SC_IER_RDA_IE_Msk |
170 
171  return;
172 }
173 
180 void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
181 {
182  sc->CTL = (sc->CTL & ~SC_CTL_BGT_Msk) | ((u32BGT - 1) << SC_CTL_BGT_Pos);
183 }
184 
191 void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
192 {
193  u32CGT -= sc->CTL & SC_CTL_SLEN_Msk ? 11: 12;
194  sc->EGTR = u32CGT;
195 }
196 
204 {
206 }
207 
229 void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount)
230 {
231  uint32_t reg = u32Mode | (SC_TMR0_CNT_Msk & (u32ETUCount - 1));
232 
233  if(u32TimerNum == 0)
234  {
235  sc->TMR0 = reg;
237  }
238  else if(u32TimerNum == 1)
239  {
240  sc->TMR1 = reg;
242  }
243  else // timer 2
244  {
245  sc->TMR2 = reg;
247  }
248 }
249 
257 void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
258 {
259  if(u32TimerNum == 0)
261  else if(u32TimerNum == 1)
263  else // timer 2
265 }
266 
267 
268  /* end of group NANO100_SC_EXPORTED_FUNCTIONS */
270  /* end of group NANO100_SC_Driver */
272  /* end of group NANO100_Device_Driver */
274 
275 /*** (C) COPYRIGHT 2013-2014 Nuvoton Technology Corp. ***/
#define SC1
Pointer to SC1 register structure.
#define SC_CTL_RX_ERETRY_EN_Msk
void SC_StopAllTimer(SC_T *sc)
This function stop all smartcard timer of specified smartcard module.
Definition: sc.c:203
#define SC_CTL_TMR_SEL_Msk
#define SC_CTL_TX_ERETRY_Msk
#define SC_CTL_SC_CEN_Msk
__IO uint32_t ETUCR
#define SC_CTL_SLEN_Msk
#define SC_PINCSR_CD_LEV_Msk
__IO uint32_t TMR1
__IO uint32_t ALTCTL
#define SC_CTL_RX_ERETRY_Msk
#define FALSE
Boolean false, define to use in API parameters or return value.
#define SC2
Pointer to SC2 register structure.
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:73
#define SC_ALTCTL_TMR1_SEN_Msk
#define SC0
Pointer to SC0 register structure.
#define SC_PIN_STATE_IGNORE
Definition: sc.h:35
uint32_t SC_IsCardInserted(SC_T *sc)
This function indicates specified smartcard slot status.
Definition: sc.c:40
#define SC_PINCSR_CD_PIN_ST_Msk
#define SC_CTL_BGT_Pos
void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
This function stop a smartcard timer of specified smartcard module.
Definition: sc.c:257
void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
This function character guard time (CGT) of specified smartcard module.
Definition: sc.c:191
Nano100 series peripheral access layer header file. This file contains all the peripheral register's ...
__IO uint32_t EGTR
#define SC_PINCSR_CD_PIN_ST_Pos
#define SC_ALTCTL_TMR2_SEN_Msk
#define SC_IER_TMR1_IE_Msk
#define SC_CTL_AUTO_CON_EN_Msk
#define SC_CTL_CD_DEB_SEL_Msk
#define SC_IER_TMR2_IE_Msk
#define SC_IER_TMR0_IE_Msk
#define SC_TMR0_CNT_Msk
#define SC_PINCSR_POW_EN_Msk
#define SC_IER_ACON_ERR_IE_Msk
#define SC_IER_BGT_IE_Msk
#define SC_IER_TERR_IE_Msk
#define SC_ALTCTL_TX_RST_Msk
#define SC_PINCSR_ADAC_CD_EN_Msk
__IO uint32_t TMR0
#define SC_CTL_TX_ERETRY_EN_Msk
#define SC_CTL_RX_FTRI_LEV_Msk
__IO uint32_t TMR2
#define SC_ALTCTL_TMR0_SEN_Msk
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:63
__IO uint32_t RFTMR
void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR)
This function initialized smartcard module.
Definition: sc.c:93
void SC_ResetReader(SC_T *sc)
This function reset specified smartcard module to its default state for activate smartcard.
Definition: sc.c:123
#define SC_INTERFACE_NUM
Definition: sc.h:32
#define SC_CTL_BGT_Msk
#define SC_PINCSR_CD_LEV_Pos
#define SC_PINCSR_POW_INV_Msk
void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
This function block guard time (BGT) of specified smartcard module.
Definition: sc.c:180
#define TRUE
Boolean true, define to use in API parameters or return value.
#define SC_IER_RDA_IE_Msk
#define SC_ALTCTL_RX_RST_Msk
__IO uint32_t PINCSR
__IO uint32_t CTL
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:229
#define SC_IER_CD_IE_Msk
__IO uint32_t IER