Nano100AN Series BSP  V3.02.002
The Board Support Package for Nano100AN 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_MODE_SEL_Pos)
35 #define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_MODE_SEL_Pos)
37 #define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL)
38 #define TIMER_CAPTURE_TRIGGER_COUNTING_MODE (TIMER_CTL_TCAP_CNT_MODE_Msk)
39 #define TIMER_CAPTURE_COUNTER_RESET_MODE (TIMER_CTL_TCAP_MODE_Msk)
41 #define TIMER_CAPTURE_FALLING_EDGE (0UL)
42 #define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_CTL_TCAP_EDGE_Pos)
43 #define TIMER_CAPTURE_FALLING_THEN_RISING_EDGE (2UL << TIMER_CTL_TCAP_EDGE_Pos)
44 #define TIMER_CAPTURE_RISING_THEN_FALLING_EDGE (3UL << TIMER_CTL_TCAP_EDGE_Pos)
46 #define TIMER_COUNTER_RISING_EDGE (TIMER_CTL_EVENT_EDGE_Msk)
47 #define TIMER_COUNTER_FALLING_EDGE (0UL)
49 #define TIMER_TIMEOUT_TRIGGER (0UL)
50 #define TIMER_CAPTURE_TRIGGER (TIMER_CTL_CAP_TRG_EN_Msk)
52  /* end of group NANO100_TIMER_EXPORTED_CONSTANTS */
53 
54 
66 #define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMPR = (u32Value))
67 
76 #define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->PRECNT = (u32Value))
77 
85 #define TIMER_IS_ACTIVE(timer) ((timer)->CTL & TIMER_CTL_TMR_ACT_Msk ? 1 : 0)
86 
87 
93 __STATIC_INLINE void TIMER_Start(TIMER_T *timer)
94 {
95  timer->CTL |= TIMER_CTL_TMR_EN_Msk;
96 }
97 
103 __STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
104 {
105  timer->CTL &= ~TIMER_CTL_TMR_EN_Msk;
106 }
107 
114 __STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
115 {
116  timer->CTL |= TIMER_CTL_WAKE_EN_Msk;
117 }
118 
124 __STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
125 {
126  timer->CTL &= ~TIMER_CTL_WAKE_EN_Msk;
127 }
128 
129 
135 __STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
136 {
137  timer->CTL |= TIMER_CTL_TCAP_DEB_EN_Msk;
138 }
139 
145 __STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
146 {
147  timer->CTL &= ~TIMER_CTL_TCAP_DEB_EN_Msk;
148 }
149 
150 
156 __STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
157 {
158  timer->CTL |= TIMER_CTL_EVNT_DEB_EN_Msk;
159 }
160 
166 __STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
167 {
168  timer->CTL &= ~TIMER_CTL_EVNT_DEB_EN_Msk;
169 }
170 
176 __STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
177 {
178  timer->IER |= TIMER_IER_TMR_IE_Msk;
179 }
180 
186 __STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
187 {
188  timer->IER &= ~TIMER_IER_TMR_IE_Msk;
189 }
190 
196 __STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
197 {
198  timer->IER |= TIMER_IER_TCAP_IE_Msk;
199 }
200 
206 __STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
207 {
208  timer->IER &= ~TIMER_IER_TCAP_IE_Msk;
209 }
210 
218 __STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
219 {
220  return(timer->ISR & TIMER_ISR_TMR_IS_Msk ? 1 : 0);
221 }
222 
228 __STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
229 {
230  timer->ISR = TIMER_ISR_TMR_IS_Msk;
231 }
232 
240 __STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
241 {
242  return(timer->ISR & TIMER_ISR_TCAP_IS_Msk ? 1 : 0);
243 }
244 
250 __STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
251 {
252  timer->ISR = TIMER_ISR_TCAP_IS_Msk;
253 }
254 
262 __STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
263 {
264  return (timer->ISR & TIMER_ISR_TMR_WAKE_STS_Msk ? 1 : 0);
265 }
266 
272 __STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
273 {
275 }
276 
282 __STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
283 {
284  return timer->TCAP;
285 }
286 
292 __STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
293 {
294  return timer->DR;
295 }
296 
297 uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
298 void TIMER_Close(TIMER_T *timer);
299 void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
300 void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
301 void TIMER_DisableCapture(TIMER_T *timer);
302 void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
304 uint32_t TIMER_GetModuleClock(TIMER_T *timer);
305 void TIMER_EnableFreqCounter(TIMER_T *timer,
306  uint32_t u32DropCount,
307  uint32_t u32Timeout,
308  uint32_t u32EnableInt);
309 void TIMER_DisableFreqCounter(TIMER_T *timer);
310 void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
311 void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
312  /* end of group NANO100_TIMER_EXPORTED_FUNCTIONS */
314  /* end of group NANO100_TIMER_Driver */
316  /* end of group NANO100_Device_Driver */
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 
323 #endif //__TIMER_H__
324 
325 /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
This function is used to disable the Timer time-out interrupt function.
Definition: timer.h:186
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:272
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: timer.h:228
void TIMER_DisableEventCounter(TIMER_T *timer)
This function is used to disable the Timer event counter function.
Definition: timer.c:184
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:93
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
This function is used to enable the capture pin detection de-bounce function.
Definition: timer.h:135
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:292
__I uint32_t DR
#define TIMER_CTL_TMR_EN_Msk
#define TIMER_CTL_TCAP_DEB_EN_Msk
#define TIMER_CTL_WAKE_EN_Msk
#define TIMER_ISR_TMR_WAKE_STS_Msk
__IO uint32_t IER
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
This function is used to enable timer capture function with specified mode and capture edge.
Definition: timer.c:144
#define TIMER_IER_TMR_IE_Msk
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: timer.h:114
__IO uint32_t ISR
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
This function is used to disable the counter pin detection de-bounce function.
Definition: timer.h:166
void TIMER_DisableCapture(TIMER_T *timer)
This function is used to disable the Timer capture function.
Definition: timer.c:158
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: timer.h:196
#define TIMER_IER_TCAP_IE_Msk
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This function is used to get the clock frequency of Timer.
Definition: timer.c:195
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
This function is used to disable the capture pin detection de-bounce function.
Definition: timer.h:145
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:250
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:124
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
This function is used to stop Timer counting.
Definition: timer.h:103
void TIMER_Close(TIMER_T *timer)
This function stops Timer counting and disable the Timer interrupt function.
Definition: timer.c:73
void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
This function is used to create a delay loop for u32usec micro seconds.
Definition: timer.c:87
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:218
__I uint32_t TCAP
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:282
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:262
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: timer.h:176
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:229
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: timer.h:240
#define TIMER_CTL_EVNT_DEB_EN_Msk
#define TIMER_ISR_TCAP_IS_Msk
void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
Definition: timer.c:275
__IO uint32_t CTL
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:249
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:262
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:173
uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq)
This function is used to configure timer to operate in specified mode and frequency....
Definition: timer.c:41
#define TIMER_ISR_TMR_IS_Msk
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
This function is used to enable the counter pin detection de-bounce function.
Definition: timer.h:156
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: timer.h:206