M4521_BSP V3.02.000
The Board Support Package for M4521
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
32/*---------------------------------------------------------------------------------------------------------*/
33/* TIMER Operation Mode, External Counter and Capture Mode Constant Definitions */
34/*---------------------------------------------------------------------------------------------------------*/
35#define TIMER_ONESHOT_MODE (0UL << TIMER_CTL_OPMODE_Pos)
36#define TIMER_PERIODIC_MODE (1UL << TIMER_CTL_OPMODE_Pos)
37#define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_OPMODE_Pos)
38#define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_OPMODE_Pos)
39#define TIMER_TOUT_PIN_FROM_TX (0UL << TIMER_CTL_TGLPINSEL_Pos)
40#define TIMER_TOUT_PIN_FROM_TX_EXT (1UL << TIMER_CTL_TGLPINSEL_Pos)
41#define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL << TIMER_EXTCTL_CAPFUNCS_Pos)
42#define TIMER_CAPTURE_COUNTER_RESET_MODE (1UL << TIMER_EXTCTL_CAPFUNCS_Pos)
43#define TIMER_CAPTURE_FALLING_EDGE (0UL << TIMER_EXTCTL_CAPEDGE_Pos)
44#define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_EXTCTL_CAPEDGE_Pos)
45#define TIMER_CAPTURE_FALLING_AND_RISING_EDGE (2UL << TIMER_EXTCTL_CAPEDGE_Pos)
46#define TIMER_COUNTER_FALLING_EDGE (0UL << TIMER_EXTCTL_CNTPHASE_Pos)
47#define TIMER_COUNTER_RISING_EDGE (1UL << TIMER_EXTCTL_CNTPHASE_Pos) /* end of group TIMER_EXPORTED_CONSTANTS */
50
51/*---------------------------------------------------------------------------------------------------------*/
52/* Global variables */
53/*---------------------------------------------------------------------------------------------------------*/
54extern int32_t g_TIMER_i32ErrCode;
55
73#define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
74
86#define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value))
87
98#define TIMER_IS_ACTIVE(timer) (((timer)->CTL & TIMER_CTL_ACTSTS_Msk)? 1 : 0)
99
112#define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel))
113
123static __INLINE void TIMER_Start(TIMER_T *timer)
124{
125 timer->CTL |= TIMER_CTL_CNTEN_Msk;
126}
127
137static __INLINE void TIMER_Stop(TIMER_T *timer)
138{
139 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
140}
141
153static __INLINE void TIMER_EnableWakeup(TIMER_T *timer)
154{
155 timer->CTL |= TIMER_CTL_WKEN_Msk;
156}
157
167static __INLINE void TIMER_DisableWakeup(TIMER_T *timer)
168{
169 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
170}
171
181static __INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
182{
184}
185
195static __INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
196{
197 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
198}
199
209static __INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
210{
212}
213
223static __INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
224{
225 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
226}
227
237static __INLINE void TIMER_EnableInt(TIMER_T *timer)
238{
239 timer->CTL |= TIMER_CTL_INTEN_Msk;
240}
241
251static __INLINE void TIMER_DisableInt(TIMER_T *timer)
252{
253 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
254}
255
265static __INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
266{
268}
269
279static __INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
280{
281 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
282}
283
294static __INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
295{
296 return ((timer->INTSTS & TIMER_INTSTS_TIF_Msk) ? 1 : 0);
297}
298
308static __INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
309{
310 timer->INTSTS = (timer->INTSTS & ~TIMER_INTSTS_TWKF_Msk) | TIMER_INTSTS_TIF_Msk;
311}
312
323static __INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
324{
325 return timer->EINTSTS;
326}
327
337static __INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
338{
340}
341
352static __INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
353{
354 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
355}
356
366static __INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
367{
368 timer->INTSTS = (timer->INTSTS & ~TIMER_INTSTS_TIF_Msk) | TIMER_INTSTS_TWKF_Msk;
369}
370
380static __INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
381{
382 return timer->CAP;
383}
384
394static __INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
395{
396 return timer->CNT;
397}
398
399uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
400void TIMER_Close(TIMER_T *timer);
401void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
402void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
403void TIMER_DisableCapture(TIMER_T *timer);
404void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
406uint32_t TIMER_GetModuleClock(TIMER_T *timer);
407 /* end of group TIMER_EXPORTED_FUNCTIONS */
409 /* end of group TIMER_Driver */
411 /* end of group Standard_Driver */
413
414#ifdef __cplusplus
415}
416#endif
417
418#endif //__TIMER_H__
419
420
#define TIMER_INTSTS_TWKF_Msk
Definition: M4521.h:11322
#define TIMER_CTL_WKEN_Msk
Definition: M4521.h:11292
#define TIMER_EXTCTL_CAPIEN_Msk
Definition: M4521.h:11343
#define TIMER_CTL_INTEN_Msk
Definition: M4521.h:11307
#define TIMER_EXTCTL_CNTDBEN_Msk
Definition: M4521.h:11349
#define TIMER_EINTSTS_CAPIF_Msk
Definition: M4521.h:11352
#define TIMER_INTSTS_TIF_Msk
Definition: M4521.h:11319
#define TIMER_CTL_CNTEN_Msk
Definition: M4521.h:11310
#define TIMER_EXTCTL_CAPDBEN_Msk
Definition: M4521.h:11346
__I uint32_t CNT
Definition: M4521.h:11259
__IO uint32_t INTSTS
Definition: M4521.h:11258
__IO uint32_t EINTSTS
Definition: M4521.h:11262
__I uint32_t CAP
Definition: M4521.h:11260
__IO uint32_t CTL
Definition: M4521.h:11256
__IO uint32_t EXTCTL
Definition: M4521.h:11261
int32_t g_TIMER_i32ErrCode
Definition: timer.c:27
void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
Create a specify Delay Time.
Definition: timer.c:100
void TIMER_DisableCapture(TIMER_T *timer)
Disable Timer Capture Function.
Definition: timer.c:192
uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq)
Open Timer with Operate Mode and Frequency.
Definition: timer.c:47
static __INLINE void TIMER_EnableWakeup(TIMER_T *timer)
Enable Timer Interrupt Wake-up Function.
Definition: timer.h:153
static __INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
Get Timer Capture Interrupt Flag.
Definition: timer.h:323
static __INLINE void TIMER_DisableWakeup(TIMER_T *timer)
Disable Timer Wake-up Function.
Definition: timer.h:167
void TIMER_DisableEventCounter(TIMER_T *timer)
Disable Timer Counter Function.
Definition: timer.c:226
static __INLINE void TIMER_Stop(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.h:137
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
Get Timer Clock Frequency.
Definition: timer.c:241
static __INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
Disable Counter Pin De-bounce.
Definition: timer.h:223
static __INLINE void TIMER_EnableInt(TIMER_T *timer)
Enable Timer Time-out Interrupt.
Definition: timer.h:237
static __INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
Enable Counter Pin De-bounce.
Definition: timer.h:209
void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge)
Enable Timer Counter Function.
Definition: timer.c:211
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
Enable Timer Capture Function.
Definition: timer.c:176
static __INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
Clear Timer Time-out Interrupt Flag.
Definition: timer.h:308
void TIMER_Close(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.c:80
static __INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
Clear Timer Capture Interrupt Flag.
Definition: timer.h:337
static __INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
Get Timer Time-out Interrupt Flag.
Definition: timer.h:294
static __INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
Enable Capture Pin De-bounce.
Definition: timer.h:181
static __INLINE void TIMER_Start(TIMER_T *timer)
Start Timer Counting.
Definition: timer.h:123
static __INLINE void TIMER_DisableInt(TIMER_T *timer)
Disable Timer Time-out Interrupt.
Definition: timer.h:251
static __INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
Get Capture value.
Definition: timer.h:380
static __INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
Enable Capture Trigger Interrupt.
Definition: timer.h:265
static __INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
Disable Capture Trigger Interrupt.
Definition: timer.h:279
static __INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
Disable Capture Pin De-bounce.
Definition: timer.h:195
static __INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
Get Timer Wake-up Flag.
Definition: timer.h:352
static __INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
Get Counter value.
Definition: timer.h:394
static __INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
Clear Timer Wake-up Flag.
Definition: timer.h:366