Nano100AN Series BSP  V3.02.002
The Board Support Package for Nano100AN 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 
31 #define SC_INTERFACE_NUM 2
32 #define SC_PIN_STATE_HIGH 1
33 #define SC_PIN_STATE_LOW 0
34 #define SC_PIN_STATE_IGNORE 0xFFFFFFFF
35 #define SC_CLK_ON 1
36 #define SC_CLK_OFF 0
38 #define SC_TMR_MODE_0 (0ul << SC_TMR0_MODE_Pos)
39 #define SC_TMR_MODE_1 (1ul << SC_TMR0_MODE_Pos)
40 #define SC_TMR_MODE_2 (2ul << SC_TMR0_MODE_Pos)
41 #define SC_TMR_MODE_3 (3ul << SC_TMR0_MODE_Pos)
42 #define SC_TMR_MODE_4 (4ul << SC_TMR0_MODE_Pos)
43 #define SC_TMR_MODE_5 (5ul << SC_TMR0_MODE_Pos)
44 #define SC_TMR_MODE_6 (6ul << SC_TMR0_MODE_Pos)
45 #define SC_TMR_MODE_7 (7ul << SC_TMR0_MODE_Pos)
46 #define SC_TMR_MODE_8 (8ul << SC_TMR0_MODE_Pos)
48  /* end of group NANO100_SC_EXPORTED_CONSTANTS */
49 
51 extern uint32_t u32CardPwrPolarity[SC_INTERFACE_NUM];
53 
76 #define SC_ENABLE_INT(sc, u32Mask) ((sc)->IER |= (u32Mask))
77 
96 #define SC_DISABLE_INT(sc, u32Mask) ((sc)->IER &= ~(u32Mask))
97 
105 #define SC_SET_VCC_PIN(sc, u32State) \
106  do {\
107  uint32_t u32Intf = (sc == SC0) ? 0 : 1;\
108  if(u32State == u32CardPwrPolarity[u32Intf])\
109  (sc)->PINCSR |= SC_PINCSR_POW_EN_Msk;\
110  else\
111  (sc)->PINCSR &= ~SC_PINCSR_POW_EN_Msk;\
112  }while(0)
113 
114 
122 #define SC_SET_CLK_PIN(sc, u32OnOff)\
123  do {\
124  if(u32OnOff)\
125  (sc)->PINCSR |= SC_PINCSR_CLK_KEEP_Msk;\
126  else\
127  (sc)->PINCSR &= ~(SC_PINCSR_CLK_KEEP_Msk);\
128  }while(0)
129 
137 #define SC_SET_IO_PIN(sc, u32State)\
138  do {\
139  if(u32State)\
140  (sc)->PINCSR |= SC_PINCSR_SC_DATA_O_Msk;\
141  else\
142  (sc)->PINCSR &= ~SC_PINCSR_SC_DATA_O_Msk;\
143  }while(0)
144 
152 #define SC_SET_RST_PIN(sc, u32State)\
153  do {\
154  if(u32State)\
155  (sc)->PINCSR |= SC_PINCSR_SC_RST_Msk;\
156  else\
157  (sc)->PINCSR &= ~SC_PINCSR_SC_RST_Msk;\
158  }while(0)
159 
166 #define SC_READ(sc) ((char)((sc)->RBR))
167 
175 #define SC_WRITE(sc, u8Data) ((sc)->THR = (u8Data))
176 
185 #define SC_SET_STOP_BIT_LEN(sc, u32Len) ((sc)->CTL = ((sc)->CTL & ~SC_CTL_SLEN_Msk) | (u32Len == 1 ? SC_CTL_SLEN_Msk : 0))
186 
193 __STATIC_INLINE void SC_SetTxRetry(SC_T *sc, uint32_t u32Count)
194 {
195  // Retry count must set while enable bit disabled, so disable it first
197 
198  if(u32Count != 0)
199  {
200  sc->CTL |= ((u32Count - 1) << SC_CTL_TX_ERETRY_Pos) | SC_CTL_TX_ERETRY_EN_Msk;
201  }
202 }
203 
210 __STATIC_INLINE void SC_SetRxRetry(SC_T *sc, uint32_t u32Count)
211 {
212  // Retry count must set while enable bit disabled, so disable it first
214 
215  if(u32Count != 0)
216  {
217  sc->CTL |= ((u32Count - 1) << SC_CTL_RX_ERETRY_Pos) | SC_CTL_RX_ERETRY_EN_Msk;
218  }
219 }
220 
221 
222 uint32_t SC_IsCardInserted(SC_T *sc);
223 void SC_ClearFIFO(SC_T *sc);
224 void SC_Close(SC_T *sc);
225 void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR);
226 void SC_ResetReader(SC_T *sc);
227 void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT);
228 void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT);
229 void SC_StopAllTimer(SC_T *sc);
230 void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount);
231 void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum);
232 
233  /* end of group NANO100_SC_EXPORTED_FUNCTIONS */
235  /* end of group NANO100_SC_Driver */
237  /* end of group NANO100_Device_Driver */
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif //__SC_H__
245 
246 /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/
#define SC_CTL_RX_ERETRY_Pos
#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:206
#define SC_CTL_TX_ERETRY_Msk
#define SC_CTL_TX_ERETRY_Pos
#define SC_CTL_RX_ERETRY_Msk
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:71
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:259
void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
This function character guard time (CGT) of specified smartcard module.
Definition: sc.c:194
__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:210
#define SC_CTL_TX_ERETRY_EN_Msk
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:61
void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR)
This function initialized smartcard module.
Definition: sc.c:91
void SC_ResetReader(SC_T *sc)
This function reset specified smartcard module to its default state for activate smartcard.
Definition: sc.c:128
#define SC_INTERFACE_NUM
Definition: sc.h:31
void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
This function block guard time (BGT) of specified smartcard module.
Definition: sc.c:183
__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:231
__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:193