NANO102/112 BSP V3.03.003
The Board Support Package for Nano102/112 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_MODE_SEL_Pos)
35#define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_MODE_SEL_Pos)
36#define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_MODE_SEL_Pos)
38#define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL)
39#define TIMER_CAPTURE_TRIGGER_COUNTING_MODE (TIMER_CTL_TCAP_CNT_MODE_Msk)
40#define TIMER_CAPTURE_COUNTER_RESET_MODE (TIMER_CTL_TCAP_MODE_Msk)
42#define TIMER_CAPTURE_FALLING_EDGE (0UL)
43#define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_CTL_TCAP_EDGE_Pos)
44#define TIMER_CAPTURE_FALLING_THEN_RISING_EDGE (2UL << TIMER_CTL_TCAP_EDGE_Pos)
45#define TIMER_CAPTURE_RISING_THEN_FALLING_EDGE (3UL << TIMER_CTL_TCAP_EDGE_Pos)
47#define TIMER_COUNTER_RISING_EDGE (TIMER_CTL_EVENT_EDGE_Msk)
48#define TIMER_COUNTER_FALLING_EDGE (0UL)
50#define TIMER_TIMEOUT_TRIGGER (0UL)
51#define TIMER_CAPTURE_TRIGGER (TIMER_CTL_CAP_TRG_EN_Msk) /* end of group NANO1X2_TIMER_EXPORTED_CONSTANTS */
54
55
67#define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMPR = (u32Value))
68
77#define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->PRECNT = (u32Value))
78
86#define TIMER_IS_ACTIVE(timer) ((timer)->CTL & TIMER_CTL_TMR_ACT_Msk ? 1 : 0)
87
88
94__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
95{
96 timer->CTL |= TIMER_CTL_TMR_EN_Msk;
97}
98
104__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
105{
106 timer->CTL &= ~TIMER_CTL_TMR_EN_Msk;
107}
108
115__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
116{
117 timer->CTL |= TIMER_CTL_WAKE_EN_Msk;
118}
119
125__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
126{
127 timer->CTL &= ~TIMER_CTL_WAKE_EN_Msk;
128}
129
130
136__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
137{
139}
140
146__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
147{
148 timer->CTL &= ~TIMER_CTL_TCAP_DEB_EN_Msk;
149}
150
151
157__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
158{
160}
161
167__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
168{
169 timer->CTL &= ~TIMER_CTL_EVNT_DEB_EN_Msk;
170}
171
177__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
178{
179 timer->IER |= TIMER_IER_TMR_IE_Msk;
180}
181
187__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
188{
189 timer->IER &= ~TIMER_IER_TMR_IE_Msk;
190}
191
197__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
198{
199 timer->IER |= TIMER_IER_TCAP_IE_Msk;
200}
201
207__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
208{
209 timer->IER &= ~TIMER_IER_TCAP_IE_Msk;
210}
211
219__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
220{
221 return(timer->ISR & TIMER_ISR_TMR_IS_Msk ? 1 : 0);
222}
223
229__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
230{
231 timer->ISR = TIMER_ISR_TMR_IS_Msk;
232}
233
241__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
242{
243 return(timer->ISR & TIMER_ISR_TCAP_IS_Msk ? 1 : 0);
244}
245
251__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
252{
253 timer->ISR = TIMER_ISR_TCAP_IS_Msk;
254}
255
263__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
264{
265 return (timer->ISR & TIMER_ISR_TMR_WAKE_STS_Msk ? 1 : 0);
266}
267
273__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
274{
276}
277
283__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
284{
285 return timer->TCAP;
286}
287
293__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
294{
295 return (timer->DR & 0xFFFFFF);
296}
297
298uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
299void TIMER_Close(TIMER_T *timer);
300void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
301void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
302void TIMER_DisableCapture(TIMER_T *timer);
303void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
305uint32_t TIMER_GetModuleClock(TIMER_T *timer);
306void TIMER_ResetCounter(TIMER_T *timer);
308 uint32_t u32DropCount,
309 uint32_t u32Timeout,
310 uint32_t u32EnableInt);
312void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
313void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
314 /* end of group NANO1X2_TIMER_EXPORTED_FUNCTIONS */
316 /* end of group NANO1X2_TIMER_Driver */
318 /* end of group NANO1X2_Device_Driver */
320
321#ifdef __cplusplus
322}
323#endif
324
325#endif //__TIMER_H__
326
327/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
#define TIMER_CTL_TMR_EN_Msk
#define TIMER_ISR_TCAP_IS_Msk
#define TIMER_ISR_TMR_IS_Msk
#define TIMER_ISR_TMR_WAKE_STS_Msk
#define TIMER_IER_TCAP_IE_Msk
#define TIMER_CTL_WAKE_EN_Msk
#define TIMER_CTL_EVNT_DEB_EN_Msk
#define TIMER_CTL_TCAP_DEB_EN_Msk
#define TIMER_IER_TMR_IE_Msk
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:283
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:304
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
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:293
__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_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:94
__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
void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: timer.c:160
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:104
__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
__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_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:251
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:263
void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: timer.c:186
void TIMER_ResetCounter(TIMER_T *timer)
This function is used to reset the Timer counter value.
Definition: timer.c: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
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: timer.h:177
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This API is used to get the clock frequency of Timer.
Definition: timer.c:197
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:125
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:291
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:175
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:146
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:167
__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_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
Definition: timer.c:317
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:264
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: timer.h:207
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: timer.h:197
__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 uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:219
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:273
__IO uint32_t IER
__IO uint32_t DR
__IO uint32_t ISR
__IO uint32_t CTL
__I uint32_t TCAP