Nano103 BSP  V3.01.002
The Board Support Package for Nano103 Series
timer.h
Go to the documentation of this file.
1 /**************************************************************************/
12 #ifndef __TIMER_H__
13 #define __TIMER_H__
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 
33 #define TIMER_ONESHOT_MODE (0UL)
34 #define TIMER_PERIODIC_MODE (1UL << TIMER_CTL_OPMODE_Pos)
35 #define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_OPMODE_Pos)
36 #define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_OPMODE_Pos)
38 #define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL)
39 #define TIMER_CAPTURE_TRIGGER_COUNTING_MODE (TIMER_CTL_CAPCNTMD_Msk)
40 #define TIMER_CAPTURE_COUNTER_RESET_MODE (TIMER_CTL_CAPFUNCS_Msk)
42 #define TIMER_CAPTURE_FALLING_EDGE (0UL)
43 #define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_CTL_CAPEDGE_Pos)
44 #define TIMER_CAPTURE_FALLING_THEN_RISING_EDGE (2UL << TIMER_CTL_CAPEDGE_Pos)
45 #define TIMER_CAPTURE_RISING_THEN_FALLING_EDGE (3UL << TIMER_CTL_CAPEDGE_Pos)
47 #define TIMER_COUNTER_RISING_EDGE (TIMER_CTL_CNTPHASE_Msk)
48 #define TIMER_COUNTER_FALLING_EDGE (0UL)
50 #define TIMER_TIMEOUT_TRIGGER (0UL)
51 #define TIMER_CAPTURE_TRIGGER (TIMER_CTL_TRGSSEL_Msk)
53  /* end of group NANO103_TIMER_EXPORTED_CONSTANTS */
54 
55 
67 #define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
68 
77 #define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->PRECNT = (u32Value))
78 
86 #define TIMER_IS_ACTIVE(timer) ((timer)->CTL & TIMER_CTL_ACTSTS_Msk ? 1 : 0)
87 
88 
94 __STATIC_INLINE void TIMER_Start(TIMER_T *timer)
95 {
96  timer->CTL |= TIMER_CTL_CNTEN_Msk;
97 }
98 
104 __STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
105 {
106  timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
107 }
108 
115 __STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
116 {
117  timer->CTL |= TIMER_CTL_WKEN_Msk;
118 }
119 
125 __STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
126 {
127  timer->CTL &= ~TIMER_CTL_WKEN_Msk;
128 }
129 
130 
136 __STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
137 {
138  timer->CTL |= TIMER_CTL_CAPDBEN_Msk;
139 }
140 
146 __STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
147 {
148  timer->CTL &= ~TIMER_CTL_CAPDBEN_Msk;
149 }
150 
151 
157 __STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
158 {
159  timer->CTL |= TIMER_CTL_CNTDBEN_Msk;
160 }
161 
167 __STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
168 {
169  timer->CTL &= ~TIMER_CTL_CNTDBEN_Msk;
170 }
171 
177 __STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
178 {
179  timer->INTEN |= TIMER_INTEN_CNTIEN_Msk;
180 }
181 
187 __STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
188 {
189  timer->INTEN &= ~TIMER_INTEN_CNTIEN_Msk;
190 }
191 
197 __STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
198 {
199  timer->INTEN |= TIMER_INTEN_CAPIEN_Msk;
200 }
201 
207 __STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
208 {
209  timer->INTEN &= ~TIMER_INTEN_CAPIEN_Msk;
210 }
211 
219 __STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
220 {
221  return(timer->INTSTS & TIMER_INTSTS_CNTIF_Msk ? 1 : 0);
222 }
223 
229 __STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
230 {
232 }
233 
241 __STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
242 {
243  return(timer->INTSTS & TIMER_INTSTS_CAPIF_Msk ? 1 : 0);
244 }
245 
251 __STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
252 {
254 }
255 
263 __STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
264 {
265  return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
266 }
267 
273 __STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
274 {
275  timer->INTSTS = TIMER_INTSTS_TWKF_Msk;
276 }
277 
283 __STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
284 {
285  return timer->CAP;
286 }
287 
293 __STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
294 {
295  return (timer->CNT & 0xFFFFFF);
296 }
297 
298 uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
299 void TIMER_Close(TIMER_T *timer);
300 void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
301 void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
302 void TIMER_DisableCapture(TIMER_T *timer);
303 void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
305 uint32_t TIMER_GetModuleClock(TIMER_T *timer);
306 void TIMER_ResetCounter(TIMER_T *timer);
307 void TIMER_EnableFreqCounter(TIMER_T *timer,
308  uint32_t u32DropCount,
309  uint32_t u32Timeout,
310  uint32_t u32EnableInt);
311 void TIMER_DisableFreqCounter(TIMER_T *timer);
312 void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
313 void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
314  /* end of group NANO103_TIMER_EXPORTED_FUNCTIONS */
316  /* end of group NANO103_TIMER_Driver */
318  /* end of group NANO103_Device_Driver */
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 
325 #endif //__TIMER_H__
326 
327 /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
__IO uint32_t CTL
Definition: Nano103.h:14227
#define TIMER_INTSTS_TWKF_Msk
Definition: Nano103.h:14327
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: timer.h:207
#define TIMER_INTEN_CAPIEN_Msk
Definition: Nano103.h:14318
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: timer.h:177
__IO uint32_t INTSTS
Definition: Nano103.h:14231
#define TIMER_INTEN_CNTIEN_Msk
Definition: Nano103.h:14315
void TIMER_Close(TIMER_T *timer)
This API stops Timer counting and disable the Timer interrupt function.
Definition: timer.c:74
void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge)
This function is used to enable the Timer counter function with specify detection edge.
Definition: timer.c:174
uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq)
This API is used to configure timer to operate in specified mode and frequency. If timer cannot work ...
Definition: timer.c:42
void TIMER_EnableFreqCounter(TIMER_T *timer, uint32_t u32DropCount, uint32_t u32Timeout, uint32_t u32EnableInt)
This function is used to enable the Timer frequency counter function.
Definition: timer.c:280
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
This function is used to stop Timer counting.
Definition: timer.h:104
#define TIMER_CTL_CNTEN_Msk
Definition: Nano103.h:14246
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:219
__I uint32_t CAP
Definition: Nano103.h:14233
void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: timer.c:185
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
This function is used to enable the capture pin detection de-bounce function.
Definition: timer.h:136
void TIMER_ResetCounter(TIMER_T *timer)
This function is used to reset the Timer counter value.
Definition: timer.c:257
#define TIMER_INTSTS_CAPIF_Msk
Definition: Nano103.h:14324
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:125
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
This function is used to disable the counter pin detection de-bounce function.
Definition: timer.h:167
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
This API is used to enable timer capture function with specified mode and capture edge.
Definition: timer.c:145
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: timer.h:229
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:251
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:94
#define TIMER_CTL_CAPDBEN_Msk
Definition: Nano103.h:14294
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This API is used to get the clock frequency of Timer.
Definition: timer.c:196
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
This function is used to disable the capture pin detection de-bounce function.
Definition: timer.h:146
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:273
#define TIMER_CTL_CNTDBEN_Msk
Definition: Nano103.h:14279
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
This function is used to enable the counter pin detection de-bounce function.
Definition: timer.h:157
void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
Definition: timer.c:334
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:293
void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: timer.c:159
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:283
__IO uint32_t CNT
Definition: Nano103.h:14232
void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
This API is used to create a delay loop for u32usec micro seconds.
Definition: timer.c:88
__IO uint32_t INTEN
Definition: Nano103.h:14230
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: timer.h:115
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: timer.h:197
#define TIMER_CTL_WKEN_Msk
Definition: Nano103.h:14252
#define TIMER_INTSTS_CNTIF_Msk
Definition: Nano103.h:14321
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:307
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: timer.h:241
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
This function is used to disable the Timer time-out interrupt function.
Definition: timer.h:187
void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src)
This function is used to select the interrupt source used to trigger other modules.
Definition: timer.c:320
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:263