M480 BSP V3.05.005
The Board Support Package for M480 Series
timer.h
Go to the documentation of this file.
1/**************************************************************************/
9#ifndef __TIMER_H__
10#define __TIMER_H__
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17
29/*---------------------------------------------------------------------------------------------------------*/
30/* TIMER Operation Mode, External Counter and Capture Mode Constant Definitions */
31/*---------------------------------------------------------------------------------------------------------*/
32#define TIMER_ONESHOT_MODE (0UL << TIMER_CTL_OPMODE_Pos)
33#define TIMER_PERIODIC_MODE (1UL << TIMER_CTL_OPMODE_Pos)
34#define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_OPMODE_Pos)
35#define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_OPMODE_Pos)
36#define TIMER_TOUT_PIN_FROM_TMX (0UL << TIMER_CTL_TGLPINSEL_Pos)
37#define TIMER_TOUT_PIN_FROM_TMX_EXT (1UL << TIMER_CTL_TGLPINSEL_Pos)
39#define TIMER_COUNTER_EVENT_FALLING (0UL << TIMER_EXTCTL_CNTPHASE_Pos)
40#define TIMER_COUNTER_EVENT_RISING (1UL << TIMER_EXTCTL_CNTPHASE_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)
44#define TIMER_CAPTURE_EVENT_FALLING (0UL << TIMER_EXTCTL_CAPEDGE_Pos)
45#define TIMER_CAPTURE_EVENT_RISING (1UL << TIMER_EXTCTL_CAPEDGE_Pos)
46#define TIMER_CAPTURE_EVENT_FALLING_RISING (2UL << TIMER_EXTCTL_CAPEDGE_Pos)
47#define TIMER_CAPTURE_EVENT_RISING_FALLING (3UL << TIMER_EXTCTL_CAPEDGE_Pos)
48#define TIMER_CAPTURE_EVENT_GET_LOW_PERIOD (6UL << TIMER_EXTCTL_CAPEDGE_Pos)
49#define TIMER_CAPTURE_EVENT_GET_HIGH_PERIOD (7UL << TIMER_EXTCTL_CAPEDGE_Pos)
51#define TIMER_TRGSRC_TIMEOUT_EVENT (0UL << TIMER_TRGCTL_TRGSSEL_Pos)
52#define TIMER_TRGSRC_CAPTURE_EVENT (1UL << TIMER_TRGCTL_TRGSSEL_Pos)
53#define TIMER_TRG_TO_EPWM (TIMER_TRGCTL_TRGEPWM_Msk)
54#define TIMER_TRG_TO_EADC (TIMER_TRGCTL_TRGEADC_Msk)
55#define TIMER_TRG_TO_DAC (TIMER_TRGCTL_TRGDAC_Msk)
56#define TIMER_TRG_TO_PDMA (TIMER_TRGCTL_TRGPDMA_Msk)
58#define TIMER_TIMEOUT_ERR (-1L) /* end of group TIMER_EXPORTED_CONSTANTS */
62
63
82#define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
83
96#define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value))
97
109#define TIMER_IS_ACTIVE(timer) (((timer)->CTL & TIMER_CTL_ACTSTS_Msk)? 1 : 0)
110
124#define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel))
125
139#define TIMER_SET_OPMODE(timer, u32OpMode) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_OPMODE_Msk) | (u32OpMode))
140
141/* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
142__STATIC_INLINE void TIMER_Start(TIMER_T *timer);
143__STATIC_INLINE void TIMER_Stop(TIMER_T *timer);
144__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer);
145__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer);
146__STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer);
147__STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer);
148__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer);
149__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer);
150__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer);
151__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer);
152__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer);
153__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer);
154__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer);
155__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer);
156__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer);
157__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer);
158__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer);
159__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer);
160__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer);
161__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer);
162__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer);
163__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer);
164
174__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
175{
176 timer->CTL |= TIMER_CTL_CNTEN_Msk;
177}
178
188__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
189{
190 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
191}
192
204__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
205{
206 timer->CTL |= TIMER_CTL_WKEN_Msk;
207}
208
218__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
219{
220 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
221}
222
232__STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer)
233{
235}
236
246__STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer)
247{
248 timer->EXTCTL &= ~TIMER_EXTCTL_CAPEN_Msk;
249}
250
260__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
261{
263}
264
274__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
275{
276 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
277}
278
288__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
289{
291}
292
302__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
303{
304 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
305}
306
316__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
317{
318 timer->CTL |= TIMER_CTL_INTEN_Msk;
319}
320
330__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
331{
332 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
333}
334
344__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
345{
347}
348
358__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
359{
360 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
361}
362
373__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
374{
375 return ((timer->INTSTS & TIMER_INTSTS_TIF_Msk) ? 1UL : 0UL);
376}
377
387__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
388{
390}
391
402__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
403{
404 return timer->EINTSTS;
405}
406
416__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
417{
419}
420
431__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
432{
433 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1UL : 0UL);
434}
435
445__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
446{
448}
449
459__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
460{
461 return timer->CAP;
462}
463
473__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
474{
475 return timer->CNT;
476}
477
478uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
479void TIMER_Close(TIMER_T *timer);
480int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
481void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
482void TIMER_DisableCapture(TIMER_T *timer);
483void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
485uint32_t TIMER_GetModuleClock(TIMER_T *timer);
487 uint32_t u32DropCount,
488 uint32_t u32Timeout,
489 uint32_t u32EnableInt);
491void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
492void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
493int32_t TIMER_ResetCounter(TIMER_T *timer);
494 /* end of group TIMER_EXPORTED_FUNCTIONS */
496 /* end of group TIMER_Driver */
498 /* end of group Standard_Driver */
500
501#ifdef __cplusplus
502}
503#endif
504
505#endif /* __TIMER_H__ */
#define TIMER_INTSTS_TWKF_Msk
Definition: timer_reg.h:1695
#define TIMER_CTL_WKEN_Msk
Definition: timer_reg.h:1668
#define TIMER_EXTCTL_CAPIEN_Msk
Definition: timer_reg.h:1716
#define TIMER_CTL_INTEN_Msk
Definition: timer_reg.h:1680
#define TIMER_EXTCTL_CNTDBEN_Msk
Definition: timer_reg.h:1722
#define TIMER_EINTSTS_CAPIF_Msk
Definition: timer_reg.h:1737
#define TIMER_INTSTS_TIF_Msk
Definition: timer_reg.h:1692
#define TIMER_CTL_CNTEN_Msk
Definition: timer_reg.h:1683
#define TIMER_EXTCTL_CAPEN_Msk
Definition: timer_reg.h:1710
#define TIMER_EXTCTL_CAPDBEN_Msk
Definition: timer_reg.h:1719
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
Get Capture value.
Definition: timer.h:459
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:349
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
Get Counter value.
Definition: timer.h:473
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
Clear Timer Time-out Interrupt Flag.
Definition: timer.h:387
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
Start Timer Counting.
Definition: timer.h:174
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
Disable Capture Pin De-bounce.
Definition: timer.h:274
void TIMER_DisableCapture(TIMER_T *timer)
Disable Timer Capture Function.
Definition: timer.c:210
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_Stop(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.h:188
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
Enable Counter Pin De-bounce.
Definition: timer.h:288
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
Get Timer Capture Interrupt Flag.
Definition: timer.h:402
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
Clear Timer Capture Interrupt Flag.
Definition: timer.h:416
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
Get Timer Wake-up Flag.
Definition: timer.h:431
void TIMER_DisableEventCounter(TIMER_T *timer)
Disable Timer Counter Function.
Definition: timer.c:244
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
Disable Timer Time-out Interrupt.
Definition: timer.h:330
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
Enable Timer Time-out Interrupt.
Definition: timer.h:316
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
Get Timer Clock Frequency.
Definition: timer.c:259
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
Disable Timer Wake-up Function.
Definition: timer.h:218
int32_t TIMER_ResetCounter(TIMER_T *timer)
Reset Counter.
Definition: timer.c:380
__STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer)
Stop Timer Capture Function.
Definition: timer.h:246
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:335
void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge)
Enable Timer Counter Function.
Definition: timer.c:229
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
Enable Timer Capture Function.
Definition: timer.c:195
void TIMER_Close(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.c:74
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
Disable Counter Pin De-bounce.
Definition: timer.h:302
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
Enable Capture Pin De-bounce.
Definition: timer.h:260
void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask)
This function is used to set modules trigger by timer interrupt.
Definition: timer.c:364
int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
Create a specify Delay Time.
Definition: timer.c:94
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:315
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
Disable Capture Trigger Interrupt.
Definition: timer.h:358
__STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer)
Start Timer Capture Function.
Definition: timer.h:232
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
Enable Capture Trigger Interrupt.
Definition: timer.h:344
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
Enable Timer Interrupt Wake-up Function.
Definition: timer.h:204
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
Get Timer Time-out Interrupt Flag.
Definition: timer.h:373
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
Clear Timer Wake-up Flag.
Definition: timer.h:445
__IO uint32_t CNT
Definition: timer_reg.h:1609
__IO uint32_t EINTSTS
Definition: timer_reg.h:1612
__IO uint32_t INTSTS
Definition: timer_reg.h:1608
__I uint32_t CAP
Definition: timer_reg.h:1610
__IO uint32_t CTL
Definition: timer_reg.h:1606
__IO uint32_t EXTCTL
Definition: timer_reg.h:1611