NUC472_NUC442_BSP V3.03.005
The Board Support Package for NUC472/NUC442
sc.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __SC_H__
13#define __SC_H__
14
15#ifdef __cplusplus
16extern "C"
17{
18#endif
19
20
32#define SC_INTERFACE_NUM 6
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) /* end of group NUC472_442_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 while(sc->PINCTL & SC_PINCTL_SYNC_Msk);\
108 if(u32State)\
109 (sc)->PINCTL |= SC_PINCTL_PWREN_Msk;\
110 else\
111 (sc)->PINCTL &= ~SC_PINCTL_PWREN_Msk;\
112 }while(0)
113
114
122#define SC_SET_CLK_PIN(sc, u32OnOff)\
123 do {\
124 while(sc->PINCTL & SC_PINCTL_SYNC_Msk);\
125 if(u32OnOff)\
126 (sc)->PINCTL |= SC_PINCTL_CLKKEEP_Msk;\
127 else\
128 (sc)->PINCTL &= ~(SC_PINCTL_CLKKEEP_Msk);\
129 }while(0)
130
138#define SC_SET_IO_PIN(sc, u32State)\
139 do {\
140 while(sc->PINCTL & SC_PINCTL_SYNC_Msk);\
141 if(u32State)\
142 (sc)->PINCTL |= SC_PINCTL_SCDOUT_Msk;\
143 else\
144 (sc)->PINCTL &= ~SC_PINCTL_SCDOUT_Msk;\
145 }while(0)
146
154#define SC_SET_RST_PIN(sc, u32State)\
155 do {\
156 while(sc->PINCTL & SC_PINCTL_SYNC_Msk);\
157 if(u32State)\
158 (sc)->PINCTL |= SC_PINCTL_SCRST_Msk;\
159 else\
160 (sc)->PINCTL &= ~SC_PINCTL_SCRST_Msk;\
161 }while(0)
162
169#define SC_READ(sc) ((char)((sc)->DAT))
170
178#define SC_WRITE(sc, u8Data) ((sc)->DAT = (u8Data))
179
188#define SC_SET_STOP_BIT_LEN(sc, u32Len) ((sc)->CTL = ((sc)->CTL & ~SC_CTL_NSB_Msk) | (u32Len == 1 ? SC_CTL_NSB_Msk : 0))
189
196__STATIC_INLINE void SC_SetTxRetry(SC_T *sc, uint32_t u32Count)
197{
198 while(sc->CTL & SC_CTL_SYNC_Msk);
199 // Retry count must set while enable bit disabled, so disable it first
201
202 if(u32Count != 0)
203 {
204 while(sc->CTL & SC_CTL_SYNC_Msk);
205 sc->CTL |= ((u32Count - 1) << SC_CTL_TXRTY_Pos) | SC_CTL_TXRTYEN_Msk;
206 }
207}
208
215__STATIC_INLINE void SC_SetRxRetry(SC_T *sc, uint32_t u32Count)
216{
217 while(sc->CTL & SC_CTL_SYNC_Msk);
218 // Retry count must set while enable bit disabled, so disable it first
220
221 if(u32Count != 0)
222 {
223 while(sc->CTL & SC_CTL_SYNC_Msk);
224 sc->CTL = (sc->CTL & ~SC_CTL_RXRTY_Msk) | ((u32Count - 1) << SC_CTL_RXRTY_Pos) | SC_CTL_RXRTYEN_Msk;
225 }
226}
227
228
229uint32_t SC_IsCardInserted(SC_T *sc);
230void SC_ClearFIFO(SC_T *sc);
231void SC_Close(SC_T *sc);
232void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR);
233void SC_ResetReader(SC_T *sc);
234void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT);
235void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT);
236void SC_StopAllTimer(SC_T *sc);
237void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount);
238void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum);
239
240 /* end of group NUC472_442_SC_EXPORTED_FUNCTIONS */
242 /* end of group NUC472_442_SC_Driver */
244 /* end of group NUC472_442_Device_Driver */
246
247#ifdef __cplusplus
248}
249#endif
250
251#endif //__SC_H__
252
253/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
#define SC_CTL_TXRTYEN_Msk
Definition: NUC472_442.h:21789
#define SC_CTL_RXRTYEN_Msk
Definition: NUC472_442.h:21783
#define SC_CTL_SYNC_Msk
Definition: NUC472_442.h:21798
#define SC_CTL_RXRTY_Pos
Definition: NUC472_442.h:21779
#define SC_CTL_TXRTY_Pos
Definition: NUC472_442.h:21785
#define SC_CTL_RXRTY_Msk
Definition: NUC472_442.h:21780
#define SC_CTL_TXRTY_Msk
Definition: NUC472_442.h:21786
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
__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:215
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:69
__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:196
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:79
__IO uint32_t CTL
Definition: NUC472_442.h:21226