1 /**************************************************************************//**
2 * @file timer.h
3 * @version V1.00
4 * @brief Timer Controller driver header file
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 * @copyright (C) 2023 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #ifndef __TIMER_H__
10 #define __TIMER_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
18 /** @addtogroup Standard_Driver Standard Driver
19 @{
20 */
21
22 /** @addtogroup TIMER_Driver TIMER Driver
23 @{
24 */
25
26 /** @addtogroup TIMER_EXPORTED_CONSTANTS TIMER Exported Constants
27 @{
28 */
29 /*---------------------------------------------------------------------------------------------------------*/
30 /* TIMER Operation Mode, External Counter and Capture Mode Constant Definitions */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define TIMER_ONESHOT_MODE (0UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in one-shot mode \hideinitializer */
33 #define TIMER_PERIODIC_MODE (1UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in periodic mode \hideinitializer */
34 #define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in toggle-output mode \hideinitializer */
35 #define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in continuous counting mode \hideinitializer */
36
37 #define TIMER_TOUT_PIN_FROM_TMX (0UL << TIMER_CTL_TGLPINSEL_Pos) /*!< Timer toggle-output pin is from TMx pin \hideinitializer */
38 #define TIMER_TOUT_PIN_FROM_TMX_EXT (1UL << TIMER_CTL_TGLPINSEL_Pos) /*!< Timer toggle-output pin is from TMx_EXT pin \hideinitializer */
39
40 #define TIMER_COUNTER_EVENT_FALLING (0UL << TIMER_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on falling edge detection \hideinitializer */
41 #define TIMER_COUNTER_EVENT_RISING (1UL << TIMER_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on rising edge detection \hideinitializer */
42
43 #define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL << TIMER_EXTCTL_CAPFUNCS_Pos) /*!< Timer capture event to get timer counter value \hideinitializer */
44 #define TIMER_CAPTURE_COUNTER_RESET_MODE (1UL << TIMER_EXTCTL_CAPFUNCS_Pos) /*!< Timer capture event to reset timer counter \hideinitializer */
45
46 #define TIMER_CAPTURE_EVENT_FALLING (0UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Falling edge detection to trigger capture event \hideinitializer */
47 #define TIMER_CAPTURE_EVENT_RISING (1UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Rising edge detection to trigger capture event \hideinitializer */
48 #define TIMER_CAPTURE_EVENT_FALLING_RISING (2UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Both falling and rising edge detection to trigger capture event, and first event at falling edge \hideinitializer */
49 #define TIMER_CAPTURE_EVENT_RISING_FALLING (3UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Both rising and falling edge detection to trigger capture event, and first event at rising edge \hideinitializer */
50 #define TIMER_CAPTURE_EVENT_GET_LOW_PERIOD (6UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< First capture event is at falling edge, follows are at at rising edge \hideinitializer */
51 #define TIMER_CAPTURE_EVENT_GET_HIGH_PERIOD (7UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< First capture event is at rising edge, follows are at at falling edge \hideinitializer */
52
53 #define TIMER_CAPSRC_TX_EXT (0UL << TIMER_CTL_CAPSRC_Pos) /*!< Capture source from Tx_EXT pin \hideinitializer */
54 #define TIMER_CAPSRC_INTERNAL (1UL << TIMER_CTL_CAPSRC_Pos) /*!< Capture source from Internal event such as HXT/LXT/HIRC/LIRC/MIRC or ACMP0/1/2 \hideinitializer */
55
56 #define TIMER_INTERCAPSEL_ACMP0 (0UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event ACMP0 \hideinitializer */
57 #define TIMER_INTERCAPSEL_ACMP1 (1UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event ACMP1 \hideinitializer */
58 #define TIMER_INTERCAPSEL_HXT (2UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event HXT \hideinitializer */
59 #define TIMER_INTERCAPSEL_LXT (3UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event LXT \hideinitializer */
60 #define TIMER_INTERCAPSEL_HIRC (4UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event HIRC \hideinitializer */
61 #define TIMER_INTERCAPSEL_LIRC (5UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event LIRC \hideinitializer */
62 #define TIMER_INTERCAPSEL_MIRC (6UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event MIRC \hideinitializer */
63 #define TIMER_INTERCAPSEL_ACMP2 (7UL << TIMER_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event ACMP2 \hideinitializer */
64
65 #define TIMER_CAPTURE_FROM_ACMP0 (TIMER_INTERCAPSEL_ACMP0) /*!< Capture source from Internal event ACMP0 \hideinitializer */
66 #define TIMER_CAPTURE_FROM_ACMP1 (TIMER_INTERCAPSEL_ACMP1) /*!< Capture source from Internal event ACMP1 \hideinitializer */
67 #define TIMER_CAPTURE_FROM_HXT (TIMER_INTERCAPSEL_HXT) /*!< Capture source from Internal event HXT \hideinitializer */
68 #define TIMER_CAPTURE_FROM_LXT (TIMER_INTERCAPSEL_LXT) /*!< Capture source from Internal event LXT \hideinitializer */
69 #define TIMER_CAPTURE_FROM_HIRC (TIMER_INTERCAPSEL_HIRC) /*!< Capture source from Internal event HIRC \hideinitializer */
70 #define TIMER_CAPTURE_FROM_LIRC (TIMER_INTERCAPSEL_LIRC) /*!< Capture source from Internal event LIRC \hideinitializer */
71 #define TIMER_CAPTURE_FROM_MIRC (TIMER_INTERCAPSEL_MIRC) /*!< Capture source from Internal event MIRC \hideinitializer */
72 #define TIMER_CAPTURE_FROM_ACMP2 (TIMER_INTERCAPSEL_ACMP2) /*!< Capture source from Internal event ACMP2 \hideinitializer */
73 #define TIMER_CAPTURE_FROM_EXTERNAL (0xFFUL) /*!< Capture source from Tx_EXT pin \hideinitializer */
74
75 #define TIMER_TRGSRC_TIMEOUT_EVENT (0UL << TIMER_TRGCTL_TRGSSEL_Pos) /*!< Select internal trigger source from timer time-out event \hideinitializer */
76 #define TIMER_TRGSRC_CAPTURE_EVENT (1UL << TIMER_TRGCTL_TRGSSEL_Pos) /*!< Select internal trigger source from timer capture event \hideinitializer */
77
78 #define TIMER_TRG_TO_PWM (TIMER_TRGCTL_TRGPWM_Msk) /*!< Each timer event as PWM counter clock source \hideinitializer */
79 #define TIMER_TRG_TO_EADC (TIMER_TRGCTL_TRGEADC_Msk) /*!< Each timer event to start EADC conversion \hideinitializer */
80 #define TIMER_TRG_TO_DAC (TIMER_TRGCTL_TRGDAC_Msk) /*!< Each timer event to start DAC conversion \hideinitializer */
81 #define TIMER_TRG_TO_PDMA (TIMER_TRGCTL_TRGPDMA_Msk) /*!< Each timer event to trigger PDMA transfer \hideinitializer */
82 #define TIMER_TRG_TO_LPADC (TIMER_TRGCTL_TRGLPADC_Msk) /*!< Each timer event to trigger LPADC transfer \hideinitializer */
83 #define TIMER_TRG_TO_TK (TIMER_TRGCTL_TRGTK_Msk) /*!< Each timer event to trigger TK transfer \hideinitializer */
84
85 #define TIMER_CMP_MAX_VALUE (0xFFFFFFUL) /*!< Max Timer compare value \hideinitializer */
86
87 #define TIMER_TIMEOUT_ERR (-1L) /*!< TIMER operation abort due to timeout error \hideinitializer */
88
89 /*@}*/ /* end of group TIMER_EXPORTED_CONSTANTS */
90
91
92 /** @addtogroup TIMER_EXPORTED_FUNCTIONS TIMER Exported Functions
93 @{
94 */
95
96 /**
97 * @brief Set Timer Compared Value
98 *
99 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
100 * @param[in] u32Value Timer compare value. Valid values are between 2 to 0xFFFFFF.
101 *
102 * @return None
103 *
104 * @details This macro is used to set timer compared value to adjust timer time-out interval.
105 * @note 1. Never write 0x0 or 0x1 in this field, or the core will run into unknown state. \n
106 * 2. If update timer compared value in continuous counting mode, timer counter value will keep counting continuously. \n
107 * But if timer is operating at other modes, the timer up counter will restart counting and start from 0.
108 * \hideinitializer
109 */
110 #define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value))
111
112 /**
113 * @brief Set Timer Prescale Value
114 *
115 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
116 * @param[in] u32Value Timer prescale value. Valid values are between 0 to 0xFF.
117 *
118 * @return None
119 *
120 * @details This macro is used to set timer prescale value and timer source clock will be divided by (prescale + 1) \n
121 * before it is fed into timer.
122 * \hideinitializer
123 */
124 #define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value))
125
126 /**
127 * @brief Check specify Timer Status
128 *
129 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
130 *
131 * @retval 0 Timer 24-bit up counter is inactive
132 * @retval 1 Timer 24-bit up counter is active
133 *
134 * @details This macro is used to check if specify Timer counter is inactive or active.
135 * \hideinitializer
136 */
137 #define TIMER_IS_ACTIVE(timer) (((timer)->CTL & TIMER_CTL_ACTSTS_Msk) ? 1 : 0)
138
139 /**
140 * @brief Select Toggle-output Pin
141 *
142 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
143 * @param[in] u32ToutSel Toggle-output pin selection, valid values are:
144 * - \ref TIMER_TOUT_PIN_FROM_TMX
145 * - \ref TIMER_TOUT_PIN_FROM_TMX_EXT
146 *
147 * @return None
148 *
149 * @details This macro is used to select timer toggle-output pin is output on TMx or TMx_EXT pin.
150 * \hideinitializer
151 */
152 #define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel))
153
154 /**
155 * @brief Select Timer operating mode
156 *
157 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
158 * @param[in] u32OpMode Operation mode. Possible options are
159 * - \ref TIMER_ONESHOT_MODE
160 * - \ref TIMER_PERIODIC_MODE
161 * - \ref TIMER_TOGGLE_MODE
162 * - \ref TIMER_CONTINUOUS_MODE
163 *
164 * @return None
165 * \hideinitializer
166 */
167 #define TIMER_SET_OPMODE(timer, u32OpMode) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_OPMODE_Msk) | (u32OpMode))
168
169 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
170 __STATIC_INLINE void TIMER_Start(TIMER_T *timer);
171 __STATIC_INLINE void TIMER_Stop(TIMER_T *timer);
172 __STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer);
173 __STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer);
174 __STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer);
175 __STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer);
176 __STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer);
177 __STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer);
178 __STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer);
179 __STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer);
180 __STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer);
181 __STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer);
182 __STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer);
183 __STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer);
184 __STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer);
185 __STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer);
186 __STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer);
187 __STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer);
188 __STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer);
189 __STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer);
190 __STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer);
191 __STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer);
192
193 /**
194 * @brief Start Timer Counting
195 *
196 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
197 *
198 * @return None
199 *
200 * @details This function is used to start Timer counting.
201 */
TIMER_Start(TIMER_T * timer)202 __STATIC_INLINE void TIMER_Start(TIMER_T *timer)
203 {
204 timer->CTL |= TIMER_CTL_CNTEN_Msk;
205 }
206
207 /**
208 * @brief Stop Timer Counting
209 *
210 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
211 *
212 * @return None
213 *
214 * @details This function is used to stop/suspend Timer counting.
215 */
TIMER_Stop(TIMER_T * timer)216 __STATIC_INLINE void TIMER_Stop(TIMER_T *timer)
217 {
218 timer->CTL &= ~TIMER_CTL_CNTEN_Msk;
219 }
220
221 /**
222 * @brief Enable Timer Interrupt Wake-up Function
223 *
224 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
225 *
226 * @return None
227 *
228 * @details This function is used to enable the timer interrupt wake-up function and interrupt source could be time-out interrupt, \n
229 * counter event interrupt or capture trigger interrupt.
230 * @note To wake the system from Power-down mode, timer clock source must be ether LXT or LIRC.
231 */
TIMER_EnableWakeup(TIMER_T * timer)232 __STATIC_INLINE void TIMER_EnableWakeup(TIMER_T *timer)
233 {
234 timer->CTL |= TIMER_CTL_WKEN_Msk;
235 }
236
237 /**
238 * @brief Disable Timer Wake-up Function
239 *
240 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
241 *
242 * @return None
243 *
244 * @details This function is used to disable the timer interrupt wake-up function.
245 */
TIMER_DisableWakeup(TIMER_T * timer)246 __STATIC_INLINE void TIMER_DisableWakeup(TIMER_T *timer)
247 {
248 timer->CTL &= ~TIMER_CTL_WKEN_Msk;
249 }
250
251 /**
252 * @brief Start Timer Capture Function
253 *
254 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
255 *
256 * @return None
257 *
258 * @details This function is used to start Timer capture function.
259 */
TIMER_StartCapture(TIMER_T * timer)260 __STATIC_INLINE void TIMER_StartCapture(TIMER_T *timer)
261 {
262 timer->EXTCTL |= TIMER_EXTCTL_CAPEN_Msk;
263 }
264
265 /**
266 * @brief Stop Timer Capture Function
267 *
268 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
269 *
270 * @return None
271 *
272 * @details This function is used to stop Timer capture function.
273 */
TIMER_StopCapture(TIMER_T * timer)274 __STATIC_INLINE void TIMER_StopCapture(TIMER_T *timer)
275 {
276 timer->EXTCTL &= ~TIMER_EXTCTL_CAPEN_Msk;
277 }
278
279 /**
280 * @brief Enable Capture Pin De-bounce
281 *
282 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
283 *
284 * @return None
285 *
286 * @details This function is used to enable the detect de-bounce function of capture pin.
287 */
TIMER_EnableCaptureDebounce(TIMER_T * timer)288 __STATIC_INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer)
289 {
290 timer->EXTCTL |= TIMER_EXTCTL_CAPDBEN_Msk;
291 }
292
293 /**
294 * @brief Disable Capture Pin De-bounce
295 *
296 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
297 *
298 * @return None
299 *
300 * @details This function is used to disable the detect de-bounce function of capture pin.
301 */
TIMER_DisableCaptureDebounce(TIMER_T * timer)302 __STATIC_INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer)
303 {
304 timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk;
305 }
306
307 /**
308 * @brief Enable Counter Pin De-bounce
309 *
310 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
311 *
312 * @return None
313 *
314 * @details This function is used to enable the detect de-bounce function of counter pin.
315 */
TIMER_EnableEventCounterDebounce(TIMER_T * timer)316 __STATIC_INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer)
317 {
318 timer->EXTCTL |= TIMER_EXTCTL_CNTDBEN_Msk;
319 }
320
321 /**
322 * @brief Disable Counter Pin De-bounce
323 *
324 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
325 *
326 * @return None
327 *
328 * @details This function is used to disable the detect de-bounce function of counter pin.
329 */
TIMER_DisableEventCounterDebounce(TIMER_T * timer)330 __STATIC_INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer)
331 {
332 timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk;
333 }
334
335 /**
336 * @brief Enable Timer Time-out Interrupt
337 *
338 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
339 *
340 * @return None
341 *
342 * @details This function is used to enable the timer time-out interrupt function.
343 */
TIMER_EnableInt(TIMER_T * timer)344 __STATIC_INLINE void TIMER_EnableInt(TIMER_T *timer)
345 {
346 timer->CTL |= TIMER_CTL_INTEN_Msk;
347 }
348
349 /**
350 * @brief Disable Timer Time-out Interrupt
351 *
352 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
353 *
354 * @return None
355 *
356 * @details This function is used to disable the timer time-out interrupt function.
357 */
TIMER_DisableInt(TIMER_T * timer)358 __STATIC_INLINE void TIMER_DisableInt(TIMER_T *timer)
359 {
360 timer->CTL &= ~TIMER_CTL_INTEN_Msk;
361 }
362
363 /**
364 * @brief Enable Capture Trigger Interrupt
365 *
366 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
367 *
368 * @return None
369 *
370 * @details This function is used to enable the timer capture trigger interrupt function.
371 */
TIMER_EnableCaptureInt(TIMER_T * timer)372 __STATIC_INLINE void TIMER_EnableCaptureInt(TIMER_T *timer)
373 {
374 timer->EXTCTL |= TIMER_EXTCTL_CAPIEN_Msk;
375 }
376
377 /**
378 * @brief Disable Capture Trigger Interrupt
379 *
380 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
381 *
382 * @return None
383 *
384 * @details This function is used to disable the timer capture trigger interrupt function.
385 */
TIMER_DisableCaptureInt(TIMER_T * timer)386 __STATIC_INLINE void TIMER_DisableCaptureInt(TIMER_T *timer)
387 {
388 timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk;
389 }
390
391 /**
392 * @brief Get Timer Time-out Interrupt Flag
393 *
394 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
395 *
396 * @retval 0 Timer time-out interrupt did not occur
397 * @retval 1 Timer time-out interrupt occurred
398 *
399 * @details This function indicates timer time-out interrupt occurred or not.
400 */
TIMER_GetIntFlag(TIMER_T * timer)401 __STATIC_INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer)
402 {
403 return ((timer->INTSTS & TIMER_INTSTS_TIF_Msk) ? 1UL : 0UL);
404 }
405
406 /**
407 * @brief Clear Timer Time-out Interrupt Flag
408 *
409 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
410 *
411 * @return None
412 *
413 * @details This function clears timer time-out interrupt flag to 0.
414 */
TIMER_ClearIntFlag(TIMER_T * timer)415 __STATIC_INLINE void TIMER_ClearIntFlag(TIMER_T *timer)
416 {
417 timer->INTSTS = TIMER_INTSTS_TIF_Msk;
418 }
419
420 /**
421 * @brief Get Timer Capture Interrupt Flag
422 *
423 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
424 *
425 * @retval 0 Timer capture interrupt did not occur
426 * @retval 1 Timer capture interrupt occurred
427 *
428 * @details This function indicates timer capture trigger interrupt occurred or not.
429 */
TIMER_GetCaptureIntFlag(TIMER_T * timer)430 __STATIC_INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer)
431 {
432 return ((timer->EINTSTS & TIMER_EINTSTS_CAPIF_Msk) ? 1UL : 0UL);
433 }
434
435 /**
436 * @brief Clear Timer Capture Interrupt Flag
437 *
438 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
439 *
440 * @return None
441 *
442 * @details This function clears timer capture trigger interrupt flag to 0.
443 */
TIMER_ClearCaptureIntFlag(TIMER_T * timer)444 __STATIC_INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer)
445 {
446 timer->EINTSTS = TIMER_EINTSTS_CAPIF_Msk;
447 }
448
449 /**
450 * @brief Get Timer Wake-up Flag
451 *
452 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
453 *
454 * @retval 0 Timer does not cause CPU wake-up
455 * @retval 1 Timer interrupt event cause CPU wake-up
456 *
457 * @details This function indicates timer interrupt event has waked up system or not.
458 */
TIMER_GetWakeupFlag(TIMER_T * timer)459 __STATIC_INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer)
460 {
461 return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1UL : 0UL);
462 }
463
464 /**
465 * @brief Clear Timer Wake-up Flag
466 *
467 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
468 *
469 * @return None
470 *
471 * @details This function clears the timer wake-up system flag to 0.
472 */
TIMER_ClearWakeupFlag(TIMER_T * timer)473 __STATIC_INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer)
474 {
475 timer->INTSTS = TIMER_INTSTS_TWKF_Msk;
476 }
477
478 /**
479 * @brief Get Capture value
480 *
481 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
482 *
483 * @return 24-bit Capture Value
484 *
485 * @details This function reports the current 24-bit timer capture value.
486 */
TIMER_GetCaptureData(TIMER_T * timer)487 __STATIC_INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer)
488 {
489 return timer->CAP;
490 }
491
492 /**
493 * @brief Get Counter value
494 *
495 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
496 *
497 * @return 24-bit Counter Value
498 *
499 * @details This function reports the current 24-bit timer counter value.
500 */
TIMER_GetCounter(TIMER_T * timer)501 __STATIC_INLINE uint32_t TIMER_GetCounter(TIMER_T *timer)
502 {
503 return timer->CNT;
504 }
505
506
507 uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq);
508 void TIMER_Close(TIMER_T *timer);
509 int32_t TIMER_Delay(TIMER_T *timer, uint32_t u32Usec);
510 void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge);
511 void TIMER_DisableCapture(TIMER_T *timer);
512 void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge);
513 void TIMER_DisableEventCounter(TIMER_T *timer);
514 uint32_t TIMER_GetModuleClock(TIMER_T *timer);
515 void TIMER_EnableFreqCounter(TIMER_T *timer,
516 uint32_t u32DropCount,
517 uint32_t u32Timeout,
518 uint32_t u32EnableInt);
519 void TIMER_DisableFreqCounter(TIMER_T *timer);
520 void TIMER_SetTriggerSource(TIMER_T *timer, uint32_t u32Src);
521 void TIMER_SetTriggerTarget(TIMER_T *timer, uint32_t u32Mask);
522 void TIMER_CaptureSelect(TIMER_T *timer, uint32_t u32Src);
523 int32_t TIMER_ResetCounter(TIMER_T *timer);
524
525 /*@}*/ /* end of group TIMER_EXPORTED_FUNCTIONS */
526
527 /*@}*/ /* end of group TIMER_Driver */
528
529 /*@}*/ /* end of group Standard_Driver */
530
531 #ifdef __cplusplus
532 }
533 #endif
534
535 #endif /* __TIMER_H__ */
536