NANO103 BSP V3.01.004
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
16extern "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#define TIMER_TIMEOUT_ERR (-1L) /* end of group NANO103_TIMER_EXPORTED_CONSTANTS */
56
57
69#define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
70
79#define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->PRECNT = (u32Value))
80
88#define TIMER_IS_ACTIVE(timer) ((timer)->CTL & TIMER_CTL_ACTSTS_Msk ? 1 : 0)
89
90
96__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
97{
98 timer->CTL |= TIMER_CTL_CNTEN_Msk;
99}
100
106__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
107{
108 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
109}
110
117__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
118{
119 timer->CTL |= TIMER_CTL_WKEN_Msk;
120}
121
127__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
128{
129 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
130}
131
132
138__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
139{
140 timer->CTL |= TIMER_CTL_CAPDBEN_Msk;
141}
142
148__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
149{
150 timer->CTL &= ~TIMER_CTL_CAPDBEN_Msk;
151}
152
153
159__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
160{
161 timer->CTL |= TIMER_CTL_CNTDBEN_Msk;
162}
163
169__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
170{
171 timer->CTL &= ~TIMER_CTL_CNTDBEN_Msk;
172}
173
179__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
180{
182}
183
189__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
190{
191 timer->INTEN &= ~TIMER_INTEN_CNTIEN_Msk;
192}
193
199__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
200{
202}
203
209__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
210{
211 timer->INTEN &= ~TIMER_INTEN_CAPIEN_Msk;
212}
213
221__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
222{
223 return(timer->INTSTS & TIMER_INTSTS_CNTIF_Msk ? 1 : 0);
224}
225
231__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
232{
234}
235
243__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
244{
245 return(timer->INTSTS & TIMER_INTSTS_CAPIF_Msk ? 1 : 0);
246}
247
253__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
254{
256}
257
265__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
266{
267 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
268}
269
275__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
276{
278}
279
285__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
286{
287 return timer->CAP;
288}
289
295__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
296{
297 return (timer->CNT & 0xFFFFFF);
298}
299
300uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
301void TIMER_Close(TIMER_T *timer);
302int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
303void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
304void TIMER_DisableCapture(TIMER_T *timer);
305void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
307uint32_t TIMER_GetModuleClock(TIMER_T *timer);
308void TIMER_ResetCounter(TIMER_T *timer);
310 uint32_t u32DropCount,
311 uint32_t u32Timeout,
312 uint32_t u32EnableInt);
314void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
315void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
316 /* end of group NANO103_TIMER_EXPORTED_FUNCTIONS */
318 /* end of group NANO103_TIMER_Driver */
320 /* end of group NANO103_Device_Driver */
322
323#ifdef __cplusplus
324}
325#endif
326
327#endif //__TIMER_H__
328
329/*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
#define TIMER_INTEN_CAPIEN_Msk
Definition: Nano103.h:7837
#define TIMER_INTSTS_TWKF_Msk
Definition: Nano103.h:7846
#define TIMER_CTL_CAPDBEN_Msk
Definition: Nano103.h:7813
#define TIMER_INTSTS_CAPIF_Msk
Definition: Nano103.h:7843
#define TIMER_CTL_WKEN_Msk
Definition: Nano103.h:7771
#define TIMER_CTL_CNTDBEN_Msk
Definition: Nano103.h:7798
#define TIMER_INTSTS_CNTIF_Msk
Definition: Nano103.h:7840
#define TIMER_CTL_CNTEN_Msk
Definition: Nano103.h:7765
#define TIMER_INTEN_CNTIEN_Msk
Definition: Nano103.h:7834
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:285
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:344
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:295
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: timer.h:231
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:96
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
This function is used to disable the capture pin detection de-bounce function.
Definition: timer.h:148
void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: timer.c:183
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
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
This function is used to stop Timer counting.
Definition: timer.h:106
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
This function is used to enable the counter pin detection de-bounce function.
Definition: timer.h:159
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: timer.h:243
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:253
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:265
void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: timer.c:209
void TIMER_ResetCounter(TIMER_T *timer)
This function is used to reset the Timer counter value.
Definition: timer.c:281
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
This function is used to disable the Timer time-out interrupt function.
Definition: timer.h:189
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: timer.h:179
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This API is used to get the clock frequency of Timer.
Definition: timer.c:220
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:127
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:331
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:198
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:169
void TIMER_Close(TIMER_T *timer)
This API stops Timer counting and disable the Timer interrupt function.
Definition: timer.c:74
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
This function is used to disable the counter pin detection de-bounce function.
Definition: timer.h:169
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
This function is used to enable the capture pin detection de-bounce function.
Definition: timer.h:138
void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
Definition: timer.c:358
int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
This API is used to create a delay loop for u32usec micro seconds.
Definition: timer.c:91
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:304
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: timer.h:209
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: timer.h:199
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: timer.h:117
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:221
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:275
__IO uint32_t CNT
Definition: Nano103.h:7751
__IO uint32_t INTSTS
Definition: Nano103.h:7750
__I uint32_t CAP
Definition: Nano103.h:7752
__IO uint32_t CTL
Definition: Nano103.h:7746
__IO uint32_t INTEN
Definition: Nano103.h:7749