M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
timer.h
Go to the documentation of this file.
1/**************************************************************************/
8#ifndef __TIMER_H__
9#define __TIMER_H__
10
11#ifdef __cplusplus
12extern "C"
13{
14#endif
15
16
28/*---------------------------------------------------------------------------------------------------------*/
29/* TIMER Operation Mode, External Counter and Capture Mode Constant Definitions */
30/*---------------------------------------------------------------------------------------------------------*/
31#define TIMER_ONESHOT_MODE (0UL << TIMER_CTL_OPMODE_Pos)
32#define TIMER_PERIODIC_MODE (1UL << TIMER_CTL_OPMODE_Pos)
33#define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_OPMODE_Pos)
34#define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_OPMODE_Pos)
35#define TIMER_TOUT_PIN_FROM_TX (0UL << TIMER_CTL_TGLPINSEL_Pos)
36#define TIMER_TOUT_PIN_FROM_TX_EXT (1UL << TIMER_CTL_TGLPINSEL_Pos)
37#define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL << TIMER_EXTCTL_CAPFUNCS_Pos)
38#define TIMER_CAPTURE_COUNTER_RESET_MODE (1UL << TIMER_EXTCTL_CAPFUNCS_Pos)
39#define TIMER_CAPTURE_FALLING_EDGE (0UL << TIMER_EXTCTL_CAPEDGE_Pos)
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_FALLING_EDGE (0UL << TIMER_EXTCTL_CNTPHASE_Pos)
43#define TIMER_COUNTER_RISING_EDGE (1UL << TIMER_EXTCTL_CNTPHASE_Pos)
45#define TIMER_TIMEOUT_ERR (-1L) /* end of group TIMER_EXPORTED_CONSTANTS */
48
49
67#define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
68
80#define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value))
81
92#define TIMER_IS_ACTIVE(timer) (((timer)->CTL & TIMER_CTL_ACTSTS_Msk)? 1 : 0)
93
106#define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel))
107
117static __INLINE void TIMER_Start(TIMER_T *timer)
118{
119 timer->CTL |= TIMER_CTL_CNTEN_Msk;
120}
121
131static __INLINE void TIMER_Stop(TIMER_T *timer)
132{
133 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
134}
135
147static __INLINE void TIMER_EnableWakeup(TIMER_T *timer)
148{
149 timer->CTL |= TIMER_CTL_WKEN_Msk;
150}
151
161static __INLINE void TIMER_DisableWakeup(TIMER_T *timer)
162{
163 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
164}
165
175static __INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
176{
178}
179
189static __INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
190{
191 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
192}
193
203static __INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
204{
206}
207
217static __INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
218{
219 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
220}
221
231static __INLINE void TIMER_EnableInt(TIMER_T *timer)
232{
233 timer->CTL |= TIMER_CTL_INTEN_Msk;
234}
235
245static __INLINE void TIMER_DisableInt(TIMER_T *timer)
246{
247 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
248}
249
259static __INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
260{
262}
263
273static __INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
274{
275 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
276}
277
288static __INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
289{
290 return ((timer->INTSTS & TIMER_INTSTS_TIF_Msk) ? 1 : 0);
291}
292
302static __INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
303{
304 timer->INTSTS = (timer->INTSTS & ~TIMER_INTSTS_TWKF_Msk) | TIMER_INTSTS_TIF_Msk;
305}
306
317static __INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
318{
319 return timer->EINTSTS;
320}
321
331static __INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
332{
334}
335
346static __INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
347{
348 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
349}
350
360static __INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
361{
362 timer->INTSTS = (timer->INTSTS & ~TIMER_INTSTS_TIF_Msk) | TIMER_INTSTS_TWKF_Msk;
363}
364
374static __INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
375{
376 return timer->CAP;
377}
378
388static __INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
389{
390 return timer->CNT;
391}
392
393uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
394void TIMER_Close(TIMER_T *timer);
395int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
396void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
397void TIMER_DisableCapture(TIMER_T *timer);
398void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
400uint32_t TIMER_GetModuleClock(TIMER_T *timer);
401 /* end of group TIMER_EXPORTED_FUNCTIONS */
403 /* end of group TIMER_Driver */
405 /* end of group Standard_Driver */
407
408#ifdef __cplusplus
409}
410#endif
411
412#endif //__TIMER_H__
413
414
#define TIMER_INTSTS_TWKF_Msk
Definition: M471M_R1_S.h:11318
#define TIMER_CTL_WKEN_Msk
Definition: M471M_R1_S.h:11288
#define TIMER_EXTCTL_CAPIEN_Msk
Definition: M471M_R1_S.h:11339
#define TIMER_CTL_INTEN_Msk
Definition: M471M_R1_S.h:11303
#define TIMER_EXTCTL_CNTDBEN_Msk
Definition: M471M_R1_S.h:11345
#define TIMER_EINTSTS_CAPIF_Msk
Definition: M471M_R1_S.h:11348
#define TIMER_INTSTS_TIF_Msk
Definition: M471M_R1_S.h:11315
#define TIMER_CTL_CNTEN_Msk
Definition: M471M_R1_S.h:11306
#define TIMER_EXTCTL_CAPDBEN_Msk
Definition: M471M_R1_S.h:11342
__I uint32_t CNT
Definition: M471M_R1_S.h:11255
__IO uint32_t INTSTS
Definition: M471M_R1_S.h:11254
__IO uint32_t EINTSTS
Definition: M471M_R1_S.h:11258
__I uint32_t CAP
Definition: M471M_R1_S.h:11256
__IO uint32_t CTL
Definition: M471M_R1_S.h:11252
__IO uint32_t EXTCTL
Definition: M471M_R1_S.h:11257
void TIMER_DisableCapture(TIMER_T *timer)
Disable Timer Capture Function.
Definition: timer.c:209
uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq)
Open Timer with Operate Mode and Frequency.
Definition: timer.c:41
static __INLINE void TIMER_EnableWakeup(TIMER_T *timer)
Enable Timer Interrupt Wake-up Function.
Definition: timer.h:147
static __INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
Get Timer Capture Interrupt Flag.
Definition: timer.h:317
static __INLINE void TIMER_DisableWakeup(TIMER_T *timer)
Disable Timer Wake-up Function.
Definition: timer.h:161
void TIMER_DisableEventCounter(TIMER_T *timer)
Disable Timer Counter Function.
Definition: timer.c:243
static __INLINE void TIMER_Stop(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.h:131
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
Get Timer Clock Frequency.
Definition: timer.c:258
static __INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
Disable Counter Pin De-bounce.
Definition: timer.h:217
static __INLINE void TIMER_EnableInt(TIMER_T *timer)
Enable Timer Time-out Interrupt.
Definition: timer.h:231
static __INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
Enable Counter Pin De-bounce.
Definition: timer.h:203
void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge)
Enable Timer Counter Function.
Definition: timer.c:228
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
Enable Timer Capture Function.
Definition: timer.c:193
static __INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
Clear Timer Time-out Interrupt Flag.
Definition: timer.h:302
void TIMER_Close(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.c:74
static __INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
Clear Timer Capture Interrupt Flag.
Definition: timer.h:331
static __INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
Get Timer Time-out Interrupt Flag.
Definition: timer.h:288
static __INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
Enable Capture Pin De-bounce.
Definition: timer.h:175
static __INLINE void TIMER_Start(TIMER_T *timer)
Start Timer Counting.
Definition: timer.h:117
static __INLINE void TIMER_DisableInt(TIMER_T *timer)
Disable Timer Time-out Interrupt.
Definition: timer.h:245
static __INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
Get Capture value.
Definition: timer.h:374
int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
Create a specify Delay Time.
Definition: timer.c:92
static __INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
Enable Capture Trigger Interrupt.
Definition: timer.h:259
static __INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
Disable Capture Trigger Interrupt.
Definition: timer.h:273
static __INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
Disable Capture Pin De-bounce.
Definition: timer.h:189
static __INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
Get Timer Wake-up Flag.
Definition: timer.h:346
static __INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
Get Counter value.
Definition: timer.h:388
static __INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
Clear Timer Wake-up Flag.
Definition: timer.h:360