M480 BSP V3.05.006
The Board Support Package for M480 Series
sc.h
Go to the documentation of this file.
1/**************************************************************************/
9#ifndef __SC_H__
10#define __SC_H__
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17
29#define SC_INTERFACE_NUM 3
30#define SC_PIN_STATE_HIGH 1
31#define SC_PIN_STATE_LOW 0
32#define SC_PIN_STATE_IGNORE 0xFFFFFFFF
33#define SC_CLK_ON 1
34#define SC_CLK_OFF 0
36#define SC_TMR_MODE_0 (0ul << SC_TMRCTL0_OPMODE_Pos)
37#define SC_TMR_MODE_1 (1ul << SC_TMRCTL0_OPMODE_Pos)
38#define SC_TMR_MODE_2 (2ul << SC_TMRCTL0_OPMODE_Pos)
39#define SC_TMR_MODE_3 (3ul << SC_TMRCTL0_OPMODE_Pos)
40#define SC_TMR_MODE_4 (4ul << SC_TMRCTL0_OPMODE_Pos)
41#define SC_TMR_MODE_5 (5ul << SC_TMRCTL0_OPMODE_Pos)
42#define SC_TMR_MODE_6 (6ul << SC_TMRCTL0_OPMODE_Pos)
43#define SC_TMR_MODE_7 (7ul << SC_TMRCTL0_OPMODE_Pos)
44#define SC_TMR_MODE_8 (8ul << SC_TMRCTL0_OPMODE_Pos)
45#define SC_TMR_MODE_F (0xF << SC_TMRCTL0_OPMODE_Pos) /* end of group SC_EXPORTED_CONSTANTS */
49
50
73#define SC_ENABLE_INT(sc, u32Mask) ((sc)->INTEN |= (u32Mask))
74
93#define SC_DISABLE_INT(sc, u32Mask) ((sc)->INTEN &= ~(u32Mask))
94
102#define SC_SET_VCC_PIN(sc, u32State) \
103 do {\
104 while((sc)->PINCTL & SC_PINCTL_SYNC_Msk);\
105 if(u32State)\
106 (sc)->PINCTL |= SC_PINCTL_PWREN_Msk;\
107 else\
108 (sc)->PINCTL &= ~SC_PINCTL_PWREN_Msk;\
109 }while(0)
110
111
119#define SC_SET_CLK_PIN(sc, u32OnOff)\
120 do {\
121 while((sc)->PINCTL & SC_PINCTL_SYNC_Msk);\
122 if(u32OnOff)\
123 (sc)->PINCTL |= SC_PINCTL_CLKKEEP_Msk;\
124 else\
125 (sc)->PINCTL &= ~(SC_PINCTL_CLKKEEP_Msk);\
126 }while(0)
127
135#define SC_SET_IO_PIN(sc, u32State)\
136 do {\
137 while((sc)->PINCTL & SC_PINCTL_SYNC_Msk);\
138 if(u32State)\
139 (sc)->PINCTL |= SC_PINCTL_SCDATA_Msk;\
140 else\
141 (sc)->PINCTL &= ~SC_PINCTL_SCDATA_Msk;\
142 }while(0)
143
151#define SC_SET_RST_PIN(sc, u32State)\
152 do {\
153 while((sc)->PINCTL & SC_PINCTL_SYNC_Msk);\
154 if(u32State)\
155 (sc)->PINCTL |= SC_PINCTL_RSTEN_Msk;\
156 else\
157 (sc)->PINCTL &= ~SC_PINCTL_RSTEN_Msk;\
158 }while(0)
159
166#define SC_READ(sc) ((char)((sc)->DAT))
167
175#define SC_WRITE(sc, u8Data) ((sc)->DAT = (u8Data))
176
185#define SC_SET_STOP_BIT_LEN(sc, u32Len) ((sc)->CTL = ((sc)->CTL & ~SC_CTL_NSB_Msk) | ((u32Len) == 1 ? SC_CTL_NSB_Msk : 0))
186
187/* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
188__STATIC_INLINE void SC_SetTxRetry(SC_T *sc, uint32_t u32Count);
189__STATIC_INLINE void SC_SetRxRetry(SC_T *sc, uint32_t u32Count);
190
197__STATIC_INLINE void SC_SetTxRetry(SC_T *sc, uint32_t u32Count)
198{
199 while((sc)->CTL & SC_CTL_SYNC_Msk)
200 {
201 ;
202 }
203 /* Retry count must set while enable bit disabled, so disable it first */
204 (sc)->CTL &= ~(SC_CTL_TXRTY_Msk | SC_CTL_TXRTYEN_Msk);
205
206 if((u32Count) != 0UL)
207 {
208 while((sc)->CTL & SC_CTL_SYNC_Msk)
209 {
210 ;
211 }
212 (sc)->CTL |= (((u32Count) - 1UL) << SC_CTL_TXRTY_Pos) | SC_CTL_TXRTYEN_Msk;
213 }
214}
215
222__STATIC_INLINE void SC_SetRxRetry(SC_T *sc, uint32_t u32Count)
223{
224 while((sc)->CTL & SC_CTL_SYNC_Msk)
225 {
226 ;
227 }
228 /* Retry count must set while enable bit disabled, so disable it first */
229 (sc)->CTL &= ~(SC_CTL_RXRTY_Msk | SC_CTL_RXRTYEN_Msk);
230
231 if((u32Count) != 0UL)
232 {
233 while((sc)->CTL & SC_CTL_SYNC_Msk)
234 {
235 ;
236 }
237 (sc)->CTL |= (((u32Count) - 1UL) << SC_CTL_RXRTY_Pos) | SC_CTL_RXRTYEN_Msk;
238 }
239
240}
241
242
243uint32_t SC_IsCardInserted(SC_T *sc);
244void SC_ClearFIFO(SC_T *sc);
245void SC_Close(SC_T *sc);
246void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR);
247void SC_ResetReader(SC_T *sc);
248void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT);
249void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT);
250void SC_StopAllTimer(SC_T *sc);
251void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount);
252void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum);
253uint32_t SC_GetInterfaceClock(SC_T *sc);
254
255 /* end of group SC_EXPORTED_FUNCTIONS */
257 /* end of group SC_Driver */
259 /* end of group Standard_Driver */
261
262#ifdef __cplusplus
263}
264#endif
265
266#endif /* __SC_H__ */
267
268/*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/
#define SC_CTL_TXRTYEN_Msk
Definition: sc_reg.h:1550
#define SC_CTL_RXRTYEN_Msk
Definition: sc_reg.h:1544
#define SC_CTL_SYNC_Msk
Definition: sc_reg.h:1559
#define SC_CTL_RXRTY_Pos
Definition: sc_reg.h:1540
#define SC_CTL_TXRTY_Pos
Definition: sc_reg.h:1546
#define SC_CTL_RXRTY_Msk
Definition: sc_reg.h:1541
#define SC_CTL_TXRTY_Msk
Definition: sc_reg.h:1547
void SC_Open(SC_T *sc, uint32_t u32CardDet, uint32_t u32PWR)
This function initialized smartcard module.
Definition: sc.c:113
void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT)
This function block guard time (BGT) of specified smartcard module.
Definition: sc.c:225
void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT)
This function character guard time (CGT) of specified smartcard module.
Definition: sc.c:236
void SC_ResetReader(SC_T *sc)
This function reset specified smartcard module to its default state for activate smartcard.
Definition: sc.c:152
void SC_StopAllTimer(SC_T *sc)
This function stop all smartcard timer of specified smartcard module.
Definition: sc.c:248
uint32_t SC_GetInterfaceClock(SC_T *sc)
This function gets smartcard clock frequency.
Definition: sc.c:346
uint32_t SC_IsCardInserted(SC_T *sc)
This function indicates specified smartcard slot status.
Definition: sc.c:36
void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum)
This function stop a smartcard timer of specified smartcard module.
Definition: sc.c:321
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:278
__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:222
void SC_ClearFIFO(SC_T *sc)
This function reset both transmit and receive FIFO of specified smartcard module.
Definition: sc.c:71
__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:197
void SC_Close(SC_T *sc)
This function disable specified smartcard module.
Definition: sc.c:85
Definition: sc_reg.h:27