| Nano100BN Series BSP V3.03.002 The Board Support Package for Nano100BN 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)
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)
53 /* end of group NANO100_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 {
138 timer->CTL |= TIMER_CTL_TCAP_DEB_EN_Msk;
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 {
159 timer->CTL |= TIMER_CTL_EVNT_DEB_EN_Msk;
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 {
275 timer->ISR = TIMER_ISR_TMR_WAKE_STS_Msk;
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;
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);
304 void TIMER_DisableEventCounter(TIMER_T *timer);
305 uint32_t TIMER_GetModuleClock(TIMER_T *timer);
306 void TIMER_EnableFreqCounter(TIMER_T *timer,
307 uint32_t u32DropCount,
308 uint32_t u32Timeout,
309 uint32_t u32EnableInt);
310 void TIMER_DisableFreqCounter(TIMER_T *timer);
311 void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
312 void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
313 /* end of group NANO100_TIMER_EXPORTED_FUNCTIONS */
315 /* end of group NANO100_TIMER_Driver */
317 /* end of group NANO100_Device_Driver */
319
320 #ifdef __cplusplus
321 }
322 #endif
323
324 #endif //__TIMER_H__
325
326 /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
TIMER_DisableInt
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
This function is used to disable the Timer time-out interrupt function.
Definition: timer.h:187
TIMER_ClearWakeupFlag
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:273
TIMER_ClearIntFlag
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: timer.h:229
TIMER_DisableEventCounter
void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: timer.c:195
TIMER_Start
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:94
TIMER_EnableCaptureDebounce
__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
TIMER_GetCounter
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:293
TIMER_T::DR
__I uint32_t DR
Definition: Nano100Series.h:9976
TIMER_CTL_TMR_EN_Msk
#define TIMER_CTL_TMR_EN_Msk
Definition: Nano100Series.h:9999
TIMER_CTL_TCAP_DEB_EN_Msk
#define TIMER_CTL_TCAP_DEB_EN_Msk
Definition: Nano100Series.h:10050
TIMER_CTL_WAKE_EN_Msk
#define TIMER_CTL_WAKE_EN_Msk
Definition: Nano100Series.h:10005
TIMER_ISR_TMR_WAKE_STS_Msk
#define TIMER_ISR_TMR_WAKE_STS_Msk
Definition: Nano100Series.h:10074
TIMER_T::IER
__IO uint32_t IER
Definition: Nano100Series.h:9933
TIMER_EnableCapture
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:155
TIMER_IER_TMR_IE_Msk
#define TIMER_IER_TMR_IE_Msk
Definition: Nano100Series.h:10062
TIMER_EnableWakeup
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: timer.h:115
TIMER_T::ISR
__IO uint32_t ISR
Definition: Nano100Series.h:9964
TIMER_DisableEventCounterDebounce
__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
TIMER_DisableCapture
void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: timer.c:169
TIMER_EnableCaptureInt
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: timer.h:197
TIMER_IER_TCAP_IE_Msk
#define TIMER_IER_TCAP_IE_Msk
Definition: Nano100Series.h:10065
TIMER_GetModuleClock
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This API is used to get the clock frequency of Timer.
Definition: timer.c:206
TIMER_DisableCaptureDebounce
__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
TIMER_ClearCaptureIntFlag
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:251
TIMER_DisableWakeup
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:125
TIMER_Stop
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
This function is used to stop Timer counting.
Definition: timer.h:104
TIMER_Close
void TIMER_Close(TIMER_T *timer)
This API stops Timer counting and disable the Timer interrupt function.
Definition: timer.c:79
TIMER_Delay
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:93
TIMER_GetIntFlag
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:219
TIMER_T::TCAP
__I uint32_t TCAP
Definition: Nano100Series.h:9989
TIMER_GetCaptureData
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:283
TIMER_T
Definition: Nano100Series.h:9745
TIMER_GetWakeupFlag
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:263
TIMER_EnableInt
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: timer.h:177
TIMER_EnableFreqCounter
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:240
TIMER_GetCaptureIntFlag
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: timer.h:241
TIMER_CTL_EVNT_DEB_EN_Msk
#define TIMER_CTL_EVNT_DEB_EN_Msk
Definition: Nano100Series.h:10035
TIMER_ISR_TCAP_IS_Msk
#define TIMER_ISR_TCAP_IS_Msk
Definition: Nano100Series.h:10071
TIMER_SetTriggerTarget
void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
Definition: timer.c:287
TIMER_T::CTL
__IO uint32_t CTL
Definition: Nano100Series.h:9885
TIMER_DisableFreqCounter
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:260
TIMER_SetTriggerSource
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:273
TIMER_EnableEventCounter
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:184
TIMER_Open
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
TIMER_ISR_TMR_IS_Msk
#define TIMER_ISR_TMR_IS_Msk
Definition: Nano100Series.h:10068
TIMER_EnableEventCounterDebounce
__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
TIMER_DisableCaptureInt
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: timer.h:207