PAN1080 Peripheral API
pan_timer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Panchip Technology Corp. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
15#ifndef __PAN_TIMER_H__
16#define __PAN_TIMER_H__
17
24#ifdef __cplusplus
25extern "C"
26{
27#endif
28
34{
35 TIMER_ONESHOT_MODE = (0UL << TIMER_CTL_OPMODE_Pos),
36 TIMER_PERIODIC_MODE = (1UL << TIMER_CTL_OPMODE_Pos),
37 TIMER_TOGGLE_MODE = (2UL << TIMER_CTL_OPMODE_Pos),
38 TIMER_CONTINUOUS_MODE = (3UL << TIMER_CTL_OPMODE_Pos)
46{
48 TIMER_CAPTURE_TRIGGER_COUNTING_MODE = (TIMER_EXTCTL_CAPSEL_Msk),
49 TIMER_CAPTURE_COUNTER_RESET_MODE = (TIMER_EXTCTL_CAPFUNCS_Msk)
57{
58 TIMER_CAPTURE_FALLING_EDGE = (0UL << TIMER_EXTCTL_CAPEDGE_Pos),
59 TIMER_CAPTURE_RISING_EDGE = (1UL << TIMER_EXTCTL_CAPEDGE_Pos),
60 TIMER_CAPTURE_BOTH_EDGE = (2UL << TIMER_EXTCTL_CAPEDGE_Pos),
61 TIMER_CAPTURE_FALLING_THEN_RISING_EDGE = (2UL << TIMER_EXTCTL_CAPEDGE_Pos),
62 TIMER_CAPTURE_RISING_THEN_FALLING_EDGE = (3UL << TIMER_EXTCTL_CAPEDGE_Pos)
70{
72 TIMER_COUNTER_RISING_EDGE = (TIMER_EXTCTL_CNTPHASE_Msk)
80typedef enum _TIMER_CapSrcDef
81{
83 TIMER_CAPTURE_SOURCE_32K_OUTPUT = (TIMER_CTL_CAPSRC_Msk)
102__STATIC_INLINE void TIMER_EnableCapture(TIMER_T *timer, TIMER_CapModeDef capMode, TIMER_CapEdgeDef capEdge)
103{
104
105 timer->EXTCTL = (timer->EXTCTL & ~(TIMER_EXTCTL_CAPSEL_Msk |
106 TIMER_EXTCTL_CAPFUNCS_Msk |
107 TIMER_EXTCTL_CAPEDGE_Msk)) |
108 capMode | capEdge | TIMER_EXTCTL_CAPEN_Msk;
109}
110
116__STATIC_INLINE void TIMER_DisableCapture(TIMER_T *timer)
117{
118 timer->EXTCTL &= ~TIMER_EXTCTL_CAPEN_Msk;
119}
120
130__STATIC_INLINE void TIMER_EnableEventCounter(TIMER_T *timer, TIMER_EvtCntEdgeDef evtCntEdge)
131{
132 timer->EXTCTL = (timer->EXTCTL & ~TIMER_EXTCTL_CNTPHASE_Msk) | evtCntEdge;
133 timer->CTL |= TIMER_CTL_EXTCNTEN_Msk;
134}
135
141__STATIC_INLINE void TIMER_DisableEventCounter(TIMER_T *timer)
142{
143 timer->CTL &= ~TIMER_CTL_EXTCNTEN_Msk;
144}
145
152__STATIC_INLINE void TIMER_SetCmpValue(TIMER_T *timer, uint32_t u32Value)
153{
154 timer->CMP = u32Value;
155}
156
164__STATIC_INLINE void TIMER_SetPrescaleValue(TIMER_T *timer, uint32_t u32Value)
165{
166 timer->CTL = (timer->CTL & ~TIMER_CTL_PSC_Msk) | u32Value;
167}
168
179__STATIC_INLINE void TIMER_SetCountingMode(TIMER_T *timer, TIMER_CntModeDef cntMode)
180{
181 timer->CTL = (timer->CTL & ~TIMER_CTL_OPMODE_Msk) | cntMode;
182}
183
191__STATIC_INLINE bool TIMER_IsActive(TIMER_T *timer)
192{
193 return timer->CTL & TIMER_CTL_ACTSTS_Msk ? true : false;
194}
195
196
211__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
212{
213 timer->CTL |= TIMER_CTL_CNTEN_Msk;
214}
215
221__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
222{
223 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
224}
225
231__STATIC_INLINE void TIMER_Reset(TIMER_T *timer)
232{
233 timer->CTL |= TIMER_CTL_RSTCNT_Msk;
234}
235
242__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
243{
244 timer->CTL |= TIMER_CTL_WKEN_Msk;
245}
246
252__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
253{
254 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
255}
256
257
263__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
264{
265 timer->EXTCTL |= TIMER_EXTCTL_CAPDBEN_Msk;
266}
267
273__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
274{
275 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
276}
277
278
284__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
285{
286 timer->EXTCTL |= TIMER_EXTCTL_CNTDBEN_Msk;
287}
288
294__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
295{
296 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
297}
298
304__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
305{
306 timer->CTL |= TIMER_CTL_INTEN_Msk;
307}
308
314__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
315{
316 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
317}
318
324__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
325{
326 timer->EXTCTL |= TIMER_EXTCTL_CAPIEN_Msk;
327}
328
334__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
335{
336 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
337}
338
346__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
347{
348 return(timer->INTSTS & TIMER_INTSTS_TIF_Msk ? 1 : 0);
349}
350
356__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
357{
358 timer->INTSTS = TIMER_INTSTS_TIF_Msk;
359}
360
368__STATIC_INLINE uint32_t TIMER_GetTFFlag(TIMER_T *timer)
369{
370 return(timer->INTSTS & TIMER_INTSTS_TF_Msk ? 1 : 0);
371}
372
378__STATIC_INLINE void TIMER_ClearTFFlag(TIMER_T *timer)
379{
380 timer->INTSTS = TIMER_INTSTS_TF_Msk;
381}
382
390__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
391{
392 return timer->EINTSTS & TIMER_EINTSTS_CAPIF_Msk;
393}
394
400__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
401{
402 timer->EINTSTS = TIMER_EINTSTS_CAPIF_Msk;
403}
404
412__STATIC_INLINE uint32_t TIMER_GetCaptureFlag(TIMER_T *timer)
413{
414 return ((timer->EINTSTS & TIMER_EINTSTS_CAPF_Msk)? 1:0);
415}
416
422__STATIC_INLINE void TIMER_ClearCaptureFlag(TIMER_T *timer)
423{
424 timer->EINTSTS = TIMER_EINTSTS_CAPF_Msk;
425}
426
434__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
435{
436 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0);
437}
438
444__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
445{
446 timer->INTSTS = TIMER_INTSTS_TWKF_Msk;
447}
448
457__STATIC_INLINE void TIMER_SetCaptureSource(TIMER_T *timer, TIMER_CapSrcDef capSrc)
458{
459 timer->CTL = (timer->CTL & ~TIMER_CTL_CAPSRC_Msk) | capSrc;
460}
461
467__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
468{
469 return timer->CAP;
470}
471
477__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
478{
479 return timer->CNT;
480}
481
488__STATIC_INLINE void TIMER_SetTmrCounterMode(TIMER_T *timer,uint32_t u32CntMode)
489{
490 timer->CTL &= ~(TIMER_CTL_OPMODE_Msk);
491 timer->CTL |= u32CntMode;
492}
493
509uint32_t TIMER_Open(TIMER_T *timer, TIMER_CntModeDef cntMode, uint32_t u32Freq);
510
516void TIMER_Close(TIMER_T *timer);
517
526void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
527
528
532#ifdef __cplusplus
533}
534#endif
535
536#endif /* __PAN_TIMER_H__ */
_TIMER_CapEdgeDef
Definition: pan_timer.h:57
enum _TIMER_CapEdgeDef TIMER_CapEdgeDef
@ TIMER_CAPTURE_BOTH_EDGE
Definition: pan_timer.h:60
@ TIMER_CAPTURE_RISING_THEN_FALLING_EDGE
Definition: pan_timer.h:62
@ TIMER_CAPTURE_FALLING_THEN_RISING_EDGE
Definition: pan_timer.h:61
@ TIMER_CAPTURE_FALLING_EDGE
Definition: pan_timer.h:58
@ TIMER_CAPTURE_RISING_EDGE
Definition: pan_timer.h:59
_TIMER_CapSrcDef
Definition: pan_timer.h:81
enum _TIMER_CapSrcDef TIMER_CapSrcDef
@ TIMER_CAPTURE_SOURCE_EXT_PIN
Definition: pan_timer.h:82
@ TIMER_CAPTURE_SOURCE_32K_OUTPUT
Definition: pan_timer.h:83
enum _TIMER_EvtCntEdgeDef TIMER_EvtCntEdgeDef
_TIMER_EvtCntEdgeDef
Definition: pan_timer.h:70
@ TIMER_COUNTER_RISING_EDGE
Definition: pan_timer.h:72
@ TIMER_COUNTER_FALLING_EDGE
Definition: pan_timer.h:71
enum _TIMER_CapModeDef TIMER_CapModeDef
_TIMER_CapModeDef
Definition: pan_timer.h:46
@ TIMER_CAPTURE_COUNTER_RESET_MODE
Definition: pan_timer.h:49
@ TIMER_CAPTURE_FREE_COUNTING_MODE
Definition: pan_timer.h:47
@ TIMER_CAPTURE_TRIGGER_COUNTING_MODE
Definition: pan_timer.h:48
enum _TIMER_CntModeDef TIMER_CntModeDef
_TIMER_CntModeDef
Definition: pan_timer.h:34
@ TIMER_TOGGLE_MODE
Definition: pan_timer.h:37
@ TIMER_CONTINUOUS_MODE
Definition: pan_timer.h:38
@ TIMER_ONESHOT_MODE
Definition: pan_timer.h:35
@ TIMER_PERIODIC_MODE
Definition: pan_timer.h:36
__STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
This function gets the Timer capture data.
Definition: pan_timer.h:467
void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec)
This API is used to create a delay loop for u32usec micro seconds.
__STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
This function reports the current timer counter value.
Definition: pan_timer.h:477
__STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
This function clears the Timer time-out interrupt flag.
Definition: pan_timer.h:356
__STATIC_INLINE void TIMER_Start(TIMER_T *timer)
This function is used to start Timer counting.
Definition: pan_timer.h:211
__STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
This function is used to disable the capture pin detection de-bounce function.
Definition: pan_timer.h:273
__STATIC_INLINE void TIMER_EnableCapture(TIMER_T *timer, TIMER_CapModeDef capMode, TIMER_CapEdgeDef capEdge)
This API is used to enable timer capture function with specified mode and capture edge.
Definition: pan_timer.h:102
__STATIC_INLINE void TIMER_DisableEventCounter(TIMER_T *timer)
This API is used to disable the Timer event counter function.
Definition: pan_timer.h:141
__STATIC_INLINE void TIMER_SetTmrCounterMode(TIMER_T *timer, uint32_t u32CntMode)
This function set the timer counter mode.
Definition: pan_timer.h:488
__STATIC_INLINE void TIMER_SetCountingMode(TIMER_T *timer, TIMER_CntModeDef cntMode)
This function is used to Set Timer counting mode.
Definition: pan_timer.h:179
__STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
This function is used to stop Timer counting.
Definition: pan_timer.h:221
__STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
This function is used to enable the counter pin detection de-bounce function.
Definition: pan_timer.h:284
__STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
This function indicates Timer capture interrupt occurred or not.
Definition: pan_timer.h:390
__STATIC_INLINE void TIMER_SetCaptureSource(TIMER_T *timer, TIMER_CapSrcDef capSrc)
This function set the Timer capture source.
Definition: pan_timer.h:457
__STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
This function clears the Timer capture interrupt flag.
Definition: pan_timer.h:400
__STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
This function indicates Timer has waked up system or not.
Definition: pan_timer.h:434
__STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
This function is used to disable the Timer time-out interrupt function.
Definition: pan_timer.h:314
__STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
This function is used to enable the Timer time-out interrupt function.
Definition: pan_timer.h:304
__STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
This function is used to disable the Timer wake-up function.
Definition: pan_timer.h:252
__STATIC_INLINE void TIMER_SetPrescaleValue(TIMER_T *timer, uint32_t u32Value)
This function is used to set new Timer prescale value.
Definition: pan_timer.h:164
void TIMER_Close(TIMER_T *timer)
This API stops Timer counting and disable the Timer interrupt function.
__STATIC_INLINE void TIMER_DisableCapture(TIMER_T *timer)
This API is used to disable the Timer capture function.
Definition: pan_timer.h:116
__STATIC_INLINE bool TIMER_IsActive(TIMER_T *timer)
This function is used to check if specify Timer is inactive or active.
Definition: pan_timer.h:191
__STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
This function is used to disable the counter pin detection de-bounce function.
Definition: pan_timer.h:294
__STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
This function is used to enable the capture pin detection de-bounce function.
Definition: pan_timer.h:263
__STATIC_INLINE uint32_t TIMER_GetTFFlag(TIMER_T *timer)
This function indicates Timer time-out event occurred or not.
Definition: pan_timer.h:368
__STATIC_INLINE void TIMER_SetCmpValue(TIMER_T *timer, uint32_t u32Value)
This function is used to set new Timer compared value.
Definition: pan_timer.h:152
__STATIC_INLINE void TIMER_ClearCaptureFlag(TIMER_T *timer)
This function clears the Timer capture event flag.
Definition: pan_timer.h:422
__STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
This function is used to disable the Timer capture trigger interrupt function.
Definition: pan_timer.h:334
uint32_t TIMER_Open(TIMER_T *timer, TIMER_CntModeDef cntMode, uint32_t u32Freq)
This API is used to configure timer to operate in specified mode and frequency. If timer cannot work ...
__STATIC_INLINE void TIMER_Reset(TIMER_T *timer)
This function is used to reset Timer counting, prescale counter and CNTEN.
Definition: pan_timer.h:231
__STATIC_INLINE uint32_t TIMER_GetCaptureFlag(TIMER_T *timer)
This function indicates Timer capture event occurred or not.
Definition: pan_timer.h:412
__STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
This function is used to enable the Timer capture trigger interrupt function.
Definition: pan_timer.h:324
__STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
This function is used to enable the Timer wake-up function.
Definition: pan_timer.h:242
__STATIC_INLINE void TIMER_ClearTFFlag(TIMER_T *timer)
This function clears the Timer time-out evnet flag.
Definition: pan_timer.h:378
__STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
This function indicates Timer time-out interrupt occurred or not.
Definition: pan_timer.h:346
__STATIC_INLINE void TIMER_EnableEventCounter(TIMER_T *timer, TIMER_EvtCntEdgeDef evtCntEdge)
This function is used to enable the Timer event counter function with specify detection edge.
Definition: pan_timer.h:130
__STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
This function clears the Timer wakeup interrupt flag.
Definition: pan_timer.h:444