1 /*!
2     \file    gd32l23x_lptimer.c
3     \brief   LPTIMER driver
4 
5     \version 2021-08-04, V1.0.0, firmware for GD32L23x
6 */
7 
8 /*
9     Copyright (c) 2021, GigaDevice Semiconductor Inc.
10 
11     Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13 
14     1. Redistributions of source code must retain the above copyright notice, this
15        list of conditions and the following disclaimer.
16     2. Redistributions in binary form must reproduce the above copyright notice,
17        this list of conditions and the following disclaimer in the documentation
18        and/or other materials provided with the distribution.
19     3. Neither the name of the copyright holder nor the names of its contributors
20        may be used to endorse or promote products derived from this software without
21        specific prior written permission.
22 
23     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 OF SUCH DAMAGE.
33 */
34 
35 #include "gd32l23x_lptimer.h"
36 
37 /*!
38     \brief      deinit LPTIMER
39     \param[in]  none
40     \param[out] none
41     \retval     none
42 */
lptimer_deinit(void)43 void lptimer_deinit(void)
44 {
45     /* reset LPTIMER */
46     rcu_periph_reset_enable(RCU_LPTIMERRST);
47     rcu_periph_reset_disable(RCU_LPTIMERRST);
48 }
49 
50 /*!
51     \brief      initialize LPTIMER init parameter struct with a default value
52     \param[in]  initpara: init parameter struct
53     \param[out] none
54     \retval     none
55 */
lptimer_struct_para_init(lptimer_parameter_struct * initpara)56 void lptimer_struct_para_init(lptimer_parameter_struct *initpara)
57 {
58     /* initialize the init parameter struct member with the default value */
59     initpara->clocksource      = LPTIMER_INTERNALCLK;
60     initpara->prescaler        = LPTIMER_PSC_1;
61     initpara->extclockpolarity = LPTIMER_EXTERNALCLK_RISING;
62     initpara->extclockfilter   = LPTIMER_EXTERNALCLK_FILTEROFF;
63     initpara->triggermode      = LPTIMER_TRIGGER_SOFTWARE;
64     initpara->extriggersource  = LPTIMER_EXTRIGGER_GPIO;
65     initpara->extriggerfilter  = LPTIMER_TRIGGER_FILTEROFF;
66     initpara->outputpolarity   = LPTIMER_OUTPUT_NOTINVERTED;
67     initpara->outputmode       = LPTIMER_OUTPUT_PWMORSINGLE;
68     initpara->countersource    = LPTIMER_COUNTER_INTERNAL;
69 }
70 
71 /*!
72     \brief      initialize LPTIMER counter
73     \param[in]  initpara: init parameter struct
74                   clocksource: LPTIMER_INTERNALCLK, LPTIMER_EXTERNALCLK
75                   prescaler: prescaler value of the counter clock, LPTIMER_PSC_x(x=1,2,4,8..128)
76                   extclockpolarity: LPTIMER_EXTERNALCLK_RISING, LPTIMER_EXTERNALCLK_FALLING, LPTIMER_EXTERNALCLK_BOTH
77                   extclockfilter: LPTIMER_EXTERNALCLK_FILTEROFF, LPTIMER_EXTERNALCLK_FILTER_2, LPTIMER_EXTERNALCLK_FILTER_4, LPTIMER_EXTERNALCLK_FILTER_8
78                   triggermode: LPTIMER_TRIGGER_SOFTWARE, LPTIMER_TRIGGER_EXTERNALRISING, LPTIMER_TRIGGER_EXTERNALFALLING, LPTIMER_TRIGGER_EXTERNALBOTH
79                   extriggersource: LPTIMER_EXTRIGGER_GPIO, LPTIMER_EXTRIGGER_RTCALARM0, LPTIMER_EXTRIGGER_RTCALARM1, LPTIMER_EXTRIGGER_RTCTAMP0, LPTIMER_EXTRIGGER_RTCTAMP1,
80                                    LPTIMER_EXTRIGGER_RTCTAMP2, LPTIMER_EXTRIGGER_CMP0_OUT, LPTIMER_EXTRIGGER_CMP1_OUT
81                   extriggerfilter: LPTIMER_TRIGGER_FILTEROFF, LPTIMER_TRIGGER_FILTER_2, LPTIMER_TRIGGER_FILTER_4, LPTIMER_TRIGGER_FILTER_8
82                   outputpolarity: LPTIMER_OUTPUT_NOTINVERTED, LPTIMER_OUTPUT_INVERTED
83                   outputmode: LPTIMER_OUTPUT_PWMORSINGLE, LPTIMER_OUTPUT_SET
84                   countersource: LPTIMER_COUNTER_INTERNAL, LPTIMER_COUNTER_EXTERNAL
85     \param[out] none
86     \retval     none
87 */
lptimer_init(lptimer_parameter_struct * initpara)88 void lptimer_init(lptimer_parameter_struct *initpara)
89 {
90     LPTIMER_CTL0 = initpara->clocksource | initpara->prescaler | initpara->triggermode | \
91                    initpara->outputpolarity | initpara->outputmode | initpara->countersource;
92 
93     if(initpara->triggermode != LPTIMER_TRIGGER_SOFTWARE) {
94         LPTIMER_CTL0 |= initpara->extriggersource | initpara->extriggerfilter;
95     }
96 
97     if((initpara->clocksource == LPTIMER_EXTERNALCLK) || (initpara->countersource == LPTIMER_COUNTER_EXTERNAL)) {
98         LPTIMER_CTL0 |= initpara->extclockpolarity | initpara->extclockfilter;
99     }
100 
101     if((initpara->clocksource == LPTIMER_INTERNALCLK) && (initpara->countersource == LPTIMER_COUNTER_EXTERNAL)) {
102         LPTIMER_CTL0 &= ~LPTIMER_CTL0_PSC;
103     }
104 }
105 
106 /*!
107     \brief      configure external input remap
108     \param[in]  input0remap: external input0 remap
109                 only one parameter can be selected which is shown as below:
110       \arg        LPTIMER_INPUT0_GPIO
111       \arg        LPTIMER_INPUT0_CMP0_OUT
112     \param[in]  input1remap: external input1 remap
113                 only one parameter can be selected which is shown as below:
114       \arg        LPTIMER_INPUT1_GPIO
115       \arg        LPTIMER_INPUT1_CMP1_OUT
116     \param[out] none
117     \retval     none
118 */
lptimer_inputremap(uint32_t input0remap,uint32_t input1remap)119 void lptimer_inputremap(uint32_t input0remap, uint32_t input1remap)
120 {
121     LPTIMER_EIRMP = (uint32_t)(input0remap | input1remap);
122 }
123 
124 /*!
125     \brief      enable the LPTIMER_CAR and LPTIMER_CMPV registers shadow function
126     \param[in]  none
127     \param[out] none
128     \retval     none
129 */
lptimer_register_shadow_enable(void)130 void lptimer_register_shadow_enable(void)
131 {
132     LPTIMER_CTL0 |= (uint32_t)LPTIMER_CTL0_SHWEN;
133 }
134 
135 /*!
136     \brief      disable the LPTIMER_CAR and LPTIMER_CMPV registers shadow function
137     \param[in]  none
138     \param[out] none
139     \retval     none
140 */
lptimer_register_shadow_disable(void)141 void lptimer_register_shadow_disable(void)
142 {
143     LPTIMER_CTL0 &= ~(uint32_t)LPTIMER_CTL0_SHWEN;
144 }
145 
146 /*!
147     \brief      enable the LPTIMER TIMEOUT function
148     \param[in]  none
149     \param[out] none
150     \retval     none
151 */
lptimer_timeout_enable(void)152 void lptimer_timeout_enable(void)
153 {
154     LPTIMER_CTL0 |= (uint32_t)LPTIMER_CTL0_TIMEOUT;
155 }
156 
157 /*!
158     \brief      disable the LPTIMER TIMEOUT function
159     \param[in]  none
160     \param[out] none
161     \retval     none
162 */
lptimer_timeout_disable(void)163 void lptimer_timeout_disable(void)
164 {
165     LPTIMER_CTL0 &= ~(uint32_t)LPTIMER_CTL0_TIMEOUT;
166 }
167 
168 /*!
169     \brief      LPTIMER countinue start
170     \param[in]  autoreload: auto reload value, 0x0~0xffffffff
171     \param[in]  compare: compare value, 0x0~0xffffffff
172     \param[out] none
173     \retval     none
174 */
lptimer_countinue_start(uint32_t autoreload,uint32_t compare)175 void lptimer_countinue_start(uint32_t autoreload, uint32_t compare)
176 {
177     LPTIMER_INTC |= (uint32_t)(LPTIMER_INTC_CMPVUPIC | LPTIMER_INTC_CARUPIC);
178     LPTIMER_CTL1 |= (uint32_t)LPTIMER_CTL1_LPTEN;
179 
180     while(0U == (LPTIMER_CTL1 & LPTIMER_CTL1_LPTENF)) {
181     }
182     LPTIMER_CAR = autoreload;
183     LPTIMER_CMPV = compare;
184     while(0U == (LPTIMER_INTF & LPTIMER_INTF_CARUPIF)) {
185     }
186     while(0U == (LPTIMER_INTF & LPTIMER_INTF_CMPVUPIF)) {
187     }
188     LPTIMER_INTC = LPTIMER_INTC_CMPVUPIC | LPTIMER_INTC_CARUPIC;
189     LPTIMER_CTL1 |= LPTIMER_CTL1_CTNMST;
190 }
191 
192 /*!
193     \brief      LPTIMER single start
194     \param[in]  autoreload: auto reload value, 0x0~0xffffffff
195     \param[in]  compare: compare value, 0x0~0xffffffff
196     \param[out] none
197     \retval     none
198 */
lptimer_single_start(uint32_t autoreload,uint32_t compare)199 void lptimer_single_start(uint32_t autoreload, uint32_t compare)
200 {
201     LPTIMER_INTC |= (uint32_t)(LPTIMER_INTC_CMPVUPIC | LPTIMER_INTC_CARUPIC);
202     LPTIMER_CTL1 |= (uint32_t)LPTIMER_CTL1_LPTEN;
203 
204     while(0U == (LPTIMER_CTL1 & LPTIMER_CTL1_LPTENF)) {
205     }
206     LPTIMER_CAR = autoreload;
207     LPTIMER_CMPV = compare;
208     while(0U == (LPTIMER_INTF & LPTIMER_INTF_CARUPIF)) {
209     }
210     while(0U == (LPTIMER_INTF & LPTIMER_INTF_CMPVUPIF)) {
211     }
212     LPTIMER_INTC = LPTIMER_INTC_CMPVUPIC | LPTIMER_INTC_CARUPIC;
213     LPTIMER_CTL1 |= LPTIMER_CTL1_SMST;
214 }
215 
216 /*!
217     \brief      stop LPTIMER
218     \param[in]  none
219     \param[out] none
220     \retval     none
221 */
lptimer_stop(void)222 void lptimer_stop(void)
223 {
224     LPTIMER_CTL1 &= ~(uint32_t)LPTIMER_CTL1_LPTEN;
225 }
226 
227 /*!
228     \brief      read LPTIMER current counter value
229     \param[in]  none
230     \param[out] none
231     \retval     counter value
232 */
lptimer_counter_read(void)233 uint32_t lptimer_counter_read(void)
234 {
235     uint32_t count_value = 0U;
236     count_value = LPTIMER_CNT;
237     return (count_value);
238 }
239 
240 /*!
241     \brief      read LPTIMER auto reload value
242     \param[in]  none
243     \param[out] none
244     \retval     auto reload value
245 */
lptimer_autoreload_read(void)246 uint32_t lptimer_autoreload_read(void)
247 {
248     uint32_t car_value = 0U;
249     car_value = LPTIMER_CAR;
250     return (car_value);
251 }
252 
253 /*!
254     \brief      read LPTIMER compare value
255     \param[in]  none
256     \param[out] none
257     \retval     compare value
258 */
lptimer_compare_read(void)259 uint32_t lptimer_compare_read(void)
260 {
261     uint32_t comp_value = 0U;
262     comp_value = LPTIMER_CMPV;
263     return (comp_value);
264 }
265 
266 /*!
267     \brief      configure LPTIMER autoreload register value
268     \param[in]  autoreload: autoreload value
269     \param[out] none
270     \retval     none
271 */
lptimer_autoreload_value_config(uint32_t autoreload)272 void lptimer_autoreload_value_config(uint32_t autoreload)
273 {
274     LPTIMER_CAR = (uint32_t)autoreload;
275 }
276 
277 /*!
278     \brief      configure LPTIMER compare value
279     \param[in]  compare: compare value
280     \param[out] none
281     \retval     none
282 */
lptimer_compare_value_config(uint32_t compare)283 void lptimer_compare_value_config(uint32_t compare)
284 {
285     LPTIMER_CMPV = (uint32_t)compare;
286 }
287 
288 /*!
289     \brief      enable decode mode 0
290     \param[in]  none
291     \param[out] none
292     \retval     none
293 */
lptimer_decodemode0_enable(void)294 void lptimer_decodemode0_enable(void)
295 {
296     LPTIMER_CTL0 &= ~(uint32_t)(LPTIMER_CTL0_DECMEN | LPTIMER_CTL0_DECMSEL);
297     LPTIMER_CTL0 |= LPTIMER_CTL0_DECMEN;
298 }
299 
300 /*!
301     \brief      enable decode mode 1
302     \param[in]  none
303     \param[out] none
304     \retval     none
305 */
lptimer_decodemode1_enable(void)306 void lptimer_decodemode1_enable(void)
307 {
308     LPTIMER_CTL0 |= (uint32_t)(LPTIMER_CTL0_DECMEN | LPTIMER_CTL0_DECMSEL);
309 }
310 
311 /*!
312     \brief      disable decode mode 0/1
313     \param[in]  none
314     \param[out] none
315     \retval     none
316 */
lptimer_decodemode_disable(void)317 void lptimer_decodemode_disable(void)
318 {
319     LPTIMER_CTL0 &= ~(uint32_t)(LPTIMER_CTL0_DECMEN | LPTIMER_CTL0_DECMSEL);
320 }
321 
322 /*!
323     \brief      enable external input high level counter
324     \param[in]  maxvalue: input high level counter max value, 0x0~0x03ffffff
325     \param[out] none
326     \retval     none
327 */
lptimer_highlevelcounter_enable(uint32_t maxvalue)328 void lptimer_highlevelcounter_enable(uint32_t maxvalue)
329 {
330     LPTIMER_CTL1 |= (uint32_t)LPTIMER_CTL1_INHLCEN;
331     LPTIMER_INHLCMV = (uint32_t)maxvalue;
332 }
333 
334 /*!
335     \brief      disable external input high level counter
336     \param[in]  none
337     \param[out] none
338     \retval     none
339 */
lptimer_highlevelcounter_disable(void)340 void lptimer_highlevelcounter_disable(void)
341 {
342     LPTIMER_CTL1 &= ~(uint32_t)LPTIMER_CTL1_INHLCEN;
343 }
344 
345 /*!
346     \brief      get LPTIMER flags
347     \param[in]  flag: the LPTIMER flag
348                 only one parameter can be selected which is shown as below:
349       \arg        LPTIMER_FLAG_CMPVM: compare value register match flag
350       \arg        LPTIMER_FLAG_CARM: counter auto reload register match flag
351       \arg        LPTIMER_FLAG_ETEDEV: external trigger edge event flag
352       \arg        LPTIMER_FLAG_CMPVUP: compare value register update flag
353       \arg        LPTIMER_FLAG_CARUP: counter auto reload register update flag
354       \arg        LPTIMER_FLAG_UP: LPTIMER counter direction change down to up flag
355       \arg        LPTIMER_FLAG_DOWN: LPTIMER counter direction change up to down flag
356       \arg        LPTIMER_FLAG_HLCMVUP: input high level counter max value register update flag
357       \arg        LPTIMER_FLAG_INHLCO: LPTIMER_INx(x=0,1) high level counter overflow flag
358       \arg        LPTIMER_FLAG_INHLOE: the high level of LPTIMER_IN0 and LPTIMER_IN1 overlap error flag
359       \arg        LPTIMER_FLAG_INRFOE: the falling and rising edges of LPTIMER_IN0 and LPTIMER_IN1 overlap error flag
360       \arg        LPTIMER_FLAG_IN0E: LPTIMER_IN0 error flag
361       \arg        LPTIMER_FLAG_IN1E: LPTIMER_IN1 error flag
362     \param[out] none
363     \retval     FlagStatus: SET or RESET
364 */
lptimer_flag_get(uint32_t flag)365 FlagStatus lptimer_flag_get(uint32_t flag)
366 {
367     if(RESET != (LPTIMER_INTF & flag)) {
368         return SET;
369     } else {
370         return RESET;
371     }
372 }
373 
374 /*!
375     \brief      clear LPTIMER flags
376     \param[in]  flag: the LPTIMER flag
377                 one or more parameters can be selected which is shown as below:
378       \arg        LPTIMER_FLAG_CMPVM: compare value register match flag
379       \arg        LPTIMER_FLAG_CARM: counter auto reload register match flag
380       \arg        LPTIMER_FLAG_ETEDEV: external trigger edge event flag
381       \arg        LPTIMER_FLAG_CMPVUP: compare value register update flag
382       \arg        LPTIMER_FLAG_CARUP: counter auto reload register update flag
383       \arg        LPTIMER_FLAG_UP: LPTIMER counter direction change down to up flag
384       \arg        LPTIMER_FLAG_DOWN: LPTIMER counter direction change up to down flag
385       \arg        LPTIMER_FLAG_HLCMVUP: input high level counter max value register update flag
386       \arg        LPTIMER_FLAG_INHLCO: LPTIMER_INx(x=0,1) high level counter overflow flag
387       \arg        LPTIMER_FLAG_INHLOE: the high level of LPTIMER_IN0 and LPTIMER_IN1 overlap error flag
388       \arg        LPTIMER_FLAG_INRFOE: the falling and rising edges of LPTIMER_IN0 and LPTIMER_IN1 overlap error flag
389       \arg        LPTIMER_FLAG_IN0E: LPTIMER_IN0 error flag
390       \arg        LPTIMER_FLAG_IN1E: LPTIMER_IN1 error flag
391     \param[out] none
392     \retval     none
393 */
lptimer_flag_clear(uint32_t flag)394 void lptimer_flag_clear(uint32_t flag)
395 {
396     LPTIMER_INTC |= (uint32_t)flag;
397 }
398 
399 /*!
400     \brief      enable the LPTIMER interrupt
401     \param[in]  interrupt: LPTIMER interrupt source
402                 one or more parameters can be selected which is shown as below:
403       \arg        LPTIMER_INT_CMPVM: compare value register match interrupt
404       \arg        LPTIMER_INT_CARM: counter auto reload register match interrupt
405       \arg        LPTIMER_INT_ETEDEV: external trigger edge event interrupt
406       \arg        LPTIMER_INT_CMPVUP: compare value register update interrupt
407       \arg        LPTIMER_INT_CARUP: counter auto reload register update interrupt
408       \arg        LPTIMER_INT_UP: LPTIMER counter direction change down to up interrupt
409       \arg        LPTIMER_INT_DOWN: LPTIMER counter direction change up to down interrupt
410       \arg        LPTIMER_INT_HLCMVUP: input high level counter max value register update interrupt
411       \arg        LPTIMER_INT_INHLCO: LPTIMER_INx(x=0,1) high level counter overflow interrupt
412       \arg        LPTIMER_INT_INHLOE: the high level of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt
413       \arg        LPTIMER_INT_INRFOE: the falling and rising edges of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt
414       \arg        LPTIMER_INT_IN0E: LPTIMER_IN0 error interrupt
415       \arg        LPTIMER_INT_IN1E: LPTIMER_IN1 error interrupt
416     \param[out] none
417     \retval     none
418 */
lptimer_interrupt_enable(uint32_t interrupt)419 void lptimer_interrupt_enable(uint32_t interrupt)
420 {
421     LPTIMER_INTEN |= (uint32_t)interrupt;
422 }
423 
424 /*!
425     \brief      disable the LPTIMER interrupt
426     \param[in]  interrupt: LPTIMER interrupt source
427                 one or more parameters can be selected which is shown as below:
428       \arg        LPTIMER_INT_CMPVM: compare value register match interrupt
429       \arg        LPTIMER_INT_CARM: counter auto reload register match interrupt
430       \arg        LPTIMER_INT_ETEDEV: external trigger edge event interrupt
431       \arg        LPTIMER_INT_CMPVUP: compare value register update interrupt
432       \arg        LPTIMER_INT_CARUP: counter auto reload register update interrupt
433       \arg        LPTIMER_INT_UP: LPTIMER counter direction change down to up interrupt
434       \arg        LPTIMER_INT_DOWN: LPTIMER counter direction change up to down interrupt
435       \arg        LPTIMER_INT_HLCMVUP: input high level counter max value register update interrupt
436       \arg        LPTIMER_INT_INHLCO: LPTIMER_INx(x=0,1) high level counter overflow interrupt
437       \arg        LPTIMER_INT_INHLOE: the high level of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt
438       \arg        LPTIMER_INT_INRFOE: the falling and rising edges of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt
439       \arg        LPTIMER_INT_IN0E: LPTIMER_IN0 error interrupt
440       \arg        LPTIMER_INT_IN1E: LPTIMER_IN1 error interrupt
441     \param[out] none
442     \retval     none
443 */
lptimer_interrupt_disable(uint32_t interrupt)444 void lptimer_interrupt_disable(uint32_t interrupt)
445 {
446     LPTIMER_INTEN &= (~(uint32_t)interrupt);
447 }
448 
449 /*!
450     \brief      get LPTIMER interrupt flag
451     \param[in]  int_flag: the LPTIMER interrupt flag
452                 only one parameter can be selected which is shown as below:
453       \arg        LPTIMER_INT_FLAG_CMPVM: compare value register match interrupt flag
454       \arg        LPTIMER_INT_FLAG_CARM: counter auto reload register match interrupt flag
455       \arg        LPTIMER_INT_FLAG_ETEDEV: external trigger edge event interrupt flag
456       \arg        LPTIMER_INT_FLAG_CMPVUP: compare value register update interrupt flag
457       \arg        LPTIMER_INT_FLAG_CARUP: counter auto reload register update interrupt flag
458       \arg        LPTIMER_INT_FLAG_UP: LPTIMER counter direction change down to up interrupt flag
459       \arg        LPTIMER_INT_FLAG_DOWN: LPTIMER counter direction change up to down interrupt flag
460       \arg        LPTIMER_INT_FLAG_HLCMVUP: input high level counter max value register update interrupt flag
461       \arg        LPTIMER_INT_FLAG_INHLCO: LPTIMER_INx(x=0,1) high level counter overflow interrupt flag
462       \arg        LPTIMER_INT_FLAG_INHLOE: the high level of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt flag
463       \arg        LPTIMER_INT_FLAG_INRFOE: the falling and rising edges of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt flag
464       \arg        LPTIMER_INT_FLAG_IN0E: LPTIMER_IN0 error interrupt flag
465       \arg        LPTIMER_INT_FLAG_IN1E: LPTIMER_IN1 error interrupt flag
466     \param[out] none
467     \retval     FlagStatus: SET or RESET
468 */
lptimer_interrupt_flag_get(uint32_t int_flag)469 FlagStatus lptimer_interrupt_flag_get(uint32_t int_flag)
470 {
471     uint32_t val;
472     val = (LPTIMER_INTEN & int_flag);
473     if((RESET != (LPTIMER_INTF & int_flag)) && (RESET != val)) {
474         return SET;
475     } else {
476         return RESET;
477     }
478 }
479 
480 /*!
481     \brief      clear LPTIMER interrupt flag
482     \param[in]  int_flag: the LPTIMER interrupt flag
483                 one or more parameters can be selected which is shown as below:
484       \arg        LPTIMER_INT_FLAG_CMPVM: compare value register match interrupt flag
485       \arg        LPTIMER_INT_FLAG_CARM: counter auto reload register match interrupt flag
486       \arg        LPTIMER_INT_FLAG_ETEDEV: external trigger edge event interrupt flag
487       \arg        LPTIMER_INT_FLAG_CMPVUP: compare value register update interrupt flag
488       \arg        LPTIMER_INT_FLAG_CARUP: counter auto reload register update interrupt flag
489       \arg        LPTIMER_INT_FLAG_UP: LPTIMER counter direction change down to up interrupt flag
490       \arg        LPTIMER_INT_FLAG_DOWN: LPTIMER counter direction change up to down interrupt flag
491       \arg        LPTIMER_INT_FLAG_HLCMVUP: input high level counter max value register update interrupt flag
492       \arg        LPTIMER_INT_FLAG_INHLCO: LPTIMER_INx(x=0,1) high level counter overflow interrupt flag
493       \arg        LPTIMER_INT_FLAG_INHLOE: the high level of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt flag
494       \arg        LPTIMER_INT_FLAG_INRFOE: the falling and rising edges of LPTIMER_IN0 and LPTIMER_IN1 overlap error interrupt flag
495       \arg        LPTIMER_INT_FLAG_IN0E: LPTIMER_IN0 error interrupt flag
496       \arg        LPTIMER_INT_FLAG_IN1E: LPTIMER_IN1 error interrupt flag
497     \param[out] none
498     \retval     none
499 */
lptimer_interrupt_flag_clear(uint32_t int_flag)500 void lptimer_interrupt_flag_clear(uint32_t int_flag)
501 {
502     LPTIMER_INTC |= (uint32_t)int_flag;
503 }
504