| MINI58_BSP V3.01.003 The Board Support Package for Mini58 Series MCU

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_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_TRIGGER_COUNTING_MODE (TIMER_EXTCTL_CAPSEL_Msk)
39#define TIMER_CAPTURE_COUNTER_RESET_MODE (TIMER_EXTCTL_CAPFUNCS_Msk)
40#define TIMER_CAPTURE_FALLING_EDGE (0UL)
41#define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_EXTCTL_CAPEDGE_Pos)
42#define TIMER_CAPTURE_FALLING_THEN_RISING_EDGE (2UL << TIMER_EXTCTL_CAPEDGE_Pos)
43#define TIMER_CAPTURE_RISING_THEN_FALLING_EDGE (3UL << TIMER_EXTCTL_CAPEDGE_Pos)
44#define TIMER_COUNTER_RISING_EDGE (TIMER_EXTCTL_CNTPHASE_Msk)
45#define TIMER_COUNTER_FALLING_EDGE (0UL)
46#define TIMER_TOGGLE_TMX_CNT_OUT (0UL)
47#define TIMER_TOGGLE_TMX_EXT (TIMER_CTL_TGLPINSEL_Msk) /* end of group Mini58_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
83#define TIMER_IS_ACTIVE(timer) ((timer)->CTL & TIMER_CTL_ACTSTS_Msk ? 1 : 0)
84
94#define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel))
95
96
97
103__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
104{
105 timer->CTL |= TIMER_CTL_CNTEN_Msk;
106}
107
113__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
114{
115 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
116}
117
124__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
125{
126 timer->CTL |= TIMER_CTL_WKEN_Msk;
127}
128
134__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
135{
136 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
137}
138
139
145__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
146{
147 timer->EXTCTL |= TIMER_EXTCTL_CAPDBEN_Msk;
148}
149
155__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
156{
157 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
158}
159
160
166__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
167{
168 timer->EXTCTL |= TIMER_EXTCTL_CNTDBEN_Msk;
169}
170
176__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
177{
178 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
179}
180
186__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
187{
188 timer->CTL |= TIMER_CTL_INTEN_Msk;
189}
190
196__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
197{
198 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
199}
200
206__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
207{
208 timer->EXTCTL |= TIMER_EXTCTL_CAPIEN_Msk;
209}
210
216__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
217{
218 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
219}
220
228__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
229{
230 return(timer->INTSTS & TIMER_INTSTS_TIF_Msk ? 1 : 0);
231}
232
238__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
239{
240 timer->INTSTS = TIMER_INTSTS_TIF_Msk;
241}
242
250__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
251{
252 return timer->EINTSTS;
253}
254
260__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
261{
262 timer->EINTSTS = TIMER_EINTSTS_CAPIF_Msk;
263}
264
272__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
273{
274 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
275}
276
282__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
283{
284 timer->INTSTS = TIMER_INTSTS_TWKF_Msk;
285}
286
292__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
293{
294 return timer->CAP;
295}
296
302__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
303{
304 return timer->CNT;
305}
306
307uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
308 void TIMER_Close(TIMER_T *timer);
309 void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
310 void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
311 void TIMER_DisableCapture(TIMER_T *timer);
312 void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
313 void TIMER_DisableEventCounter(TIMER_T *timer);
314uint32_t TIMER_GetModuleClock(TIMER_T *timer);
315
316 /* end of group Mini58_TIMER_EXPORTED_FUNCTIONS */
318 /* end of group Mini58_TIMER_Driver */
320 /* end of group Mini58_Device_Driver */
322
323#ifdef __cplusplus
324}
325#endif
326
327#endif //__TIMER_H__
328
329/*** (C) COPYRIGHT 2022 Nuvoton Technology Corp. ***/
TIMER_INTSTS_TWKF_Msk
#define TIMER_INTSTS_TWKF_Msk
Definition: Mini58Series.h:10653
TIMER_CTL_WKEN_Msk
#define TIMER_CTL_WKEN_Msk
Definition: Mini58Series.h:10623
TIMER_EXTCTL_CAPIEN_Msk
#define TIMER_EXTCTL_CAPIEN_Msk
Definition: Mini58Series.h:10674
TIMER_CTL_INTEN_Msk
#define TIMER_CTL_INTEN_Msk
Definition: Mini58Series.h:10638
TIMER_EXTCTL_CNTDBEN_Msk
#define TIMER_EXTCTL_CNTDBEN_Msk
Definition: Mini58Series.h:10680
TIMER_EINTSTS_CAPIF_Msk
#define TIMER_EINTSTS_CAPIF_Msk
Definition: Mini58Series.h:10689
TIMER_INTSTS_TIF_Msk
#define TIMER_INTSTS_TIF_Msk
Definition: Mini58Series.h:10650
TIMER_CTL_CNTEN_Msk
#define TIMER_CTL_CNTEN_Msk
Definition: Mini58Series.h:10641
TIMER_EXTCTL_CAPDBEN_Msk
#define TIMER_EXTCTL_CAPDBEN_Msk
Definition: Mini58Series.h:10677
TIMER_GetCaptureData
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: timer.h:292
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_GetCounter
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: timer.h:302
TIMER_ClearIntFlag
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: timer.h:238
TIMER_Start
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: timer.h:103
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:155
TIMER_DisableCapture
void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: timer.c:170
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_Stop
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
This function is used to stop Timer counting.
Definition: timer.h:113
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:166
TIMER_GetCaptureIntFlag
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: timer.h:250
TIMER_ClearCaptureIntFlag
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: timer.h:260
TIMER_GetWakeupFlag
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: timer.h:272
TIMER_DisableEventCounter
void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: timer.c:196
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:196
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:186
TIMER_GetModuleClock
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
This API is used to get the clock frequency of Timer.
Definition: timer.c:207
TIMER_DisableWakeup
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: timer.h:134
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:185
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:156
TIMER_Close
void TIMER_Close(TIMER_T *timer)
This API stops Timer counting and disable the Timer interrupt function.
Definition: timer.c:78
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:176
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:145
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:216
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:206
TIMER_EnableWakeup
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: timer.h:124
TIMER_GetIntFlag
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: timer.h:228
TIMER_ClearWakeupFlag
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: timer.h:282
TIMER_T::EINTSTS
__IO uint32_t EINTSTS
Definition: Mini58Series.h:10520
TIMER_T::CAP
__I uint32_t CAP
Definition: Mini58Series.h:10449
TIMER_T::CTL
__IO uint32_t CTL
Definition: Mini58Series.h:10386
TIMER_T::INTSTS
__IO uint32_t INTSTS
Definition: Mini58Series.h:10423
TIMER_T::EXTCTL
__IO uint32_t EXTCTL
Definition: Mini58Series.h:10502
TIMER_T::CNT
__I uint32_t CNT
Definition: Mini58Series.h:10437
TIMER_T
Definition: Mini58Series.h:10318