1 /**************************************************************************//**
2 * @file lptmr.h
3 * @version V1.00
4 * @brief LPTMR Controller (Low Power Timer) driver header file
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 * @copyright (C) 2023 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #ifndef __LPTMR_H__
10 #define __LPTMR_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
18 /** @addtogroup Standard_Driver Standard Driver
19 @{
20 */
21
22 /** @addtogroup LPTMR_Driver LPTMR Driver
23 @{
24 */
25
26 /** @addtogroup LPTMR_EXPORTED_CONSTANTS LPTMR Exported Constants
27 @{
28 */
29 /*---------------------------------------------------------------------------------------------------------*/
30 /* LPTMR Operation Mode, External Counter and Capture Mode Constant Definitions */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define LPTMR_ONESHOT_MODE (0UL << LPTMR_CTL_OPMODE_Pos) /*!< LPTMR working in one-shot mode \hideinitializer */
33 #define LPTMR_PERIODIC_MODE (1UL << LPTMR_CTL_OPMODE_Pos) /*!< LPTMR working in periodic mode \hideinitializer */
34 #define LPTMR_TOGGLE_MODE (2UL << LPTMR_CTL_OPMODE_Pos) /*!< LPTMR working in toggle-output mode \hideinitializer */
35 #define LPTMR_CONTINUOUS_MODE (3UL << LPTMR_CTL_OPMODE_Pos) /*!< LPTMR working in continuous counting mode \hideinitializer */
36
37 #define LPTMR_TOUT_PIN_FROM_TMX (0UL << LPTMR_CTL_TGLPINSEL_Pos) /*!< LPTMR toggle-output pin is from TMx pin \hideinitializer */
38 #define LPTMR_TOUT_PIN_FROM_TMX_EXT (1UL << LPTMR_CTL_TGLPINSEL_Pos) /*!< LPTMR toggle-output pin is from TMx_EXT pin \hideinitializer */
39
40 #define LPTMR_COUNTER_EVENT_FALLING (0UL << LPTMR_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on falling edge detection \hideinitializer */
41 #define LPTMR_COUNTER_EVENT_RISING (1UL << LPTMR_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on rising edge detection \hideinitializer */
42
43 #define LPTMR_CAPTURE_FREE_COUNTING_MODE (0UL << LPTMR_EXTCTL_CAPFUNCS_Pos) /*!< LPTMR capture event to get lptmr counter value \hideinitializer */
44 #define LPTMR_CAPTURE_COUNTER_RESET_MODE (1UL << LPTMR_EXTCTL_CAPFUNCS_Pos) /*!< LPTMR capture event to reset lptmr counter \hideinitializer */
45
46 #define LPTMR_CAPTURE_EVENT_FALLING (0UL << LPTMR_EXTCTL_CAPEDGE_Pos) /*!< Falling edge detection to trigger capture event \hideinitializer */
47 #define LPTMR_CAPTURE_EVENT_RISING (1UL << LPTMR_EXTCTL_CAPEDGE_Pos) /*!< Rising edge detection to trigger capture event \hideinitializer */
48 #define LPTMR_CAPTURE_EVENT_FALLING_RISING (2UL << LPTMR_EXTCTL_CAPEDGE_Pos) /*!< Both falling and rising edge detection to trigger capture event, and first event at falling edge \hideinitializer */
49 #define LPTMR_CAPTURE_EVENT_RISING_FALLING (3UL << LPTMR_EXTCTL_CAPEDGE_Pos) /*!< Both rising and falling edge detection to trigger capture event, and first event at rising edge \hideinitializer */
50 #define LPTMR_CAPTURE_EVENT_GET_LOW_PERIOD (6UL << LPTMR_EXTCTL_CAPEDGE_Pos) /*!< First capture event is at falling edge, follows are at at rising edge \hideinitializer */
51 #define LPTMR_CAPTURE_EVENT_GET_HIGH_PERIOD (7UL << LPTMR_EXTCTL_CAPEDGE_Pos) /*!< First capture event is at rising edge, follows are at at falling edge \hideinitializer */
52
53 #define LPTMR_CAPSRC_TMX_EXT (0UL << LPTMR_CTL_CAPSRC_Pos) /*!< Capture source from TMx_EXT pin \hideinitializer */
54 #define LPTMR_CAPSRC_INTERNAL (1UL << LPTMR_CTL_CAPSRC_Pos) /*!< Capture source from Internal event such as ACMP0/1/2 \hideinitializer */
55
56 #define LPTMR_INTERCAPSEL_ACMP0 (0UL << LPTMR_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event ACMP0 \hideinitializer */
57 #define LPTMR_INTERCAPSEL_ACMP1 (1UL << LPTMR_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event ACMP1 \hideinitializer */
58 #define LPTMR_INTERCAPSEL_ACMP2 (7UL << LPTMR_EXTCTL_INTERCAPSEL_Pos) /*!< Capture source from Internal event ACMP2 \hideinitializer */
59
60 #define LPTMR_CAPTURE_FROM_ACMP0 (LPTMR_INTERCAPSEL_ACMP0) /*!< Capture source from Internal event ACMP0 \hideinitializer */
61 #define LPTMR_CAPTURE_FROM_ACMP1 (LPTMR_INTERCAPSEL_ACMP1) /*!< Capture source from Internal event ACMP1 \hideinitializer */
62 #define LPTMR_CAPTURE_FROM_ACMP2 (LPTMR_INTERCAPSEL_ACMP2) /*!< Capture source from Internal event ACMP2 \hideinitializer */
63 #define LPTMR_CAPTURE_FROM_EXTERNAL (0xFFUL) /*!< Capture source from Tx_EXT pin \hideinitializer */
64
65 /* Event Counter Sourdce Selection */
66 #define LPTMR_EVENT_COUNTER_SOURCE_TMX (0UL << LPTMR_EXTCTL_ECNTSSEL_Pos) /*!< Event Counter source from external LPTMx (x= 0~1) pin \hideinitializer */
67 #define LPTMR_EVENT_COUNTER_SOURCE_ACMP0 (2UL << LPTMR_EXTCTL_ECNTSSEL_Pos) /*!< Event Counter source from internal ACMP0 output signal \hideinitializer */
68 #define LPTMR_EVENT_COUNTER_SOURCE_ACMP1 (3UL << LPTMR_EXTCTL_ECNTSSEL_Pos) /*!< Event Counter source from internal ACMP1 output signal \hideinitializer */
69 #define LPTMR_EVENT_COUNTER_SOURCE_ACMP2 (4UL << LPTMR_EXTCTL_ECNTSSEL_Pos) /*!< Event Counter source from internal ACMP2 output signal \hideinitializer */
70
71 #define LPTMR_TRGSRC_TIMEOUT_EVENT (0UL << LPTMR_TRGCTL_TRGSSEL_Pos) /*!< Select internal trigger source from lptmr time-out event \hideinitializer */
72 #define LPTMR_TRGSRC_CAPTURE_EVENT (1UL << LPTMR_TRGCTL_TRGSSEL_Pos) /*!< Select internal trigger source from lptmr capture event \hideinitializer */
73
74 #define LPTMR_TRGEN (LPTMR_TRGCTL_TRGEN_Msk) /*!< Each lptmr event to trigger Low Power IP \hideinitializer */
75 #define LPTMR_TRG_TO_LPPDMA (LPTMR_TRGCTL_TRGLPPDMA_Msk) /*!< Each lptmr event to trigger LPPDMA transfer \hideinitializer */
76
77 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_1 (0UL) /*!< Capture noise filter clock is PCLK divide by 1 \hideinitializer */
78 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_2 (1UL) /*!< Capture noise filter clock is PCLK divide by 2 \hideinitializer */
79 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_4 (2UL) /*!< Capture noise filter clock is PCLK divide by 4 \hideinitializer */
80 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_8 (3UL) /*!< Capture noise filter clock is PCLK divide by 8 \hideinitializer */
81 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_16 (4UL) /*!< Capture noise filter clock is PCLK divide by 16 \hideinitializer */
82 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_32 (5UL) /*!< Capture noise filter clock is PCLK divide by 32 \hideinitializer */
83 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_64 (6UL) /*!< Capture noise filter clock is PCLK divide by 64 \hideinitializer */
84 #define LPTMR_CAPTURE_NOISE_FILTER_PCLK_DIV_128 (7UL) /*!< Capture noise filter clock is PCLK divide by 128 \hideinitializer */
85
86 #define LPTMR_CMP_MAX_VALUE (0xFFFFFFUL) /*!< Max LPTMR compare value \hideinitializer */
87
88 #define LPTMR_TIMEOUT_ERR (-1L) /*!< LPTMR operation abort due to timeout error \hideinitializer */
89
90 /*@}*/ /* end of group LPTMR_EXPORTED_CONSTANTS */
91
92
93 /** @addtogroup LPTMR_EXPORTED_FUNCTIONS LPTMR Exported Functions
94 @{
95 */
96
97 /**
98 * @brief Set LPTMR Compared Value
99 *
100 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
101 * @param[in] u32Value LPTMR compare value. Valid values are between 2 to 0xFFFFFF.
102 *
103 * @return None
104 *
105 * @details This macro is used to set lptmr compared value to adjust lptmr time-out interval.
106 * @note 1. Never write 0x0 or 0x1 in this field, or the core will run into unknown state. \n
107 * 2. If update lptmr compared value in continuous counting mode, lptmr counter value will keep counting continuously. \n
108 * But if lptmr is operating at other modes, the lptmr up counter will restart counting and start from 0.
109 * \hideinitializer
110 */
111 #define LPTMR_SET_CMP_VALUE(lptmr, u32Value) ((lptmr)->CMP = (u32Value))
112
113 /**
114 * @brief Set LPTMR Prescale Value
115 *
116 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
117 * @param[in] u32Value LPTMR prescale value. Valid values are between 0 to 0xFF.
118 *
119 * @return None
120 *
121 * @details This macro is used to set lptmr prescale value and lptmr source clock will be divided by (prescale + 1) \n
122 * before it is fed into lptmr.
123 * \hideinitializer
124 */
125 #define LPTMR_SET_PRESCALE_VALUE(lptmr, u32Value) ((lptmr)->CTL = ((lptmr)->CTL & ~LPTMR_CTL_PSC_Msk) | (u32Value))
126
127 /**
128 * @brief Check specify LPTMR Status
129 *
130 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
131 *
132 * @retval 0 LPTMR 24-bit up counter is inactive
133 * @retval 1 LPTMR 24-bit up counter is active
134 *
135 * @details This macro is used to check if specify LPTMR counter is inactive or active.
136 * \hideinitializer
137 */
138 #define LPTMR_IS_ACTIVE(lptmr) (((lptmr)->CTL & LPTMR_CTL_ACTSTS_Msk)? 1 : 0)
139
140 /**
141 * @brief Select Toggle-output Pin
142 *
143 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
144 * @param[in] u32ToutSel Toggle-output pin selection, valid values are:
145 * - \ref LPTMR_TOUT_PIN_FROM_TMX
146 * - \ref LPTMR_TOUT_PIN_FROM_TMX_EXT
147 *
148 * @return None
149 *
150 * @details This macro is used to select lptmr toggle-output pin is output on TMx or TMx_EXT pin.
151 * \hideinitializer
152 */
153 #define LPTMR_SELECT_TOUT_PIN(lptmr, u32ToutSel) ((lptmr)->CTL = ((lptmr)->CTL & ~LPTMR_CTL_TGLPINSEL_Msk) | (u32ToutSel))
154
155 /**
156 * @brief Select LPTMR operating mode
157 *
158 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
159 * @param[in] u32OpMode Operation mode. Possible options are
160 * - \ref LPTMR_ONESHOT_MODE
161 * - \ref LPTMR_PERIODIC_MODE
162 * - \ref LPTMR_TOGGLE_MODE
163 * - \ref LPTMR_CONTINUOUS_MODE
164 *
165 * @return None
166 * \hideinitializer
167 */
168 #define LPTMR_SET_OPMODE(lptmr, u32OpMode) ((lptmr)->CTL = ((lptmr)->CTL & ~LPTMR_CTL_OPMODE_Msk) | (u32OpMode))
169
170 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
171 __STATIC_INLINE void LPTMR_Start(LPTMR_T *lptmr);
172 __STATIC_INLINE void LPTMR_Stop(LPTMR_T *lptmr);
173 __STATIC_INLINE void LPTMR_EnableWakeup(LPTMR_T *lptmr);
174 __STATIC_INLINE void LPTMR_DisableWakeup(LPTMR_T *lptmr);
175 __STATIC_INLINE void LPTMR_StartCapture(LPTMR_T *lptmr);
176 __STATIC_INLINE void LPTMR_StopCapture(LPTMR_T *lptmr);
177 __STATIC_INLINE void LPTMR_EnableCaptureDebounce(LPTMR_T *lptmr);
178 __STATIC_INLINE void LPTMR_DisableCaptureDebounce(LPTMR_T *lptmr);
179 __STATIC_INLINE void LPTMR_EnableEventCounterDebounce(LPTMR_T *lptmr);
180 __STATIC_INLINE void LPTMR_DisableEventCounterDebounce(LPTMR_T *lptmr);
181 __STATIC_INLINE void LPTMR_EnableInt(LPTMR_T *lptmr);
182 __STATIC_INLINE void LPTMR_DisableInt(LPTMR_T *lptmr);
183 __STATIC_INLINE void LPTMR_EnableCaptureInt(LPTMR_T *lptmr);
184 __STATIC_INLINE void LPTMR_DisableCaptureInt(LPTMR_T *lptmr);
185 __STATIC_INLINE uint32_t LPTMR_GetIntFlag(LPTMR_T *lptmr);
186 __STATIC_INLINE void LPTMR_ClearIntFlag(LPTMR_T *lptmr);
187 __STATIC_INLINE uint32_t LPTMR_GetCaptureIntFlag(LPTMR_T *lptmr);
188 __STATIC_INLINE uint32_t LPTMR_GetCaptureIntFlagOV(LPTMR_T *lptmr);
189 __STATIC_INLINE void LPTMR_ClearCaptureIntFlag(LPTMR_T *lptmr);
190 __STATIC_INLINE uint32_t LPTMR_GetWakeupFlag(LPTMR_T *lptmr);
191 __STATIC_INLINE void LPTMR_ClearWakeupFlag(LPTMR_T *lptmr);
192 __STATIC_INLINE uint32_t LPTMR_GetCaptureData(LPTMR_T *lptmr);
193 __STATIC_INLINE uint32_t LPTMR_GetCounter(LPTMR_T *lptmr);
194 __STATIC_INLINE void LPTMR_EnablePDCLK(LPTMR_T *lptmr);
195 __STATIC_INLINE void LPTMR_DisablePDCLK(LPTMR_T *lptmr);
196 __STATIC_INLINE void LPTMR_EventCounterSelect(LPTMR_T *lptmr, uint32_t u32Src);
197
198 /**
199 * @brief Start LPTMR Counting
200 *
201 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
202 *
203 * @return None
204 *
205 * @details This function is used to start LPTMR counting.
206 */
LPTMR_Start(LPTMR_T * lptmr)207 __STATIC_INLINE void LPTMR_Start(LPTMR_T *lptmr)
208 {
209 lptmr->CTL |= LPTMR_CTL_CNTEN_Msk;
210 }
211
212 /**
213 * @brief Stop LPTMR Counting
214 *
215 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
216 *
217 * @return None
218 *
219 * @details This function is used to stop/suspend LPTMR counting.
220 */
LPTMR_Stop(LPTMR_T * lptmr)221 __STATIC_INLINE void LPTMR_Stop(LPTMR_T *lptmr)
222 {
223 lptmr->CTL &= ~LPTMR_CTL_CNTEN_Msk;
224 }
225
226 /**
227 * @brief Enable LPTMR Interrupt Wake-up Function
228 *
229 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
230 *
231 * @return None
232 *
233 * @details This function is used to enable the lptmr interrupt wake-up function and interrupt source could be time-out interrupt, \n
234 * counter event interrupt or capture trigger interrupt.
235 * @note To wake the system from Power-down mode, lptmr clock source must be ether LXT or LIRC.
236 */
LPTMR_EnableWakeup(LPTMR_T * lptmr)237 __STATIC_INLINE void LPTMR_EnableWakeup(LPTMR_T *lptmr)
238 {
239 lptmr->CTL |= (LPTMR_CTL_WKEN_Msk | LPTMR_CTL_PDCLKEN_Msk);
240 }
241
242 /**
243 * @brief Disable LPTMR Wake-up Function
244 *
245 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
246 *
247 * @return None
248 *
249 * @details This function is used to disable the lptmr interrupt wake-up function.
250 */
LPTMR_DisableWakeup(LPTMR_T * lptmr)251 __STATIC_INLINE void LPTMR_DisableWakeup(LPTMR_T *lptmr)
252 {
253 lptmr->CTL &= ~LPTMR_CTL_WKEN_Msk;
254 }
255
256 /**
257 * @brief Start LPTMR Capture Function
258 *
259 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
260 *
261 * @return None
262 *
263 * @details This function is used to start LPTMR capture function.
264 */
LPTMR_StartCapture(LPTMR_T * lptmr)265 __STATIC_INLINE void LPTMR_StartCapture(LPTMR_T *lptmr)
266 {
267 lptmr->EXTCTL |= LPTMR_EXTCTL_CAPEN_Msk;
268 }
269
270 /**
271 * @brief Stop LPTMR Capture Function
272 *
273 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
274 *
275 * @return None
276 *
277 * @details This function is used to stop LPTMR capture function.
278 */
LPTMR_StopCapture(LPTMR_T * lptmr)279 __STATIC_INLINE void LPTMR_StopCapture(LPTMR_T *lptmr)
280 {
281 lptmr->EXTCTL &= ~LPTMR_EXTCTL_CAPEN_Msk;
282 }
283
284 /**
285 * @brief Enable Capture Pin De-bounce
286 *
287 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
288 *
289 * @return None
290 *
291 * @details This function is used to enable the detect de-bounce function of capture pin.
292 */
LPTMR_EnableCaptureDebounce(LPTMR_T * lptmr)293 __STATIC_INLINE void LPTMR_EnableCaptureDebounce(LPTMR_T *lptmr)
294 {
295 lptmr->EXTCTL |= LPTMR_EXTCTL_CAPDBEN_Msk;
296 }
297
298 /**
299 * @brief Disable Capture Pin De-bounce
300 *
301 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
302 *
303 * @return None
304 *
305 * @details This function is used to disable the detect de-bounce function of capture pin.
306 */
LPTMR_DisableCaptureDebounce(LPTMR_T * lptmr)307 __STATIC_INLINE void LPTMR_DisableCaptureDebounce(LPTMR_T *lptmr)
308 {
309 lptmr->EXTCTL &= ~LPTMR_EXTCTL_CAPDBEN_Msk;
310 }
311
312 /**
313 * @brief Enable Counter Pin De-bounce
314 *
315 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
316 *
317 * @return None
318 *
319 * @details This function is used to enable the detect de-bounce function of counter pin.
320 */
LPTMR_EnableEventCounterDebounce(LPTMR_T * lptmr)321 __STATIC_INLINE void LPTMR_EnableEventCounterDebounce(LPTMR_T *lptmr)
322 {
323 lptmr->EXTCTL |= LPTMR_EXTCTL_CNTDBEN_Msk;
324 }
325
326 /**
327 * @brief Disable Counter Pin De-bounce
328 *
329 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
330 *
331 * @return None
332 *
333 * @details This function is used to disable the detect de-bounce function of counter pin.
334 */
LPTMR_DisableEventCounterDebounce(LPTMR_T * lptmr)335 __STATIC_INLINE void LPTMR_DisableEventCounterDebounce(LPTMR_T *lptmr)
336 {
337 lptmr->EXTCTL &= ~LPTMR_EXTCTL_CNTDBEN_Msk;
338 }
339
340 /**
341 * @brief Enable LPTMR Time-out Interrupt
342 *
343 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
344 *
345 * @return None
346 *
347 * @details This function is used to enable the lptmr time-out interrupt function.
348 */
LPTMR_EnableInt(LPTMR_T * lptmr)349 __STATIC_INLINE void LPTMR_EnableInt(LPTMR_T *lptmr)
350 {
351 lptmr->CTL |= LPTMR_CTL_INTEN_Msk;
352 }
353
354 /**
355 * @brief Disable LPTMR Time-out Interrupt
356 *
357 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
358 *
359 * @return None
360 *
361 * @details This function is used to disable the lptmr time-out interrupt function.
362 */
LPTMR_DisableInt(LPTMR_T * lptmr)363 __STATIC_INLINE void LPTMR_DisableInt(LPTMR_T *lptmr)
364 {
365 lptmr->CTL &= ~LPTMR_CTL_INTEN_Msk;
366 }
367
368 /**
369 * @brief Enable Capture Trigger Interrupt
370 *
371 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
372 *
373 * @return None
374 *
375 * @details This function is used to enable the lptmr capture trigger interrupt function.
376 */
LPTMR_EnableCaptureInt(LPTMR_T * lptmr)377 __STATIC_INLINE void LPTMR_EnableCaptureInt(LPTMR_T *lptmr)
378 {
379 lptmr->EXTCTL |= LPTMR_EXTCTL_CAPIEN_Msk;
380 }
381
382 /**
383 * @brief Disable Capture Trigger Interrupt
384 *
385 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
386 *
387 * @return None
388 *
389 * @details This function is used to disable the lptmr capture trigger interrupt function.
390 */
LPTMR_DisableCaptureInt(LPTMR_T * lptmr)391 __STATIC_INLINE void LPTMR_DisableCaptureInt(LPTMR_T *lptmr)
392 {
393 lptmr->EXTCTL &= ~LPTMR_EXTCTL_CAPIEN_Msk;
394 }
395
396 /**
397 * @brief Get LPTMR Time-out Interrupt Flag
398 *
399 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
400 *
401 * @retval 0 LPTMR time-out interrupt did not occur
402 * @retval 1 LPTMR time-out interrupt occurred
403 *
404 * @details This function indicates lptmr time-out interrupt occurred or not.
405 */
LPTMR_GetIntFlag(LPTMR_T * lptmr)406 __STATIC_INLINE uint32_t LPTMR_GetIntFlag(LPTMR_T *lptmr)
407 {
408 return ((lptmr->INTSTS & LPTMR_INTSTS_TIF_Msk) ? 1UL : 0UL);
409 }
410
411 /**
412 * @brief Clear LPTMR Time-out Interrupt Flag
413 *
414 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
415 *
416 * @return None
417 *
418 * @details This function clears lptmr time-out interrupt flag to 0.
419 */
LPTMR_ClearIntFlag(LPTMR_T * lptmr)420 __STATIC_INLINE void LPTMR_ClearIntFlag(LPTMR_T *lptmr)
421 {
422 lptmr->INTSTS = LPTMR_INTSTS_TIF_Msk;
423 }
424
425 /**
426 * @brief Get LPTMR Capture Interrupt Flag
427 *
428 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
429 *
430 * @retval 0 LPTMR capture interrupt did not occur
431 * @retval 1 LPTMR capture interrupt occurred
432 *
433 * @details This function indicates lptmr capture trigger interrupt occurred or not.
434 */
LPTMR_GetCaptureIntFlag(LPTMR_T * lptmr)435 __STATIC_INLINE uint32_t LPTMR_GetCaptureIntFlag(LPTMR_T *lptmr)
436 {
437 return ((lptmr->EINTSTS & LPTMR_EINTSTS_CAPIF_Msk) ? 1UL : 0UL);
438 }
439
440 /**
441 * @brief Get LPTMR Capture Interrupt Flag Overrun Status
442 *
443 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
444 *
445 * @retval 0 LPTMR capture interrupt did not overrun
446 * @retval 1 LPTMR capture interrupt overrun
447 *
448 * @details This function indicates lptmr capture trigger interrupt overrun or not.
449 */
LPTMR_GetCaptureIntFlagOV(LPTMR_T * lptmr)450 __STATIC_INLINE uint32_t LPTMR_GetCaptureIntFlagOV(LPTMR_T *lptmr)
451 {
452 return ((lptmr->EINTSTS & LPTMR_EINTSTS_CAPIFOV_Msk) ? 1UL : 0UL);
453 }
454
455 /**
456 * @brief Clear LPTMR Capture Interrupt Flag
457 *
458 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
459 *
460 * @return None
461 *
462 * @details This function clears lptmr capture trigger interrupt flag to 0.
463 */
LPTMR_ClearCaptureIntFlag(LPTMR_T * lptmr)464 __STATIC_INLINE void LPTMR_ClearCaptureIntFlag(LPTMR_T *lptmr)
465 {
466 lptmr->EINTSTS = LPTMR_EINTSTS_CAPIF_Msk;
467 }
468
469 /**
470 * @brief Get LPTMR Wake-up Flag
471 *
472 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
473 *
474 * @retval 0 LPTMR does not cause CPU wake-up
475 * @retval 1 LPTMR interrupt event cause CPU wake-up
476 *
477 * @details This function indicates lptmr interrupt event has waked up system or not.
478 */
LPTMR_GetWakeupFlag(LPTMR_T * lptmr)479 __STATIC_INLINE uint32_t LPTMR_GetWakeupFlag(LPTMR_T *lptmr)
480 {
481 return (lptmr->INTSTS & LPTMR_INTSTS_TWKF_Msk ? 1UL : 0UL);
482 }
483
484 /**
485 * @brief Clear LPTMR Wake-up Flag
486 *
487 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
488 *
489 * @return None
490 *
491 * @details This function clears the lptmr wake-up system flag to 0.
492 */
LPTMR_ClearWakeupFlag(LPTMR_T * lptmr)493 __STATIC_INLINE void LPTMR_ClearWakeupFlag(LPTMR_T *lptmr)
494 {
495 lptmr->INTSTS = LPTMR_INTSTS_TWKF_Msk;
496 }
497
498 /**
499 * @brief Get Capture value
500 *
501 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
502 *
503 * @return 24-bit Capture Value
504 *
505 * @details This function reports the current 24-bit lptmr capture value.
506 */
LPTMR_GetCaptureData(LPTMR_T * lptmr)507 __STATIC_INLINE uint32_t LPTMR_GetCaptureData(LPTMR_T *lptmr)
508 {
509 return lptmr->CAP;
510 }
511
512 /**
513 * @brief Get Counter value
514 *
515 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
516 *
517 * @return 24-bit Counter Value
518 *
519 * @details This function reports the current 24-bit lptmr counter value.
520 */
LPTMR_GetCounter(LPTMR_T * lptmr)521 __STATIC_INLINE uint32_t LPTMR_GetCounter(LPTMR_T *lptmr)
522 {
523 return lptmr->CNT;
524 }
525
526 /**
527 * @brief Enable LPTMR Power-down Engine Clock
528 *
529 * @param[in] lptmr The pointer of the specified lptmr module. It could be LPTMR0, LPTMR1.
530 *
531 * @return None
532 *
533 * @details This function is used to enable the lptmr Power-down Engine Clock.
534 */
LPTMR_EnablePDCLK(LPTMR_T * lptmr)535 __STATIC_INLINE void LPTMR_EnablePDCLK(LPTMR_T *lptmr)
536 {
537 lptmr->CTL |= LPTMR_CTL_PDCLKEN_Msk;
538 }
539
540 /**
541 * @brief Disable LPTMR Power-down Engine Clock
542 *
543 * @param[in] lptmr The pointer of the specified lptmr module. It could be LPTMR0, LPTMR1.
544 *
545 * @return None
546 *
547 * @details This function is used to disable the lptmr Power-down Engine Clock.
548 */
LPTMR_DisablePDCLK(LPTMR_T * lptmr)549 __STATIC_INLINE void LPTMR_DisablePDCLK(LPTMR_T *lptmr)
550 {
551 lptmr->CTL &= ~LPTMR_CTL_PDCLKEN_Msk;
552 }
553
554 /**
555 * @brief Select LPTMR Event Counter Source
556 *
557 * @param[in] lptmr The pointer of the specified LPTMR module. It could be LPTMR0, LPTMR1.
558 * @param[in] u32Src LPTMR Event Counter source. Possible values are
559 * - \ref LPTMR_EVENT_COUNTER_SOURCE_TMX
560 * - \ref LPTMR_EVENT_COUNTER_SOURCE_ACMP0
561 * - \ref LPTMR_EVENT_COUNTER_SOURCE_ACMP1
562 * - \ref LPTMR_EVENT_COUNTER_SOURCE_ACMP2
563 * @return None
564 *
565 * @details This API is used to select lptmr Event Counter source from LPTMx or internal singal.
566 */
LPTMR_EventCounterSelect(LPTMR_T * lptmr,uint32_t u32Src)567 __STATIC_INLINE void LPTMR_EventCounterSelect(LPTMR_T *lptmr, uint32_t u32Src)
568 {
569 lptmr->EXTCTL = (lptmr->EXTCTL & ~LPTMR_EXTCTL_ECNTSSEL_Msk) | u32Src;
570 }
571
572 uint32_t LPTMR_Open(LPTMR_T *lptmr, uint32_t u32Mode, uint32_t u32Freq);
573 void LPTMR_Close(LPTMR_T *lptmr);
574 int32_t LPTMR_Delay(LPTMR_T *lptmr, uint32_t u32Usec);
575 void LPTMR_EnableCapture(LPTMR_T *lptmr, uint32_t u32CapMode, uint32_t u32Edge);
576 void LPTMR_DisableCapture(LPTMR_T *lptmr);
577 void LPTMR_EnableEventCounter(LPTMR_T *lptmr, uint32_t u32Edge);
578 void LPTMR_DisableEventCounter(LPTMR_T *lptmr);
579 uint32_t LPTMR_GetModuleClock(LPTMR_T *lptmr);
580 void LPTMR_SetTriggerSource(LPTMR_T *lptmr, uint32_t u32Src);
581 void LPTMR_SetTriggerTarget(LPTMR_T *lptmr, uint32_t u32Mask);
582 void LPTMR_CaptureSelect(LPTMR_T *lptmr, uint32_t u32Src);
583 int32_t LPTMR_ResetCounter(LPTMR_T *lptmr);
584 void LPTMR_EnableCaptureInputNoiseFilter(LPTMR_T *lptmr, uint32_t u32FilterCount, uint32_t u32ClkSrcSel);
585 void LPTMR_DisableCaptureInputNoiseFilter(LPTMR_T *lptmr);
586
587 /*@}*/ /* end of group LPTMR_EXPORTED_FUNCTIONS */
588
589 /*@}*/ /* end of group LPTMR_Driver */
590
591 /*@}*/ /* end of group Standard_Driver */
592
593 #ifdef __cplusplus
594 }
595 #endif
596
597 #endif /* __LPTMR_H__ */
598