| M480 BSP V3.05.001 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
13 extern "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 /* end of group TIMER_EXPORTED_CONSTANTS */
59
60
79 #define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
80
93 #define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value))
94
106 #define TIMER_IS_ACTIVE(timer) (((timer)->CTL & TIMER_CTL_ACTSTS_Msk)? 1 : 0)
107
121 #define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel))
122
136 #define TIMER_SET_OPMODE(timer, u32OpMode) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_OPMODE_Msk) | (u32OpMode))
137
138 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
139 __STATIC_INLINE void TIMER_Start(TIMER_T *timer);
140 __STATIC_INLINE void TIMER_Stop(TIMER_T *timer);
141 __STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer);
142 __STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer);
143 __STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer);
144 __STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer);
145 __STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer);
146 __STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer);
147 __STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer);
148 __STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer);
149 __STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer);
150 __STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer);
151 __STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer);
152 __STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer);
153 __STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer);
154 __STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer);
155 __STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer);
156 __STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer);
157 __STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer);
158 __STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer);
159 __STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer);
160 __STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer);
161 __STATIC_INLINE void TIMER_ResetCounter(TIMER_T *timer);
162
172 __STATIC_INLINE void TIMER_Start(TIMER_T *timer)
173 {
174 timer->CTL |= TIMER_CTL_CNTEN_Msk;
175 }
176
186 __STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
187 {
188 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
189 }
190
202 __STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
203 {
204 timer->CTL |= TIMER_CTL_WKEN_Msk;
205 }
206
216 __STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
217 {
218 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
219 }
220
230 __STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer)
231 {
232 timer->EXTCTL |= TIMER_EXTCTL_CAPEN_Msk;
233 }
234
244 __STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer)
245 {
246 timer->EXTCTL &= ~TIMER_EXTCTL_CAPEN_Msk;
247 }
248
258 __STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
259 {
260 timer->EXTCTL |= TIMER_EXTCTL_CAPDBEN_Msk;
261 }
262
272 __STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
273 {
274 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
275 }
276
286 __STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
287 {
288 timer->EXTCTL |= TIMER_EXTCTL_CNTDBEN_Msk;
289 }
290
300 __STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
301 {
302 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
303 }
304
314 __STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
315 {
316 timer->CTL |= TIMER_CTL_INTEN_Msk;
317 }
318
328 __STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
329 {
330 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
331 }
332
342 __STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
343 {
344 timer->EXTCTL |= TIMER_EXTCTL_CAPIEN_Msk;
345 }
346
356 __STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
357 {
358 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
359 }
360
371 __STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
372 {
373 return ((timer->INTSTS & TIMER_INTSTS_TIF_Msk) ? 1UL : 0UL);
374 }
375
385 __STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
386 {
387 timer->INTSTS = TIMER_INTSTS_TIF_Msk;
388 }
389
400 __STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
401 {
402 return timer->EINTSTS;
403 }
404
414 __STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
415 {
416 timer->EINTSTS = TIMER_EINTSTS_CAPIF_Msk;
417 }
418
429 __STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
430 {
431 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1UL : 0UL);
432 }
433
443 __STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
444 {
445 timer->INTSTS = TIMER_INTSTS_TWKF_Msk;
446 }
447
457 __STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
458 {
459 return timer->CAP;
460 }
461
471 __STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
472 {
473 return timer->CNT;
474 }
475
485 __STATIC_INLINE void TIMER_ResetCounter(TIMER_T *timer)
486 {
487 timer->CNT = 0UL;
488 while((timer->CNT&TIMER_CNT_RSTACT_Msk) == TIMER_CNT_RSTACT_Msk)
489 {
490 ;
491 }
492 }
493
494
495 uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
496 void TIMER_Close(TIMER_T *timer);
497 void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
498 void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
499 void TIMER_DisableCapture(TIMER_T *timer);
500 void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
501 void TIMER_DisableEventCounter(TIMER_T *timer);
502 uint32_t TIMER_GetModuleClock(TIMER_T *timer);
503 void TIMER_EnableFreqCounter(TIMER_T *timer,
504 uint32_t u32DropCount,
505 uint32_t u32Timeout,
506 uint32_t u32EnableInt);
507 void TIMER_DisableFreqCounter(TIMER_T *timer);
508 void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
509 void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
510 /* end of group TIMER_EXPORTED_FUNCTIONS */
512 /* end of group TIMER_Driver */
514 /* end of group Standard_Driver */
516
517 #ifdef __cplusplus
518 }
519 #endif
520
521 #endif /* __TIMER_H__ */
522
523
TIMER_DisableCaptureDebounce
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
Disable Capture Pin De-bounce.
Definition: timer.h:272
TIMER_EXTCTL_CAPIEN_Msk
#define TIMER_EXTCTL_CAPIEN_Msk
Definition: timer_reg.h:1716
TIMER_StartCapture
__STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer)
Start Timer Capture Function.
Definition: timer.h:230
TIMER_T::CTL
__IO uint32_t CTL
Definition: timer_reg.h:1606
TIMER_T::INTSTS
__IO uint32_t INTSTS
Definition: timer_reg.h:1608
TIMER_EnableEventCounter
void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge)
Enable Timer Counter Function.
Definition: timer.c:208
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:328
TIMER_Start
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
Start Timer Counting.
Definition: timer.h:172
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:343
TIMER_ClearIntFlag
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
Clear Timer Time-out Interrupt Flag.
Definition: timer.h:385
TIMER_GetCaptureIntFlag
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
Get Timer Capture Interrupt Flag.
Definition: timer.h:400
TIMER_Open
uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq)
Open Timer with Operate Mode and Frequency.
Definition: timer.c:41
TIMER_ClearCaptureIntFlag
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
Clear Timer Capture Interrupt Flag.
Definition: timer.h:414
TIMER_T::CAP
__I uint32_t CAP
Definition: timer_reg.h:1610
TIMER_GetModuleClock
uint32_t TIMER_GetModuleClock(TIMER_T *timer)
Get Timer Clock Frequency.
Definition: timer.c:238
TIMER_Delay
void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
Create a specify Delay Time.
Definition: timer.c:92
TIMER_EnableWakeup
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
Enable Timer Interrupt Wake-up Function.
Definition: timer.h:202
TIMER_StopCapture
__STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer)
Stop Timer Capture Function.
Definition: timer.h:244
TIMER_DisableEventCounterDebounce
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
Disable Counter Pin De-bounce.
Definition: timer.h:300
TIMER_CTL_WKEN_Msk
#define TIMER_CTL_WKEN_Msk
Definition: timer_reg.h:1668
TIMER_EXTCTL_CNTDBEN_Msk
#define TIMER_EXTCTL_CNTDBEN_Msk
Definition: timer_reg.h:1722
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:294
TIMER_EnableCaptureDebounce
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
Enable Capture Pin De-bounce.
Definition: timer.h:258
TIMER_DisableFreqCounter
void TIMER_DisableFreqCounter(TIMER_T *timer)
This function is used to disable the Timer frequency counter function.
Definition: timer.c:314
TIMER_EnableCapture
void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge)
Enable Timer Capture Function.
Definition: timer.c:174
TIMER_DisableCaptureInt
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
Disable Capture Trigger Interrupt.
Definition: timer.h:356
TIMER_GetCounter
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
Get Counter value.
Definition: timer.h:471
TIMER_INTSTS_TIF_Msk
#define TIMER_INTSTS_TIF_Msk
Definition: timer_reg.h:1692
TIMER_T::EXTCTL
__IO uint32_t EXTCTL
Definition: timer_reg.h:1611
TIMER_EXTCTL_CAPDBEN_Msk
#define TIMER_EXTCTL_CAPDBEN_Msk
Definition: timer_reg.h:1719
TIMER_CNT_RSTACT_Msk
#define TIMER_CNT_RSTACT_Msk
Definition: timer_reg.h:1701
TIMER_DisableInt
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
Disable Timer Time-out Interrupt.
Definition: timer.h:328
TIMER_GetCaptureData
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
Get Capture value.
Definition: timer.h:457
TIMER_EnableEventCounterDebounce
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
Enable Counter Pin De-bounce.
Definition: timer.h:286
TIMER_DisableEventCounter
void TIMER_DisableEventCounter(TIMER_T *timer)
Disable Timer Counter Function.
Definition: timer.c:223
TIMER_ResetCounter
__STATIC_INLINE void TIMER_ResetCounter(TIMER_T *timer)
Reset Counter.
Definition: timer.h:485
TIMER_EnableInt
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
Enable Timer Time-out Interrupt.
Definition: timer.h:314
TIMER_INTSTS_TWKF_Msk
#define TIMER_INTSTS_TWKF_Msk
Definition: timer_reg.h:1695
TIMER_EINTSTS_CAPIF_Msk
#define TIMER_EINTSTS_CAPIF_Msk
Definition: timer_reg.h:1737
TIMER_EXTCTL_CAPEN_Msk
#define TIMER_EXTCTL_CAPEN_Msk
Definition: timer_reg.h:1710
TIMER_DisableCapture
void TIMER_DisableCapture(TIMER_T *timer)
Disable Timer Capture Function.
Definition: timer.c:189
TIMER_GetWakeupFlag
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
Get Timer Wake-up Flag.
Definition: timer.h:429
TIMER_DisableWakeup
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
Disable Timer Wake-up Function.
Definition: timer.h:216
TIMER_Close
void TIMER_Close(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.c:74
TIMER_T
Definition: timer_reg.h:26
TIMER_T::CNT
__IO uint32_t CNT
Definition: timer_reg.h:1609
TIMER_GetIntFlag
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
Get Timer Time-out Interrupt Flag.
Definition: timer.h:371
TIMER_T::EINTSTS
__IO uint32_t EINTSTS
Definition: timer_reg.h:1612
TIMER_CTL_INTEN_Msk
#define TIMER_CTL_INTEN_Msk
Definition: timer_reg.h:1680
TIMER_Stop
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
Stop Timer Counting.
Definition: timer.h:186
TIMER_CTL_CNTEN_Msk
#define TIMER_CTL_CNTEN_Msk
Definition: timer_reg.h:1683
TIMER_EnableCaptureInt
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
Enable Capture Trigger Interrupt.
Definition: timer.h:342
TIMER_ClearWakeupFlag
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
Clear Timer Wake-up Flag.
Definition: timer.h:443