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