NUC472_NUC442_BSP V3.03.005
The Board Support Package for NUC472/NUC442
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)
37#define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL)
38#define TIMER_CAPTURE_COUNTER_RESET_MODE (TIMER_EXTCTL_CAPFUNCS_Msk)
39#define TIMER_CAPTURE_FALLING_EDGE (0UL)
40#define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_EXTCTL_CAPEDGE_Pos)
41#define TIMER_CAPTURE_FALLING_AND_RISING_EDGE (2UL << TIMER_EXTCTL_CAPEDGE_Pos)
42#define TIMER_COUNTER_RISING_EDGE (TIMER_EXTCTL_CNTPHASE_Msk)
43#define TIMER_COUNTER_FALLING_EDGE (0UL)
44#define TIMER_TOGGLE_OUT1 (TIMER_CTL_TOGDIS2_Msk)
45#define TIMER_TOGGLE_OUT2 (TIMER_CTL_TOGDIS1_Msk)
47#define TIMER_TIMEOUT_ERR (-1L) /* end of group NUC472_442_TIMER_EXPORTED_CONSTANTS */
50
51
63#define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
64
73#define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value))
74
82#define TIMER_IS_ACTIVE(timer) ((timer)->CTL & TIMER_CTL_ACTSTS_Msk ? 1 : 0)
83
93#define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~(TIMER_CTL_TOGDIS2_Msk | TIMER_CTL_TOGDIS1_Msk)) | (u32ToutSel))
94
95
101__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
102{
103 timer->CTL |= TIMER_CTL_CNTEN_Msk;
104}
105
111__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
112{
113 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
114}
115
122__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
123{
124 timer->CTL |= TIMER_CTL_WKEN_Msk;
125}
126
132__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
133{
134 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
135}
136
137
143__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
144{
146}
147
153__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
154{
155 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
156}
157
158
164__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
165{
167}
168
174__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
175{
176 timer->EXTCTL &= ~TIMER_EXTCTL_ECNTDBEN_Msk;
177}
178
184__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
185{
186 timer->CTL |= TIMER_CTL_INTEN_Msk;
187}
188
194__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
195{
196 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
197}
198
204__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
205{
207}
208
214__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
215{
216 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
217}
218
226__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
227{
228 return(timer->INTSTS & TIMER_INTSTS_TIF_Msk ? 1 : 0);
229}
230
236__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
237{
239}
240
248__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
249{
250 return timer->EINTSTS;
251}
252
258__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
259{
261}
262
270__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
271{
272 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
273}
274
280__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
281{
283}
284
290__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
291{
292 return timer->CAP;
293}
294
300__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
301{
302 return timer->CNT;
303}
304
305uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
306void TIMER_Close(TIMER_T *timer);
307int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
308void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
309void TIMER_DisableCapture(TIMER_T *timer);
310void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
312uint32_t TIMER_GetModuleClock(TIMER_T *timer);
313
314 /* end of group NUC472_442_TIMER_EXPORTED_FUNCTIONS */
316 /* end of group NUC472_442_TIMER_Driver */
318 /* end of group NUC472_442_Device_Driver */
320
321#ifdef __cplusplus
322}
323#endif
324
325#endif //__TIMER_H__
326
327/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
#define TIMER_INTSTS_TWKF_Msk
Definition: NUC472_442.h:25127
#define TIMER_CTL_WKEN_Msk
Definition: NUC472_442.h:25097
#define TIMER_EXTCTL_CAPIEN_Msk
Definition: NUC472_442.h:25148
#define TIMER_CTL_INTEN_Msk
Definition: NUC472_442.h:25112
#define TIMER_EINTSTS_CAPIF_Msk
Definition: NUC472_442.h:25157
#define TIMER_INTSTS_TIF_Msk
Definition: NUC472_442.h:25124
#define TIMER_CTL_CNTEN_Msk
Definition: NUC472_442.h:25115
#define TIMER_EXTCTL_ECNTDBEN_Msk
Definition: NUC472_442.h:25154
#define TIMER_EXTCTL_CAPDBEN_Msk
Definition: NUC472_442.h:25151
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:290
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:300
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: timer.h:236
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:101
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
This function is used to disable the capture pin detection de-bounce function.
Definition: timer.h:153
void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: timer.c:201
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:111
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
This function is used to enable the counter pin detection de-bounce function.
Definition: timer.h:164
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: timer.h:248
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:258
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:270
void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: timer.c:228
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
This function is used to disable the Timer time-out interrupt function.
Definition: timer.h:194
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: timer.h:184
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This API is used to get the clock frequency of Timer.
Definition: timer.c:239
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:132
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:217
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:188
void TIMER_Close(TIMER_T *timer)
This API stops Timer counting and disable the Timer interrupt function.
Definition: timer.c:84
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
This function is used to disable the counter pin detection de-bounce function.
Definition: timer.h:174
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
This function is used to enable the capture pin detection de-bounce function.
Definition: timer.h:143
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:103
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: timer.h:214
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: timer.h:204
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: timer.h:122
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:226
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:280
__IO uint32_t EINTSTS
Definition: NUC472_442.h:25075
__I uint32_t CAP
Definition: NUC472_442.h:25018
__IO uint32_t CTL
Definition: NUC472_442.h:24954
__IO uint32_t INTSTS
Definition: NUC472_442.h:24991
__IO uint32_t EXTCTL
Definition: NUC472_442.h:25059
__I uint32_t CNT
Definition: NUC472_442.h:25006