Nano103 BSP  V3.01.002
The Board Support Package for Nano103 Series
sc.h
Go to the documentation of this file.
1 /**************************************************************************/
12 #ifndef __SC_H__
13 #define __SC_H__
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 
32 #define SC_INTERFACE_NUM 2
33 #define SC_PIN_STATE_HIGH 1
34 #define SC_PIN_STATE_LOW 0
35 #define SC_PIN_STATE_IGNORE 0xFFFFFFFF
36 #define SC_CLK_ON 1
37 #define SC_CLK_OFF 0
39 #define SC_TMR_MODE_0 (0ul << SC_TMRCTL0_OPMODE_Pos)
40 #define SC_TMR_MODE_1 (1ul << SC_TMRCTL0_OPMODE_Pos)
41 #define SC_TMR_MODE_2 (2ul << SC_TMRCTL0_OPMODE_Pos)
42 #define SC_TMR_MODE_3 (3ul << SC_TMRCTL0_OPMODE_Pos)
43 #define SC_TMR_MODE_4 (4ul << SC_TMRCTL0_OPMODE_Pos)
44 #define SC_TMR_MODE_5 (5ul << SC_TMRCTL0_OPMODE_Pos)
45 #define SC_TMR_MODE_6 (6ul << SC_TMRCTL0_OPMODE_Pos)
46 #define SC_TMR_MODE_7 (7ul << SC_TMRCTL0_OPMODE_Pos)
47 #define SC_TMR_MODE_8 (8ul << SC_TMRCTL0_OPMODE_Pos)
48 #define SC_TMR_MODE_F (0xF << SC_TMRCTL0_OPMODE_Pos)
51  /* end of group NANO103_SC_EXPORTED_CONSTANTS */
52 
53 
76 #define SC_ENABLE_INT(sc, u32Mask) ((sc)->INTEN |= (u32Mask))
77 
96 #define SC_DISABLE_INT(sc, u32Mask) ((sc)->INTEN &= ~(u32Mask))
97 
105 #define SC_SET_VCC_PIN(sc, u32State) \
106  do {\
107  if(u32State)\
108  (sc)->PINCTL |= SC_PINCTL_PWREN_Msk;\
109  else\
110  (sc)->PINCTL &= ~SC_PINCTL_PWREN_Msk;\
111  }while(0)
112 
113 
121 #define SC_SET_CLK_PIN(sc, u32OnOff)\
122  do {\
123  uint32_t reg = (sc)->PINCTL;\
124  if(((reg & (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)) == 0) ||\
125  ((reg & (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)) == (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)))\
126  reg &= ~SC_PINCTL_PWREN_Msk;\
127  else\
128  reg |= SC_PINCTL_PWREN_Msk;\
129  if(u32OnOff)\
130  (sc)->PINCTL |= SC_PINCTL_CLKKEEP_Msk;\
131  else\
132  (sc)->PINCTL &= ~(SC_PINCTL_CLKKEEP_Msk);\
133  }while(0)
134 
141 #define SC_SET_IO_PIN(sc, u32State)\
142  do {\
143  uint32_t reg = (sc)->PINCTL;\
144  if(((reg & (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)) == 0) ||\
145  ((reg & (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)) == (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)))\
146  reg &= ~SC_PINCTL_PWREN_Msk;\
147  else\
148  reg |= SC_PINCTL_PWREN_Msk;\
149  if(u32State)\
150  (sc)->PINCTL |= SC_PINCTL_SCDOUT_Msk;\
151  else\
152  (sc)->PINCTL &= ~SC_PINCTL_SCDOUT_Msk;\
153  }while(0)
154 
161 #define SC_SET_RST_PIN(sc, u32State)\
162  do {\
163  uint32_t reg = (sc)->PINCTL;\
164  if(((reg & (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)) == 0) ||\
165  ((reg & (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)) == (SC_PINCTL_PWREN_Msk | SC_PINCTL_PWRINV_Msk)))\
166  reg &= ~SC_PINCTL_PWREN_Msk;\
167  else\
168  reg |= SC_PINCTL_PWREN_Msk;\
169  if(u32State)\
170  (sc)->PINCTL |= SC_PINCTL_SCRST_Msk;\
171  else\
172  (sc)->PINCTL &= ~SC_PINCTL_SCRST_Msk;\
173  }while(0)
174 
180 #define SC_READ(sc) ((char)((sc)->DAT))
181 
189 #define SC_WRITE(sc, u8Data) ((sc)->DAT = (u8Data))
190 
199 #define SC_SET_STOP_BIT_LEN(sc, u32Len) ((sc)->CTL = ((sc)->CTL & ~SC_CTL_NSB_Msk) | (u32Len == 1 ? SC_CTL_NSB_Msk : 0))
200 
207 __STATIC_INLINE void SC_SetTxRetry(SC_T *sc, uint32_t u32Count)
208 {
209  // Retry count must set while enable bit disabled, so disable it first
211 
212  if(u32Count != 0)
213  {
214  sc->CTL |= ((u32Count - 1) << SC_CTL_TXRTY_Pos) | SC_CTL_TXRTYEN_Msk;
215  }
216 }
217 
224 __STATIC_INLINE void SC_SetRxRetry(SC_T *sc, uint32_t u32Count)
225 {
226  // Retry count must set while enable bit disabled, so disable it first
228 
229  if(u32Count != 0)
230  {
231  sc->CTL |= ((u32Count - 1) << SC_CTL_RXRTY_Pos) | SC_CTL_RXRTYEN_Msk;
232  }
233 }
234 
235 
236 uint32_t SC_IsCardInserted(SC_T *sc);
237 void SC_ClearFIFO(SC_T *sc);
238 void SC_Close(SC_T *sc);
239 void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR);
240 void SC_ResetReader(SC_T *sc);
241 void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT);
242 void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT);
243 void SC_StopAllTimer(SC_T *sc);
244 void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount);
245 void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum);
246 uint32_t SC_GetInterfaceClock(SC_T *sc);
247  /* end of group NANO103_SC_EXPORTED_FUNCTIONS */
249  /* end of group NANO103_SC_Driver */
251  /* end of group NANO103_Device_Driver */
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif //__SC_H__
259 
260 /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
#define SC_CTL_RXRTY_Msk
Definition: Nano103.h:21693
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:224
#define SC_CTL_TXRTY_Pos
Definition: Nano103.h:21698
uint32_t SC_IsCardInserted(SC_T *sc)
This function indicates specified smartcard slot status.
Definition: sc.c:40
__STATIC_INLINE void SC_SetTxRetry(SC_T *sc, uint32_t u32Count)
Enable/Disable Tx error retry, and set Tx error retry count.
Definition: sc.h:207
__IO uint32_t CTL
Definition: Nano103.h:21637
void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
This function character guard time (CGT) of specified smartcard module.
Definition: sc.c:186
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:71
void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
This function stop a smartcard timer of specified smartcard module.
Definition: sc.c:252
#define SC_CTL_TXRTYEN_Msk
Definition: Nano103.h:21702
#define SC_CTL_TXRTY_Msk
Definition: Nano103.h:21699
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:61
void SC_ResetReader(SC_T *sc)
This function reset specified smartcard module to its default state for activate smartcard.
Definition: sc.c:120
__STATIC_INLINE void SC_SetRxRetry(SC_T *sc, uint32_t u32Count)
Enable/Disable Rx error retry, and set Rx error retry count.
Definition: sc.h:224
uint32_t SC_GetInterfaceClock(SC_T *sc)
This function gets smartcard clock frequency.
Definition: sc.c:267
void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
This function block guard time (BGT) of specified smartcard module.
Definition: sc.c:175
#define SC_CTL_RXRTY_Pos
Definition: Nano103.h:21692
void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR)
This function initialized smartcard module.
Definition: sc.c:91
#define SC_CTL_RXRTYEN_Msk
Definition: Nano103.h:21696
void SC_StopAllTimer(SC_T *sc)
This function stop all smartcard timer of specified smartcard module.
Definition: sc.c:198