1 /*!
2 \file gd32l23x_timer.c
3 \brief TIMER 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_timer.h"
36
37 /*!
38 \brief deinit a TIMER
39 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
40 \param[out] none
41 \retval none
42 */
timer_deinit(uint32_t timer_periph)43 void timer_deinit(uint32_t timer_periph)
44 {
45 switch(timer_periph) {
46 case TIMER1:
47 /* reset TIMER1 */
48 rcu_periph_reset_enable(RCU_TIMER1RST);
49 rcu_periph_reset_disable(RCU_TIMER1RST);
50 break;
51 case TIMER2:
52 /* reset TIMER2 */
53 rcu_periph_reset_enable(RCU_TIMER2RST);
54 rcu_periph_reset_disable(RCU_TIMER2RST);
55 break;
56 case TIMER5:
57 /* reset TIMER5 */
58 rcu_periph_reset_enable(RCU_TIMER5RST);
59 rcu_periph_reset_disable(RCU_TIMER5RST);
60 break;
61 case TIMER6:
62 /* reset TIMER6 */
63 rcu_periph_reset_enable(RCU_TIMER6RST);
64 rcu_periph_reset_disable(RCU_TIMER6RST);
65 break;
66 case TIMER8:
67 /* reset TIMER8 */
68 rcu_periph_reset_enable(RCU_TIMER8RST);
69 rcu_periph_reset_disable(RCU_TIMER8RST);
70 break;
71 case TIMER11:
72 /* reset TIMER11 */
73 rcu_periph_reset_enable(RCU_TIMER11RST);
74 rcu_periph_reset_disable(RCU_TIMER11RST);
75 break;
76 default:
77 break;
78 }
79 }
80
81 /*!
82 \brief initialize TIMER init parameter struct with a default value
83 \param[in] initpara: init parameter struct
84 \param[out] none
85 \retval none
86 */
timer_struct_para_init(timer_parameter_struct * initpara)87 void timer_struct_para_init(timer_parameter_struct *initpara)
88 {
89 /* initialize the init parameter struct member with the default value */
90 initpara->prescaler = 0U;
91 initpara->alignedmode = TIMER_COUNTER_EDGE;
92 initpara->counterdirection = TIMER_COUNTER_UP;
93 initpara->period = 65535U;
94 initpara->clockdivision = TIMER_CKDIV_DIV1;
95 }
96
97 /*!
98 \brief initialize TIMER counter
99 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
100 \param[in] initpara: init parameter struct
101 prescaler: prescaler value of the counter clock, 0~65535
102 alignedmode: TIMER_COUNTER_EDGE, TIMER_COUNTER_CENTER_DOWN, TIMER_COUNTER_CENTER_UP, TIMER_COUNTER_CENTER_BOTH
103 counterdirection: TIMER_COUNTER_UP, TIMER_COUNTER_DOWN
104 period: counter auto reload value, 0~65535
105 clockdivision: TIMER_CKDIV_DIV1, TIMER_CKDIV_DIV2, TIMER_CKDIV_DIV4
106 \param[out] none
107 \retval none
108 */
gd32_timer_init(uint32_t timer_periph,timer_parameter_struct * initpara)109 void gd32_timer_init(uint32_t timer_periph, timer_parameter_struct *initpara)
110 {
111 /* configure the counter prescaler value */
112 TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
113
114 /* configure the counter direction and aligned mode */
115 if((TIMER1 == timer_periph) || (TIMER2 == timer_periph)) {
116 TIMER_CTL0(timer_periph) &= (~(uint32_t)(TIMER_CTL0_DIR | TIMER_CTL0_CAM));
117 TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->alignedmode);
118 TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->counterdirection);
119 }
120
121 /* configure the autoreload value */
122 TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
123
124 if(TIMER5 != timer_periph) {
125 /* reset the CKDIV bit */
126 TIMER_CTL0(timer_periph) &= (~(uint32_t)TIMER_CTL0_CKDIV);
127 TIMER_CTL0(timer_periph) |= (uint32_t)(initpara->clockdivision);
128 }
129
130 /* generate an update event */
131 TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
132 }
133
134 /*!
135 \brief enable a TIMER
136 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
137 \param[out] none
138 \retval none
139 */
timer_enable(uint32_t timer_periph)140 void timer_enable(uint32_t timer_periph)
141 {
142 TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_CEN;
143 }
144
145 /*!
146 \brief disable a TIMER
147 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
148 \param[out] none
149 \retval none
150 */
timer_disable(uint32_t timer_periph)151 void timer_disable(uint32_t timer_periph)
152 {
153 TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CEN;
154 }
155
156 /*!
157 \brief enable the auto reload shadow function
158 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
159 \param[out] none
160 \retval none
161 */
timer_auto_reload_shadow_enable(uint32_t timer_periph)162 void timer_auto_reload_shadow_enable(uint32_t timer_periph)
163 {
164 TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_ARSE;
165 }
166
167 /*!
168 \brief disable the auto reload shadow function
169 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
170 \param[out] none
171 \retval none
172 */
timer_auto_reload_shadow_disable(uint32_t timer_periph)173 void timer_auto_reload_shadow_disable(uint32_t timer_periph)
174 {
175 TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_ARSE;
176 }
177
178 /*!
179 \brief enable the update event
180 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
181 \param[out] none
182 \retval none
183 */
timer_update_event_enable(uint32_t timer_periph)184 void timer_update_event_enable(uint32_t timer_periph)
185 {
186 TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPDIS;
187 }
188
189 /*!
190 \brief disable the update event
191 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
192 \param[out] none
193 \retval none
194 */
timer_update_event_disable(uint32_t timer_periph)195 void timer_update_event_disable(uint32_t timer_periph)
196 {
197 TIMER_CTL0(timer_periph) |= (uint32_t) TIMER_CTL0_UPDIS;
198 }
199
200 /*!
201 \brief set TIMER counter alignment mode
202 \param[in] timer_periph: TIMERx(x=1,2)
203 \param[in] aligned:
204 only one parameter can be selected which is shown as below:
205 \arg TIMER_COUNTER_EDGE: edge-aligned mode
206 \arg TIMER_COUNTER_CENTER_DOWN: center-aligned and counting down assert mode
207 \arg TIMER_COUNTER_CENTER_UP: center-aligned and counting up assert mode
208 \arg TIMER_COUNTER_CENTER_BOTH: center-aligned and counting up/down assert mode
209 \param[out] none
210 \retval none
211 */
timer_counter_alignment(uint32_t timer_periph,uint16_t aligned)212 void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned)
213 {
214 TIMER_CTL0(timer_periph) &= (uint32_t)(~TIMER_CTL0_CAM);
215 TIMER_CTL0(timer_periph) |= (uint32_t)aligned;
216 }
217
218 /*!
219 \brief set TIMER counter up direction
220 \param[in] timer_periph: TIMERx(x=1,2)
221 \param[out] none
222 \retval none
223 */
timer_counter_up_direction(uint32_t timer_periph)224 void timer_counter_up_direction(uint32_t timer_periph)
225 {
226 TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_DIR;
227 }
228
229 /*!
230 \brief set TIMER counter down direction
231 \param[in] timer_periph: TIMERx(x=1,2)
232 \param[out] none
233 \retval none
234 */
timer_counter_down_direction(uint32_t timer_periph)235 void timer_counter_down_direction(uint32_t timer_periph)
236 {
237 TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_DIR;
238 }
239
240 /*!
241 \brief configure TIMER prescaler
242 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
243 \param[in] prescaler: prescaler value,0~65535
244 \param[in] pscreload: prescaler reload mode
245 only one parameter can be selected which is shown as below:
246 \arg TIMER_PSC_RELOAD_NOW: the prescaler is loaded right now
247 \arg TIMER_PSC_RELOAD_UPDATE: the prescaler is loaded at the next update event
248 \param[out] none
249 \retval none
250 */
timer_prescaler_config(uint32_t timer_periph,uint16_t prescaler,uint32_t pscreload)251 void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint32_t pscreload)
252 {
253 TIMER_PSC(timer_periph) = (uint32_t)prescaler;
254
255 if(TIMER_PSC_RELOAD_NOW == pscreload) {
256 TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
257 }
258 }
259
260 /*!
261 \brief configure TIMER autoreload register value
262 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
263 \param[in] autoreload: the counter auto-reload value,0~65535
264 \param[out] none
265 \retval none
266 */
timer_autoreload_value_config(uint32_t timer_periph,uint32_t autoreload)267 void timer_autoreload_value_config(uint32_t timer_periph, uint32_t autoreload)
268 {
269 TIMER_CAR(timer_periph) = (uint32_t)autoreload;
270 }
271
272 /*!
273 \brief configure TIMER counter register value
274 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
275 \param[in] counter: the counter value,0~65535
276 \param[out] none
277 \retval none
278 */
timer_counter_value_config(uint32_t timer_periph,uint32_t counter)279 void timer_counter_value_config(uint32_t timer_periph, uint32_t counter)
280 {
281 TIMER_CNT(timer_periph) = (uint32_t)counter;
282 }
283
284 /*!
285 \brief read TIMER counter value
286 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
287 \param[out] none
288 \retval counter value
289 */
timer_counter_read(uint32_t timer_periph)290 uint32_t timer_counter_read(uint32_t timer_periph)
291 {
292 uint32_t count_value = 0U;
293 count_value = TIMER_CNT(timer_periph);
294 return (count_value);
295 }
296
297 /*!
298 \brief read TIMER prescaler value
299 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
300 \param[out] none
301 \retval prescaler register value
302 */
timer_prescaler_read(uint32_t timer_periph)303 uint16_t timer_prescaler_read(uint32_t timer_periph)
304 {
305 uint16_t prescaler_value = 0U;
306 prescaler_value = (uint16_t)(TIMER_PSC(timer_periph));
307 return (prescaler_value);
308 }
309
310 /*!
311 \brief configure TIMER single pulse mode
312 \param[in] timer_periph: TIMERx(x=1,2,8,11)
313 \param[in] spmode:
314 only one parameter can be selected which is shown as below:
315 \arg TIMER_SP_MODE_SINGLE: single pulse mode
316 \arg TIMER_SP_MODE_REPETITIVE: repetitive pulse mode
317 \param[out] none
318 \retval none
319 */
timer_single_pulse_mode_config(uint32_t timer_periph,uint32_t spmode)320 void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
321 {
322 if(TIMER_SP_MODE_SINGLE == spmode) {
323 TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_SPM;
324 } else if(TIMER_SP_MODE_REPETITIVE == spmode) {
325 TIMER_CTL0(timer_periph) &= ~((uint32_t)TIMER_CTL0_SPM);
326 } else {
327 /* illegal parameters */
328 }
329 }
330
331 /*!
332 \brief configure TIMER update source
333 \param[in] timer_periph: TIMERx(x=1,2,5,6,8,11)
334 \param[in] update:
335 only one parameter can be selected which is shown as below:
336 \arg TIMER_UPDATE_SRC_GLOBAL: update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger
337 \arg TIMER_UPDATE_SRC_REGULAR: update generate only by counter overflow/underflow
338 \param[out] none
339 \retval none
340 */
timer_update_source_config(uint32_t timer_periph,uint32_t update)341 void timer_update_source_config(uint32_t timer_periph, uint32_t update)
342 {
343 if(TIMER_UPDATE_SRC_REGULAR == update) {
344 TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPS;
345 } else if(TIMER_UPDATE_SRC_GLOBAL == update) {
346 TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPS;
347 } else {
348 /* illegal parameters */
349 }
350 }
351
352 /*!
353 \brief enable the TIMER DMA
354 \param[in] timer_periph: please refer to the following parameters
355 \param[in] dma: specify which DMA to enable
356 only one parameter can be selected which is shown as below:
357 \arg TIMER_DMA_UPD: update DMA ,TIMERx(x=1,2,5,6,8,11)
358 \arg TIMER_DMA_CH0D: channel 0 DMA request,TIMERx(x=1,2,8,11)
359 \arg TIMER_DMA_CH1D: channel 1 DMA request,TIMERx(x=1,2,8,11)
360 \arg TIMER_DMA_CH2D: channel 2 DMA request,TIMERx(x=1,2)
361 \arg TIMER_DMA_CH3D: channel 3 DMA request,TIMERx(x=1,2)
362 \arg TIMER_DMA_TRGD: trigger DMA request,TIMERx(x=1,2,8,11)
363 \param[out] none
364 \retval none
365 */
timer_dma_enable(uint32_t timer_periph,uint16_t dma)366 void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
367 {
368 TIMER_DMAINTEN(timer_periph) |= (uint32_t) dma;
369 }
370
371 /*!
372 \brief disable the TIMER DMA
373 \param[in] timer_periph: please refer to the following parameters
374 \param[in] dma: specify which DMA to enable
375 one or more parameters can be selected which are shown as below:
376 \arg TIMER_DMA_UPD: update DMA ,TIMERx(x=1,2,5,6,8,11)
377 \arg TIMER_DMA_CH0D: channel 0 DMA request,TIMERx(x=1,2,8,11)
378 \arg TIMER_DMA_CH1D: channel 1 DMA request,TIMERx(x=1,2,8,11)
379 \arg TIMER_DMA_CH2D: channel 2 DMA request,TIMERx(x=1,2)
380 \arg TIMER_DMA_CH3D: channel 3 DMA request,TIMERx(x=1,2)
381 \arg TIMER_DMA_TRGD: trigger DMA request,TIMERx(x=1,2,8,11)
382 \param[out] none
383 \retval none
384 */
timer_dma_disable(uint32_t timer_periph,uint16_t dma)385 void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
386 {
387 TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma));
388 }
389
390 /*!
391 \brief channel DMA request source selection
392 \param[in] timer_periph: TIMERx(x=1,2)
393 \param[in] dma_request: channel DMA request source selection
394 only one parameter can be selected which is shown as below:
395 \arg TIMER_DMAREQUEST_CHANNELEVENT: DMA request of channel y is sent when channel y event occurs
396 \arg TIMER_DMAREQUEST_UPDATEEVENT: DMA request of channel y is sent when update event occurs
397 \param[out] none
398 \retval none
399 */
timer_channel_dma_request_source_select(uint32_t timer_periph,uint32_t dma_request)400 void timer_channel_dma_request_source_select(uint32_t timer_periph, uint32_t dma_request)
401 {
402 if(TIMER_DMAREQUEST_UPDATEEVENT == dma_request) {
403 TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_DMAS;
404 } else if(TIMER_DMAREQUEST_CHANNELEVENT == dma_request) {
405 TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_DMAS;
406 } else {
407 /* illegal parameters */
408 }
409 }
410
411 /*!
412 \brief configure the TIMER DMA transfer
413 \param[in] timer_periph: TIMERx(x=1,2)
414 \param[in] dma_baseaddr:
415 only one parameter can be selected which is shown as below:
416 \arg TIMER_DMACFG_DMATA_CTL0: DMA transfer address is TIMER_CTL0
417 \arg TIMER_DMACFG_DMATA_CTL1: DMA transfer address is TIMER_CTL1
418 \arg TIMER_DMACFG_DMATA_SMCFG: DMA transfer address is TIMER_SMCFG
419 \arg TIMER_DMACFG_DMATA_DMAINTEN: DMA transfer address is TIMER_DMAINTEN
420 \arg TIMER_DMACFG_DMATA_INTF: DMA transfer address is TIMER_INTF
421 \arg TIMER_DMACFG_DMATA_SWEVG: DMA transfer address is TIMER_SWEVG
422 \arg TIMER_DMACFG_DMATA_CHCTL0: DMA transfer address is TIMER_CHCTL0
423 \arg TIMER_DMACFG_DMATA_CHCTL1: DMA transfer address is TIMER_CHCTL1
424 \arg TIMER_DMACFG_DMATA_CHCTL2: DMA transfer address is TIMER_CHCTL2
425 \arg TIMER_DMACFG_DMATA_CNT: DMA transfer address is TIMER_CNT
426 \arg TIMER_DMACFG_DMATA_PSC: DMA transfer address is TIMER_PSC
427 \arg TIMER_DMACFG_DMATA_CAR: DMA transfer address is TIMER_CAR
428 \arg TIMER_DMACFG_DMATA_CH0CV: DMA transfer address is TIMER_CH0CV
429 \arg TIMER_DMACFG_DMATA_CH1CV: DMA transfer address is TIMER_CH1CV
430 \arg TIMER_DMACFG_DMATA_CH2CV: DMA transfer address is TIMER_CH2CV
431 \arg TIMER_DMACFG_DMATA_CH3CV: DMA transfer address is TIMER_CH3CV
432 \param[in] dma_lenth:
433 only one parameter can be selected which is shown as below:
434 \arg TIMER_DMACFG_DMATC_xTRANSFER(x=1..17): DMA transfer x time
435 \param[out] none
436 \retval none
437 */
timer_dma_transfer_config(uint32_t timer_periph,uint32_t dma_baseaddr,uint32_t dma_lenth)438 void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth)
439 {
440 uint32_t ctl;
441 ctl = TIMER_DMACFG(timer_periph);
442 ctl &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
443 ctl |= (uint32_t)(dma_baseaddr | dma_lenth);
444 TIMER_DMACFG(timer_periph) = ctl;
445 }
446
447 /*!
448 \brief software generate events
449 \param[in] timer_periph: please refer to the following parameters
450 \param[in] event: the timer software event generation sources
451 one or more parameters can be selected which are shown as below:
452 \arg TIMER_EVENT_SRC_UPG: update event,TIMERx(x=1,2,5,6,8,11)
453 \arg TIMER_EVENT_SRC_CH0G: channel 0 capture or compare event generation,TIMERx(x=1,2,8,11)
454 \arg TIMER_EVENT_SRC_CH1G: channel 1 capture or compare event generation,TIMERx(x=1,2,8,11)
455 \arg TIMER_EVENT_SRC_CH2G: channel 2 capture or compare event generation,TIMERx(x=1,2)
456 \arg TIMER_EVENT_SRC_CH3G: channel 3 capture or compare event generation,TIMERx(x=1,2)
457 \arg TIMER_EVENT_SRC_TRGG: trigger event generation,TIMERx(x=1,2,8,11)
458 \param[out] none
459 \retval none
460 */
timer_event_software_generate(uint32_t timer_periph,uint16_t event)461 void timer_event_software_generate(uint32_t timer_periph, uint16_t event)
462 {
463 TIMER_SWEVG(timer_periph) |= (uint32_t)event;
464 }
465
466 /*!
467 \brief initialize TIMER channel output parameter struct with a default value
468 \param[in] ocpara: TIMER channel n output parameter struct
469 \param[out] none
470 \retval none
471 */
timer_channel_output_struct_para_init(timer_oc_parameter_struct * ocpara)472 void timer_channel_output_struct_para_init(timer_oc_parameter_struct *ocpara)
473 {
474 /* initialize the channel output parameter struct member with the default value */
475 ocpara->outputstate = TIMER_CCX_DISABLE;
476 ocpara->ocpolarity = TIMER_OC_POLARITY_HIGH;
477 }
478
479 /*!
480 \brief configure TIMER channel output function
481 \param[in] timer_periph: please refer to the following parameters
482 \param[in] channel:
483 only one parameter can be selected which is shown as below:
484 \arg TIMER_CH_0: TIMER channel 0(TIMERx(x=1,2,8,11))
485 \arg TIMER_CH_1: TIMER channel 1(TIMERx(x=1,2,8,11))
486 \arg TIMER_CH_2: TIMER channel 2(TIMERx(x=1,2))
487 \arg TIMER_CH_3: TIMER channel 3(TIMERx(x=1,2))
488 \param[in] ocpara: TIMER channeln output parameter struct
489 outputstate: TIMER_CCX_ENABLE,TIMER_CCX_DISABLE
490 ocpolarity: TIMER_OC_POLARITY_HIGH,TIMER_OC_POLARITY_LOW
491 \param[out] none
492 \retval none
493 */
timer_channel_output_config(uint32_t timer_periph,uint16_t channel,timer_oc_parameter_struct * ocpara)494 void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct *ocpara)
495 {
496 uint32_t ctl;
497
498 switch(channel) {
499 /* configure TIMER_CH_0 */
500 case TIMER_CH_0:
501 /* reset the CH0EN bit */
502 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
503 TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH0MS;
504 /* set the CH0EN bit */
505 TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->outputstate;
506 /* set the CH0P bit */
507 ctl = TIMER_CHCTL2(timer_periph);
508 ctl &= (~(uint32_t)TIMER_CHCTL2_CH0P);
509 ctl |= (uint32_t)ocpara->ocpolarity;
510 TIMER_CHCTL2(timer_periph) = ctl;
511 break;
512 /* configure TIMER_CH_1 */
513 case TIMER_CH_1:
514 /* reset the CH1EN bit */
515 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
516 TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH1MS;
517 /* set the CH1EN bit */
518 TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputstate) << 4U);
519 /* set the CH1P bit */
520 ctl = TIMER_CHCTL2(timer_periph);
521 ctl &= (~(uint32_t)TIMER_CHCTL2_CH1P);
522 ctl |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 4U);
523 TIMER_CHCTL2(timer_periph) = ctl;
524 break;
525 /* configure TIMER_CH_2 */
526 case TIMER_CH_2:
527 /* reset the CH2EN bit */
528 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
529 TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH2MS;
530 /* set the CH2EN bit */
531 TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputstate) << 8U);
532 /* set the CH2P bit */
533 ctl = TIMER_CHCTL2(timer_periph);
534 ctl &= (~(uint32_t)TIMER_CHCTL2_CH2P);
535 ctl |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 8U);
536 TIMER_CHCTL2(timer_periph) = ctl;
537 break;
538 /* configure TIMER_CH_3 */
539 case TIMER_CH_3:
540 /* reset the CH3EN bit */
541 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
542 TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH3MS;
543 /* set the CH3EN bit */
544 TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputstate) << 12U);
545 /* set the CH3P bit */
546 ctl = TIMER_CHCTL2(timer_periph);
547 ctl &= (~(uint32_t)TIMER_CHCTL2_CH3P);
548 ctl |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 12U);
549 TIMER_CHCTL2(timer_periph) = ctl;
550 break;
551 default:
552 break;
553 }
554 }
555
556 /*!
557 \brief configure TIMER channel output compare mode
558 \param[in] timer_periph: please refer to the following parameters
559 \param[in] channel:
560 only one parameter can be selected which is shown as below:
561 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
562 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
563 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
564 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
565 \param[in] ocmode: channel output compare mode
566 only one parameter can be selected which is shown as below:
567 \arg TIMER_OC_MODE_TIMING: timing mode
568 \arg TIMER_OC_MODE_ACTIVE: active mode
569 \arg TIMER_OC_MODE_INACTIVE: inactive mode
570 \arg TIMER_OC_MODE_TOGGLE: toggle mode
571 \arg TIMER_OC_MODE_LOW: force low mode
572 \arg TIMER_OC_MODE_HIGH: force high mode
573 \arg TIMER_OC_MODE_PWM0: PWM0 mode
574 \arg TIMER_OC_MODE_PWM1: PWM1 mode
575 \param[out] none
576 \retval none
577 */
timer_channel_output_mode_config(uint32_t timer_periph,uint16_t channel,uint16_t ocmode)578 void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode)
579 {
580 uint32_t ctl;
581
582 switch(channel) {
583 /* configure TIMER_CH_0 */
584 case TIMER_CH_0:
585 ctl = TIMER_CHCTL0(timer_periph);
586 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0COMCTL);
587 ctl |= (uint32_t)ocmode;
588 TIMER_CHCTL0(timer_periph) = ctl;
589 break;
590 /* configure TIMER_CH_1 */
591 case TIMER_CH_1:
592 ctl = TIMER_CHCTL0(timer_periph);
593 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1COMCTL);
594 ctl |= (uint32_t)((uint32_t)(ocmode) << 8U);
595 TIMER_CHCTL0(timer_periph) = ctl;
596 break;
597 /* configure TIMER_CH_2 */
598 case TIMER_CH_2:
599 ctl = TIMER_CHCTL1(timer_periph);
600 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2COMCTL);
601 ctl |= (uint32_t)ocmode;
602 TIMER_CHCTL1(timer_periph) = ctl;
603 break;
604 /* configure TIMER_CH_3 */
605 case TIMER_CH_3:
606 ctl = TIMER_CHCTL1(timer_periph);
607 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3COMCTL);
608 ctl |= (uint32_t)((uint32_t)(ocmode) << 8U);
609 TIMER_CHCTL1(timer_periph) = ctl;
610 break;
611 default:
612 break;
613 }
614 }
615
616 /*!
617 \brief configure TIMER channel output pulse value
618 \param[in] timer_periph: please refer to the following parameters
619 \param[in] channel:
620 only one parameter can be selected which is shown as below:
621 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
622 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
623 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
624 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
625 \param[in] pulse: channel output pulse value
626 \param[out] none
627 \retval none
628 */
timer_channel_output_pulse_value_config(uint32_t timer_periph,uint16_t channel,uint32_t pulse)629 void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse)
630 {
631 switch(channel) {
632 /* configure TIMER_CH_0 */
633 case TIMER_CH_0:
634 TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
635 break;
636 /* configure TIMER_CH_1 */
637 case TIMER_CH_1:
638 TIMER_CH1CV(timer_periph) = (uint32_t)pulse;
639 break;
640 /* configure TIMER_CH_2 */
641 case TIMER_CH_2:
642 TIMER_CH2CV(timer_periph) = (uint32_t)pulse;
643 break;
644 /* configure TIMER_CH_3 */
645 case TIMER_CH_3:
646 TIMER_CH3CV(timer_periph) = (uint32_t)pulse;
647 break;
648 default:
649 break;
650 }
651 }
652
653 /*!
654 \brief configure TIMER channel output shadow function
655 \param[in] timer_periph: please refer to the following parameters
656 \param[in] channel:
657 only one parameter can be selected which is shown as below:
658 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
659 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
660 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
661 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
662 \param[in] ocshadow: channel output shadow state
663 only one parameter can be selected which is shown as below:
664 \arg TIMER_OC_SHADOW_ENABLE: channel output shadow state enable
665 \arg TIMER_OC_SHADOW_DISABLE: channel output shadow state disable
666 \param[out] none
667 \retval none
668 */
timer_channel_output_shadow_config(uint32_t timer_periph,uint16_t channel,uint16_t ocshadow)669 void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow)
670 {
671 uint32_t ctl;
672
673 switch(channel) {
674 /* configure TIMER_CH_0 */
675 case TIMER_CH_0:
676 ctl = TIMER_CHCTL0(timer_periph);
677 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0COMSEN);
678 ctl |= (uint32_t)ocshadow;
679 TIMER_CHCTL0(timer_periph) = ctl;
680 break;
681 /* configure TIMER_CH_1 */
682 case TIMER_CH_1:
683 ctl = TIMER_CHCTL0(timer_periph);
684 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1COMSEN);
685 ctl |= (uint32_t)((uint32_t)(ocshadow) << 8U);
686 TIMER_CHCTL0(timer_periph) = ctl;
687 break;
688 /* configure TIMER_CH_2 */
689 case TIMER_CH_2:
690 ctl = TIMER_CHCTL1(timer_periph);
691 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2COMSEN);
692 ctl |= (uint32_t)ocshadow;
693 TIMER_CHCTL1(timer_periph) = ctl;
694 break;
695 /* configure TIMER_CH_3 */
696 case TIMER_CH_3:
697 ctl = TIMER_CHCTL1(timer_periph);
698 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3COMSEN);
699 ctl |= (uint32_t)((uint32_t)(ocshadow) << 8U);
700 TIMER_CHCTL1(timer_periph) = ctl;
701 break;
702 default:
703 break;
704 }
705 }
706
707 /*!
708 \brief configure TIMER channel output fast function
709 \param[in] timer_periph: please refer to the following parameters
710 \param[in] channel:
711 only one parameter can be selected which is shown as below:
712 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
713 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
714 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
715 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
716 \param[in] ocfast: channel output fast function
717 only one parameter can be selected which is shown as below:
718 \arg TIMER_OC_FAST_ENABLE: channel output fast function enable
719 \arg TIMER_OC_FAST_DISABLE: channel output fast function disable
720 \param[out] none
721 \retval none
722 */
timer_channel_output_fast_config(uint32_t timer_periph,uint16_t channel,uint16_t ocfast)723 void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast)
724 {
725 uint32_t ctl;
726
727 switch(channel) {
728 /* configure TIMER_CH_0 */
729 case TIMER_CH_0:
730 ctl = TIMER_CHCTL0(timer_periph);
731 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0COMFEN);
732 ctl |= (uint32_t)ocfast;
733 TIMER_CHCTL0(timer_periph) = ctl;
734 break;
735 /* configure TIMER_CH_1 */
736 case TIMER_CH_1:
737 ctl = TIMER_CHCTL0(timer_periph);
738 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1COMFEN);
739 ctl |= (uint32_t)((uint32_t)ocfast << 8U);
740 TIMER_CHCTL0(timer_periph) = ctl;
741 break;
742 /* configure TIMER_CH_2 */
743 case TIMER_CH_2:
744 ctl = TIMER_CHCTL1(timer_periph);
745 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2COMFEN);
746 ctl |= (uint32_t)ocfast;
747 TIMER_CHCTL1(timer_periph) = ctl;
748 break;
749 /* configure TIMER_CH_3 */
750 case TIMER_CH_3:
751 ctl = TIMER_CHCTL1(timer_periph);
752 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3COMFEN);
753 ctl |= (uint32_t)((uint32_t)ocfast << 8U);
754 TIMER_CHCTL1(timer_periph) = ctl;
755 break;
756 default:
757 break;
758 }
759 }
760
761 /*!
762 \brief configure TIMER channel output clear function
763 \param[in] timer_periph: please refer to the following parameters
764 \param[in] channel:
765 only one parameter can be selected which is shown as below:
766 \arg TIMER_CH_0: TIMER channel0 TIMERx(x=1,2)
767 \arg TIMER_CH_1: TIMER channel1 TIMERx(x=1,2)
768 \arg TIMER_CH_2: TIMER channel2 TIMERx(x=1,2)
769 \arg TIMER_CH_3: TIMER channel3 TIMERx(x=1,2)
770 \param[in] occlear: channel output clear function
771 only one parameter can be selected which is shown as below:
772 \arg TIMER_OC_CLEAR_ENABLE: channel output clear function enable
773 \arg TIMER_OC_CLEAR_DISABLE: channel output clear function disable
774 \param[out] none
775 \retval none
776 */
timer_channel_output_clear_config(uint32_t timer_periph,uint16_t channel,uint16_t occlear)777 void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel, uint16_t occlear)
778 {
779 uint32_t ctl;
780
781 switch(channel) {
782 /* configure TIMER_CH_0 */
783 case TIMER_CH_0:
784 ctl = TIMER_CHCTL0(timer_periph);
785 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0COMCEN);
786 ctl |= (uint32_t)occlear;
787 TIMER_CHCTL0(timer_periph) = ctl;
788 break;
789 /* configure TIMER_CH_1 */
790 case TIMER_CH_1:
791 ctl = TIMER_CHCTL0(timer_periph);
792 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1COMCEN);
793 ctl |= (uint32_t)((uint32_t)occlear << 8U);
794 TIMER_CHCTL0(timer_periph) = ctl;
795 break;
796 /* configure TIMER_CH_2 */
797 case TIMER_CH_2:
798 ctl = TIMER_CHCTL1(timer_periph);
799 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2COMCEN);
800 ctl |= (uint32_t)occlear;
801 TIMER_CHCTL1(timer_periph) = ctl;
802 break;
803 /* configure TIMER_CH_3 */
804 case TIMER_CH_3:
805 ctl = TIMER_CHCTL1(timer_periph);
806 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3COMCEN);
807 ctl |= (uint32_t)((uint32_t)occlear << 8U);
808 TIMER_CHCTL1(timer_periph) = ctl;
809 break;
810 default:
811 break;
812 }
813 }
814
815 /*!
816 \brief configure TIMER channel output polarity
817 \param[in] timer_periph: please refer to the following parameters
818 \param[in] channel:
819 only one parameter can be selected which is shown as below:
820 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
821 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
822 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
823 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
824 \param[in] ocpolarity: channel output polarity
825 only one parameter can be selected which is shown as below:
826 \arg TIMER_OC_POLARITY_HIGH: channel output polarity is high
827 \arg TIMER_OC_POLARITY_LOW: channel output polarity is low
828 \param[out] none
829 \retval none
830 */
timer_channel_output_polarity_config(uint32_t timer_periph,uint16_t channel,uint16_t ocpolarity)831 void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity)
832 {
833 uint32_t ctl;
834
835 switch(channel) {
836 /* configure TIMER_CH_0 */
837 case TIMER_CH_0:
838 ctl = TIMER_CHCTL2(timer_periph);
839 ctl &= (~(uint32_t)TIMER_CHCTL2_CH0P);
840 ctl |= (uint32_t)ocpolarity;
841 TIMER_CHCTL2(timer_periph) = ctl;
842 break;
843 /* configure TIMER_CH_1 */
844 case TIMER_CH_1:
845 ctl = TIMER_CHCTL2(timer_periph);
846 ctl &= (~(uint32_t)TIMER_CHCTL2_CH1P);
847 ctl |= (uint32_t)((uint32_t)ocpolarity << 4U);
848 TIMER_CHCTL2(timer_periph) = ctl;
849 break;
850 /* configure TIMER_CH_2 */
851 case TIMER_CH_2:
852 ctl = TIMER_CHCTL2(timer_periph);
853 ctl &= (~(uint32_t)TIMER_CHCTL2_CH2P);
854 ctl |= (uint32_t)((uint32_t)ocpolarity << 8U);
855 TIMER_CHCTL2(timer_periph) = ctl;
856 break;
857 /* configure TIMER_CH_3 */
858 case TIMER_CH_3:
859 ctl = TIMER_CHCTL2(timer_periph);
860 ctl &= (~(uint32_t)TIMER_CHCTL2_CH3P);
861 ctl |= (uint32_t)((uint32_t)ocpolarity << 12U);
862 TIMER_CHCTL2(timer_periph) = ctl;
863 break;
864 default:
865 break;
866 }
867 }
868
869 /*!
870 \brief configure TIMER channel enable state
871 \param[in] timer_periph: please refer to the following parameters
872 \param[in] channel:
873 only one parameter can be selected which is shown as below:
874 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
875 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
876 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
877 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
878 \param[in] state: TIMER channel enable state
879 only one parameter can be selected which is shown as below:
880 \arg TIMER_CCX_ENABLE: channel enable
881 \arg TIMER_CCX_DISABLE: channel disable
882 \param[out] none
883 \retval none
884 */
timer_channel_output_state_config(uint32_t timer_periph,uint16_t channel,uint32_t state)885 void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state)
886 {
887 uint32_t ctl;
888
889 switch(channel) {
890 /* configure TIMER_CH_0 */
891 case TIMER_CH_0:
892 ctl = TIMER_CHCTL2(timer_periph);
893 ctl &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
894 ctl |= (uint32_t)state;
895 TIMER_CHCTL2(timer_periph) = ctl;
896 break;
897 /* configure TIMER_CH_1 */
898 case TIMER_CH_1:
899 ctl = TIMER_CHCTL2(timer_periph);
900 ctl &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
901 ctl |= (uint32_t)((uint32_t)state << 4U);
902 TIMER_CHCTL2(timer_periph) = ctl;
903 break;
904 /* configure TIMER_CH_2 */
905 case TIMER_CH_2:
906 ctl = TIMER_CHCTL2(timer_periph);
907 ctl &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
908 ctl |= (uint32_t)((uint32_t)state << 8U);
909 TIMER_CHCTL2(timer_periph) = ctl;
910 break;
911 /* configure TIMER_CH_3 */
912 case TIMER_CH_3:
913 ctl = TIMER_CHCTL2(timer_periph);
914 ctl &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
915 ctl |= (uint32_t)((uint32_t)state << 12U);
916 TIMER_CHCTL2(timer_periph) = ctl;
917 break;
918 default:
919 break;
920 }
921 }
922
923 /*!
924 \brief initialize TIMER channel input parameter struct with a default value
925 \param[in] icpara: TIMER channel intput parameter struct
926 \param[out] none
927 \retval none
928 */
timer_channel_input_struct_para_init(timer_ic_parameter_struct * icpara)929 void timer_channel_input_struct_para_init(timer_ic_parameter_struct *icpara)
930 {
931 /* initialize the channel input parameter struct member with the default value */
932 icpara->icpolarity = TIMER_IC_POLARITY_RISING;
933 icpara->icselection = TIMER_IC_SELECTION_DIRECTTI;
934 icpara->icprescaler = TIMER_IC_PSC_DIV1;
935 icpara->icfilter = 0U;
936 }
937
938 /*!
939 \brief configure TIMER input capture parameter
940 \param[in] timer_periph: please refer to the following parameters
941 \param[in] channel:
942 only one parameter can be selected which is shown as below:
943 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
944 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
945 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
946 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
947 \param[in] icpara: TIMER channel intput parameter struct
948 icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING,TIMER_IC_POLARITY_BOTH_EDGE
949 icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI,TIMER_IC_SELECTION_ITS
950 icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
951 icfilter: 0~15
952 \param[out] none
953 \retval none
954 */
timer_input_capture_config(uint32_t timer_periph,uint16_t channel,timer_ic_parameter_struct * icpara)955 void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpara)
956 {
957 uint32_t ctl;
958
959 switch(channel) {
960 /* configure TIMER_CH_0 */
961 case TIMER_CH_0:
962 /* reset the CH0EN bit */
963 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
964
965 /* reset the CH0P and CH0NP bits */
966 ctl = TIMER_CHCTL2(timer_periph);
967 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
968 ctl |= (uint32_t)(icpara->icpolarity);
969 TIMER_CHCTL2(timer_periph) = ctl;
970 /* reset the CH0MS bit */
971 ctl = TIMER_CHCTL0(timer_periph);
972 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
973 ctl |= (uint32_t)(icpara->icselection);
974 TIMER_CHCTL0(timer_periph) = ctl;
975 /* reset the CH0CAPFLT bit */
976 ctl = TIMER_CHCTL0(timer_periph);
977 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
978 ctl |= (uint32_t)((uint32_t)(icpara->icfilter) << 4U);
979 TIMER_CHCTL0(timer_periph) = ctl;
980 /* set the CH0EN bit */
981 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
982 break;
983
984 /* configure TIMER_CH_1 */
985 case TIMER_CH_1:
986 /* reset the CH1EN bit */
987 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
988
989 /* reset the CH1P and CH1NP bits */
990 ctl = TIMER_CHCTL2(timer_periph);
991 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
992 ctl |= (uint32_t)((uint32_t)(icpara->icpolarity) << 4U);
993 TIMER_CHCTL2(timer_periph) = ctl;
994 /* reset the CH1MS bit */
995 ctl = TIMER_CHCTL0(timer_periph);
996 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
997 ctl |= (uint32_t)((uint32_t)(icpara->icselection) << 8U);
998 TIMER_CHCTL0(timer_periph) = ctl;
999 /* reset the CH1CAPFLT bit */
1000 ctl = TIMER_CHCTL0(timer_periph);
1001 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
1002 ctl |= (uint32_t)((uint32_t)(icpara->icfilter) << 12U);
1003 TIMER_CHCTL0(timer_periph) = ctl;
1004 /* set the CH1EN bit */
1005 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
1006 break;
1007 /* configure TIMER_CH_2 */
1008 case TIMER_CH_2:
1009 /* reset the CH2EN bit */
1010 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
1011
1012 /* reset the CH2P and CH2NP bits */
1013 ctl = TIMER_CHCTL2(timer_periph);
1014 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH2P | TIMER_CHCTL2_CH2NP));
1015 ctl |= (uint32_t)((uint32_t)(icpara->icpolarity) << 8U);
1016 TIMER_CHCTL2(timer_periph) = ctl;
1017 /* reset the CH2MS bit */
1018 ctl = TIMER_CHCTL1(timer_periph);
1019 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2MS);
1020 ctl |= (uint32_t)((uint32_t)(icpara->icselection));
1021 TIMER_CHCTL1(timer_periph) = ctl;
1022 /* reset the CH2CAPFLT bit */
1023 ctl = TIMER_CHCTL1(timer_periph);
1024 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2CAPFLT);
1025 ctl |= (uint32_t)((uint32_t)(icpara->icfilter) << 4U);
1026 TIMER_CHCTL1(timer_periph) = ctl;
1027 /* set the CH2EN bit */
1028 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH2EN;
1029 break;
1030 /* configure TIMER_CH_3 */
1031 case TIMER_CH_3:
1032 /* reset the CH3EN bit */
1033 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
1034
1035 /* reset the CH3P and CH3NP bits */
1036 ctl = TIMER_CHCTL2(timer_periph);
1037 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH3P | TIMER_CHCTL2_CH3NP));
1038 ctl |= (uint32_t)((uint32_t)(icpara->icpolarity) << 12U);
1039 TIMER_CHCTL2(timer_periph) = ctl;
1040 /* reset the CH3MS bit */
1041 ctl = TIMER_CHCTL1(timer_periph);
1042 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3MS);
1043 ctl |= (uint32_t)((uint32_t)(icpara->icselection) << 8U);
1044 TIMER_CHCTL1(timer_periph) = ctl;
1045 /* reset the CH3CAPFLT bit */
1046 ctl = TIMER_CHCTL1(timer_periph);
1047 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3CAPFLT);
1048 ctl |= (uint32_t)((uint32_t)(icpara->icfilter) << 12U);
1049 TIMER_CHCTL1(timer_periph) = ctl;
1050 /* set the CH3EN bit */
1051 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH3EN;
1052 break;
1053 default:
1054 break;
1055 }
1056 /* configure TIMER channel input capture prescaler value */
1057 timer_channel_input_capture_prescaler_config(timer_periph, channel, (uint16_t)(icpara->icprescaler));
1058 }
1059
1060 /*!
1061 \brief configure TIMER channel input capture prescaler value
1062 \param[in] timer_periph: please refer to the following parameters
1063 \param[in] channel:
1064 only one parameter can be selected which is shown as below:
1065 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
1066 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
1067 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
1068 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
1069 \param[in] prescaler: channel input capture prescaler value
1070 only one parameter can be selected which is shown as below:
1071 \arg TIMER_IC_PSC_DIV1: no prescaler
1072 \arg TIMER_IC_PSC_DIV2: divided by 2
1073 \arg TIMER_IC_PSC_DIV4: divided by 4
1074 \arg TIMER_IC_PSC_DIV8: divided by 8
1075 \param[out] none
1076 \retval none
1077 */
timer_channel_input_capture_prescaler_config(uint32_t timer_periph,uint16_t channel,uint16_t prescaler)1078 void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler)
1079 {
1080 uint32_t ctl;
1081
1082 switch(channel) {
1083 /* configure TIMER_CH_0 */
1084 case TIMER_CH_0:
1085 ctl = TIMER_CHCTL0(timer_periph);
1086 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0CAPPSC);
1087 ctl |= (uint32_t)prescaler;
1088 TIMER_CHCTL0(timer_periph) = ctl;
1089 break;
1090 /* configure TIMER_CH_1 */
1091 case TIMER_CH_1:
1092 ctl = TIMER_CHCTL0(timer_periph);
1093 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1CAPPSC);
1094 ctl |= ((uint32_t)prescaler << 8U);
1095 TIMER_CHCTL0(timer_periph) = ctl;
1096 break;
1097 /* configure TIMER_CH_2 */
1098 case TIMER_CH_2:
1099 ctl = TIMER_CHCTL1(timer_periph);
1100 ctl &= (~(uint32_t)TIMER_CHCTL1_CH2CAPPSC);
1101 ctl |= (uint32_t)prescaler;
1102 TIMER_CHCTL1(timer_periph) = ctl;
1103 break;
1104 /* configure TIMER_CH_3 */
1105 case TIMER_CH_3:
1106 ctl = TIMER_CHCTL1(timer_periph);
1107 ctl &= (~(uint32_t)TIMER_CHCTL1_CH3CAPPSC);
1108 ctl |= ((uint32_t)prescaler << 8U);
1109 TIMER_CHCTL1(timer_periph) = ctl;
1110 break;
1111 default:
1112 break;
1113 }
1114 }
1115
1116 /*!
1117 \brief read TIMER channel capture compare register value
1118 \param[in] timer_periph: please refer to the following parameters
1119 \param[in] channel:
1120 only one parameter can be selected which is shown as below:
1121 \arg TIMER_CH_0: TIMER channel0(TIMERx(x=1,2,8,11))
1122 \arg TIMER_CH_1: TIMER channel1(TIMERx(x=1,2,8,11))
1123 \arg TIMER_CH_2: TIMER channel2(TIMERx(x=1,2))
1124 \arg TIMER_CH_3: TIMER channel3(TIMERx(x=1,2))
1125 \param[out] none
1126 \retval channel capture compare register value
1127 */
timer_channel_capture_value_register_read(uint32_t timer_periph,uint16_t channel)1128 uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel)
1129 {
1130 uint32_t count_value = 0U;
1131
1132 switch(channel) {
1133 /* read TIMER channel 0 capture compare register value */
1134 case TIMER_CH_0:
1135 count_value = TIMER_CH0CV(timer_periph);
1136 break;
1137 /* read TIMER channel 1 capture compare register value */
1138 case TIMER_CH_1:
1139 count_value = TIMER_CH1CV(timer_periph);
1140 break;
1141 /* read TIMER channel 2 capture compare register value */
1142 case TIMER_CH_2:
1143 count_value = TIMER_CH2CV(timer_periph);
1144 break;
1145 /* read TIMER channel 3 capture compare register value */
1146 case TIMER_CH_3:
1147 count_value = TIMER_CH3CV(timer_periph);
1148 break;
1149 default:
1150 break;
1151 }
1152 return (count_value);
1153 }
1154
1155 /*!
1156 \brief configure TIMER input pwm capture function
1157 \param[in] timer_periph: TIMERx(x=1,2,8,11)
1158 \param[in] channel:
1159 only one parameter can be selected which is shown as below:
1160 \arg TIMER_CH_0: TIMER channel0
1161 \arg TIMER_CH_1: TIMER channel1
1162 \param[in] icpwm:TIMER channel intput pwm parameter struct
1163 icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING
1164 icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI
1165 icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
1166 icfilter: 0~15
1167 \param[out] none
1168 \retval none
1169 */
timer_input_pwm_capture_config(uint32_t timer_periph,uint16_t channel,timer_ic_parameter_struct * icpwm)1170 void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct *icpwm)
1171 {
1172 uint32_t ctl;
1173
1174 uint16_t icpolarity = 0x0U;
1175 uint16_t icselection = 0x0U;
1176
1177 /* Set channel input polarity */
1178 if(TIMER_IC_POLARITY_RISING == icpwm->icpolarity) {
1179 icpolarity = TIMER_IC_POLARITY_FALLING;
1180 } else {
1181 icpolarity = TIMER_IC_POLARITY_RISING;
1182 }
1183 /* Set channel input mode selection */
1184 if(TIMER_IC_SELECTION_DIRECTTI == icpwm->icselection) {
1185 icselection = TIMER_IC_SELECTION_INDIRECTTI;
1186 } else {
1187 icselection = TIMER_IC_SELECTION_DIRECTTI;
1188 }
1189
1190 if(TIMER_CH_0 == channel) {
1191 /* reset the CH0EN bit */
1192 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
1193 /* set the CH0P and CH0NP bits */
1194 ctl = TIMER_CHCTL2(timer_periph);
1195 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
1196 ctl |= (uint32_t)(icpwm->icpolarity);
1197 TIMER_CHCTL2(timer_periph) = ctl;
1198 /* set the CH0MS bit */
1199 ctl = TIMER_CHCTL0(timer_periph);
1200 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
1201 ctl |= (uint32_t)(icpwm->icselection);
1202 TIMER_CHCTL0(timer_periph) = ctl;
1203 /* set the CH0CAPFLT bit */
1204 ctl = TIMER_CHCTL0(timer_periph);
1205 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
1206 ctl |= ((uint32_t)(icpwm->icfilter) << 4U);
1207 TIMER_CHCTL0(timer_periph) = ctl;
1208 /* set the CH0EN bit */
1209 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
1210 /* configure TIMER channel input capture prescaler value */
1211 timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_0, (uint16_t)(icpwm->icprescaler));
1212
1213 /* reset the CH1EN bit */
1214 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
1215 /* set the CH1P and CH1NP bits */
1216 ctl = TIMER_CHCTL2(timer_periph);
1217 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
1218 ctl |= (uint32_t)((uint32_t)icpolarity << 4U);
1219 TIMER_CHCTL2(timer_periph) = ctl;
1220
1221 /* set the CH1MS bit */
1222 ctl = TIMER_CHCTL0(timer_periph);
1223 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
1224 ctl |= (uint32_t)((uint32_t)icselection << 8U);
1225 TIMER_CHCTL0(timer_periph) = ctl;
1226
1227 /* set the CH1CAPFLT bit */
1228 ctl = TIMER_CHCTL0(timer_periph);
1229 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
1230 ctl |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
1231 TIMER_CHCTL0(timer_periph) = ctl;
1232
1233 /* set the CH1EN bit */
1234 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
1235 /* configure TIMER channel input capture prescaler value */
1236 timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_1, (uint16_t)(icpwm->icprescaler));
1237 } else {
1238 /* reset the CH1EN bit */
1239 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
1240 /* set the CH1P and CH1NP bits */
1241 ctl = TIMER_CHCTL2(timer_periph);
1242 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
1243 ctl |= (uint32_t)((uint32_t)(icpwm->icpolarity) << 4U);
1244 TIMER_CHCTL2(timer_periph) = ctl;
1245 /* set the CH1MS bit */
1246 ctl = TIMER_CHCTL0(timer_periph);
1247 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
1248 ctl |= (uint32_t)((uint32_t)(icpwm->icselection) << 8U);
1249 TIMER_CHCTL0(timer_periph) = ctl;
1250 /* set the CH1CAPFLT bit */
1251 ctl = TIMER_CHCTL0(timer_periph);
1252 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
1253 ctl |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
1254 TIMER_CHCTL0(timer_periph) = ctl;
1255 /* set the CH1EN bit */
1256 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
1257 /* configure TIMER channel input capture prescaler value */
1258 timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_1, (uint16_t)(icpwm->icprescaler));
1259
1260 /* reset the CH0EN bit */
1261 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
1262 /* set the CH0P and CH0NP bits */
1263 ctl = TIMER_CHCTL2(timer_periph);
1264 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
1265 ctl |= (uint32_t)icpolarity;
1266 TIMER_CHCTL2(timer_periph) = ctl;
1267 /* set the CH0MS bit */
1268 ctl = TIMER_CHCTL0(timer_periph);
1269 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
1270 ctl |= (uint32_t)icselection;
1271 TIMER_CHCTL0(timer_periph) = ctl;
1272 /* set the CH0CAPFLT bit */
1273 ctl = TIMER_CHCTL0(timer_periph);
1274 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
1275 ctl |= ((uint32_t)(icpwm->icfilter) << 4U);
1276 TIMER_CHCTL0(timer_periph) = ctl;
1277 /* set the CH0EN bit */
1278 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
1279 /* configure TIMER channel input capture prescaler value */
1280 timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_0, (uint16_t)(icpwm->icprescaler));
1281 }
1282 }
1283
1284 /*!
1285 \brief configure TIMER hall sensor mode
1286 \param[in] timer_periph: TIMERx(x=1,2)
1287 \param[in] hallmode:
1288 only one parameter can be selected which is shown as below:
1289 \arg TIMER_HALLINTERFACE_ENABLE: TIMER hall sensor mode enable
1290 \arg TIMER_HALLINTERFACE_DISABLE: TIMER hall sensor mode disable
1291 \param[out] none
1292 \retval none
1293 */
timer_hall_mode_config(uint32_t timer_periph,uint32_t hallmode)1294 void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
1295 {
1296 if(TIMER_HALLINTERFACE_ENABLE == hallmode) {
1297 TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_TI0S;
1298 } else if(TIMER_HALLINTERFACE_DISABLE == hallmode) {
1299 TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_TI0S;
1300 } else {
1301 /* illegal parameters */
1302 }
1303 }
1304
1305 /*!
1306 \brief select TIMER input trigger source
1307 \param[in] timer_periph: please refer to the following parameters
1308 \param[in] intrigger:
1309 only one parameter can be selected which is shown as below:
1310 \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0 (TIMERx(x=1,2,8))
1311 \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1 (TIMERx(x=8,11))
1312 \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2 (TIMERx(x=11)
1313 \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector (TIMERx(x=1,2,8,11))
1314 \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0 (TIMERx(x=1,2,,8,11))
1315 \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1 (TIMERx(x=1,2,8,11))
1316 \arg TIMER_SMCFG_TRGSEL_ETIFP: external trigger (TIMERx(x=1,2,8,11))
1317 \param[out] none
1318 \retval none
1319 */
timer_input_trigger_source_select(uint32_t timer_periph,uint32_t intrigger)1320 void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger)
1321 {
1322 uint32_t ctl;
1323
1324 ctl = TIMER_SMCFG(timer_periph);
1325 ctl &= (~(uint32_t)TIMER_SMCFG_TRGS);
1326 ctl |= (uint32_t)intrigger;
1327 TIMER_SMCFG(timer_periph) = ctl;
1328 }
1329
1330 /*!
1331 \brief select TIMER master mode output trigger source
1332 \param[in] timer_periph: please refer to the following parameters
1333 \param[in] outrigger:
1334 only one parameter can be selected which is shown as below:
1335 \arg TIMER_TRI_OUT_SRC_RESET: the UPG bit as trigger output (TIMERx(x=1,2,5,6))
1336 \arg TIMER_TRI_OUT_SRC_ENABLE: the counter enable signal TIMER_CTL0_CEN as trigger output (TIMERx(x=1,2,5,6))
1337 \arg TIMER_TRI_OUT_SRC_UPDATE: update event as trigger output (TIMERx(x=1,2,5,6))
1338 \arg TIMER_TRI_OUT_SRC_CH0: a capture or a compare match occurred in channal0 as trigger output TRGO (TIMERx(x=1,2))
1339 \arg TIMER_TRI_OUT_SRC_O0CPRE: O0CPRE as trigger output (TIMERx(x=1,2))
1340 \arg TIMER_TRI_OUT_SRC_O1CPRE: O1CPRE as trigger output (TIMERx(x=1,2))
1341 \arg TIMER_TRI_OUT_SRC_O2CPRE: O2CPRE as trigger output (TIMERx(x=1,2))
1342 \arg TIMER_TRI_OUT_SRC_O3CPRE: O3CPRE as trigger output (TIMERx(x=1,2))
1343 \param[out] none
1344 \retval none
1345 */
timer_master_output_trigger_source_select(uint32_t timer_periph,uint32_t outrigger)1346 void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger)
1347 {
1348 uint32_t ctl;
1349
1350 ctl = TIMER_CTL1(timer_periph);
1351 ctl &= (~(uint32_t)TIMER_CTL1_MMC);
1352 ctl |= (uint32_t)outrigger;
1353 TIMER_CTL1(timer_periph) = ctl;
1354 }
1355
1356 /*!
1357 \brief select TIMER slave mode
1358 \param[in] timer_periph: please refer to the following parameters
1359 \param[in] slavemode:
1360 only one parameter can be selected which is shown as below:
1361 \arg TIMER_SLAVE_MODE_DISABLE: slave mode disable
1362 \arg TIMER_ENCODER_MODE0: encoder mode 0 (TIMERx(x=1,2))
1363 \arg TIMER_ENCODER_MODE1: encoder mode 1 (TIMERx(x=1,2))
1364 \arg TIMER_ENCODER_MODE2: encoder mode 2 (TIMERx(x=1,2))
1365 \arg TIMER_SLAVE_MODE_RESTART: restart mode (TIMERx(x=1,2,8,11))
1366 \arg TIMER_SLAVE_MODE_PAUSE: pause mode (TIMERx(x=1,2,8,11))
1367 \arg TIMER_SLAVE_MODE_EVENT: event mode (TIMERx(x=1,2,8,11))
1368 \arg TIMER_SLAVE_MODE_EXTERNAL0: external clock mode 0 (TIMERx(x=1,2,8,11))
1369 \param[out] none
1370 \retval none
1371 */
1372
timer_slave_mode_select(uint32_t timer_periph,uint32_t slavemode)1373 void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
1374 {
1375 uint32_t ctl;
1376
1377 ctl = TIMER_SMCFG(timer_periph);
1378 ctl &= (~(uint32_t)TIMER_SMCFG_SMC);
1379 ctl |= (uint32_t)slavemode;
1380 TIMER_SMCFG(timer_periph) = ctl;
1381 }
1382
1383 /*!
1384 \brief configure TIMER master slave mode
1385 \param[in] timer_periph: TIMERx(x=1,2,8,11)
1386 \param[in] masterslave:
1387 only one parameter can be selected which is shown as below:
1388 \arg TIMER_MASTER_SLAVE_MODE_ENABLE: master slave mode enable
1389 \arg TIMER_MASTER_SLAVE_MODE_DISABLE: master slave mode disable
1390 \param[out] none
1391 \retval none
1392 */
timer_master_slave_mode_config(uint32_t timer_periph,uint32_t masterslave)1393 void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
1394 {
1395 if(TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave) {
1396 TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_MSM;
1397 } else if(TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave) {
1398 TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_MSM;
1399 } else {
1400 /* illegal parameters */
1401 }
1402 }
1403
1404 /*!
1405 \brief configure TIMER external trigger input
1406 \param[in] timer_periph: TIMERx(x=1,2)
1407 \param[in] extprescaler:
1408 only one parameter can be selected which is shown as below:
1409 \arg TIMER_EXT_TRI_PSC_OFF: no divided
1410 \arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
1411 \arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
1412 \arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
1413 \param[in] extpolarity:
1414 only one parameter can be selected which is shown as below:
1415 \arg TIMER_ETP_FALLING: active low or falling edge active
1416 \arg TIMER_ETP_RISING: active high or rising edge active
1417 \param[in] extfilter: a value between 0 and 15
1418 \param[out] none
1419 \retval none
1420 */
timer_external_trigger_config(uint32_t timer_periph,uint32_t extprescaler,uint32_t extpolarity,uint32_t extfilter)1421 void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
1422 {
1423 uint32_t ctl;
1424
1425 ctl = TIMER_SMCFG(timer_periph);
1426 ctl &= (~(uint32_t)(TIMER_SMCFG_ETP | TIMER_SMCFG_ETPSC | TIMER_SMCFG_ETFC));
1427 ctl |= (uint32_t)(extprescaler | extpolarity);
1428 ctl |= (uint32_t)(extfilter << 8U);
1429 TIMER_SMCFG(timer_periph) = ctl;
1430 }
1431
1432 /*!
1433 \brief configure TIMER quadrature decoder mode
1434 \param[in] timer_periph: TIMERx(x=1,2)
1435 \param[in] decomode:
1436 only one parameter can be selected which is shown as below:
1437 \arg TIMER_ENCODER_MODE0: counter counts on CI0FE0 edge depending on CI1FE1 level
1438 \arg TIMER_ENCODER_MODE1: counter counts on CI1FE1 edge depending on CI0FE0 level
1439 \arg TIMER_ENCODER_MODE2: counter counts on both CI0FE0 and CI1FE1 edges depending on the level of the other input
1440 \param[in] ic0polarity:
1441 only one parameter can be selected which is shown as below:
1442 \arg TIMER_IC_POLARITY_RISING: capture rising edge
1443 \arg TIMER_IC_POLARITY_FALLING: capture falling edge
1444 \arg TIMER_IC_POLARITY_BOTH_EDGE: active both edge
1445 \param[in] ic1polarity:
1446 only one parameter can be selected which is shown as below:
1447 \arg TIMER_IC_POLARITY_RISING: capture rising edge
1448 \arg TIMER_IC_POLARITY_FALLING: capture falling edge
1449 \arg TIMER_IC_POLARITY_BOTH_EDGE: active both edge
1450 \param[out] none
1451 \retval none
1452 */
timer_quadrature_decoder_mode_config(uint32_t timer_periph,uint32_t decomode,uint16_t ic0polarity,uint16_t ic1polarity)1453 void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity)
1454 {
1455 uint32_t ctl;
1456 /* configure the quadrature decoder mode */
1457 ctl = TIMER_SMCFG(timer_periph);
1458 ctl &= (~(uint32_t)TIMER_SMCFG_SMC);
1459 ctl |= (uint32_t)decomode;
1460 TIMER_SMCFG(timer_periph) = ctl;
1461 /* configure input capture selection */
1462 ctl = TIMER_CHCTL0(timer_periph);
1463 ctl &= (uint32_t)(((~(uint32_t)TIMER_CHCTL0_CH0MS)) & ((~(uint32_t)TIMER_CHCTL0_CH1MS)));
1464 ctl |= (uint32_t)(TIMER_IC_SELECTION_DIRECTTI | ((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U));
1465 TIMER_CHCTL0(timer_periph) = ctl;
1466 /* configure channel input capture polarity */
1467 ctl = TIMER_CHCTL2(timer_periph);
1468 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
1469 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
1470 ctl |= ((uint32_t)ic0polarity | ((uint32_t)ic1polarity << 4U));
1471 TIMER_CHCTL2(timer_periph) = ctl;
1472 }
1473
1474 /*!
1475 \brief configure TIMER the internal trigger as external clock input
1476 \param[in] timer_periph: please refer to the following parameters
1477 \param[in] intrigger:
1478 only one parameter can be selected which is shown as below:
1479 \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0 (TIMERx(x=1,2,8))
1480 \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1 (TIMERx(x=8,11))
1481 \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2 (TIMERx(x=11))
1482 \param[out] none
1483 \retval none
1484 */
timer_internal_trigger_as_external_clock_config(uint32_t timer_periph,uint32_t intrigger)1485 void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger)
1486 {
1487 uint32_t ctl;
1488
1489 ctl = TIMER_SMCFG(timer_periph);
1490 ctl &= ~(uint32_t)TIMER_SMCFG_SMC;
1491 ctl |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
1492 TIMER_SMCFG(timer_periph) = ctl;
1493 }
1494
1495 /*!
1496 \brief configure TIMER the external trigger as external clock input
1497 \param[in] timer_periph: TIMERx(x=1,2,8,11)
1498 \param[in] extrigger:
1499 only one parameter can be selected which is shown as below:
1500 \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector TIMERx(x=1,2,8,11)
1501 \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0 TIMERx(x=1,2,8,11)
1502 \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1 TIMERx(x=1,2,8,11)
1503 \param[in] extpolarity:
1504 only one parameter can be selected which is shown as below:
1505 \arg TIMER_IC_POLARITY_RISING: active high or rising edge active
1506 \arg TIMER_IC_POLARITY_FALLING: active low or falling edge active
1507 \arg TIMER_IC_POLARITY_BOTH_EDGE: active both edge
1508 \param[in] extfilter: a value between 0 and 15
1509 \param[out] none
1510 \retval none
1511 */
timer_external_trigger_as_external_clock_config(uint32_t timer_periph,uint32_t extrigger,uint16_t extpolarity,uint32_t extfilter)1512 void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity, uint32_t extfilter)
1513 {
1514 uint32_t ctl;
1515
1516 if(TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger) {
1517 /* reset the CH1EN bit */
1518 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
1519 /* set the CH1NP bit */
1520 ctl = TIMER_CHCTL2(timer_periph);
1521 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
1522 ctl |= (uint32_t)((uint32_t)extpolarity << 4U);
1523 TIMER_CHCTL2(timer_periph) = ctl;
1524 /* set the CH1MS bit */
1525 ctl = TIMER_CHCTL0(timer_periph);
1526 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
1527 ctl |= (uint32_t)((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U);
1528 TIMER_CHCTL0(timer_periph) = ctl;
1529 /* set the CH1CAPFLT bit */
1530 ctl = TIMER_CHCTL0(timer_periph);
1531 ctl &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
1532 ctl |= (uint32_t)(extfilter << 12U);
1533 TIMER_CHCTL0(timer_periph) = ctl;
1534 /* set the CH1EN bit */
1535 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
1536 } else {
1537 /* reset the CH0EN bit */
1538 TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
1539 /* set the CH0P and CH0NP bits */
1540 ctl = TIMER_CHCTL2(timer_periph);
1541 ctl &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
1542 ctl |= (uint32_t)extpolarity;
1543 TIMER_CHCTL2(timer_periph) = ctl;
1544 /* set the CH0MS bit */
1545 ctl = TIMER_CHCTL0(timer_periph);
1546 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
1547 ctl |= (uint32_t)TIMER_IC_SELECTION_DIRECTTI;
1548 TIMER_CHCTL0(timer_periph) = ctl;
1549 /* reset the CH0CAPFLT bit */
1550 ctl = TIMER_CHCTL0(timer_periph);
1551 ctl &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
1552 ctl |= (uint32_t)(extfilter << 4U);
1553 TIMER_CHCTL0(timer_periph) = ctl;
1554 /* set the CH0EN bit */
1555 TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
1556 }
1557 /* select TIMER input trigger source */
1558 timer_input_trigger_source_select(timer_periph, extrigger);
1559 /* set the SMC bit */
1560 ctl = TIMER_SMCFG(timer_periph);
1561 ctl &= (~(uint32_t)TIMER_SMCFG_SMC);
1562 ctl |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
1563 TIMER_SMCFG(timer_periph) = ctl;
1564 }
1565
1566 /*!
1567 \brief configure TIMER the external clock mode0
1568 \param[in] timer_periph: TIMERx(x=1,2,8,11)
1569 \param[in] extprescaler:
1570 only one parameter can be selected which is shown as below:
1571 \arg TIMER_EXT_TRI_PSC_OFF: no divided
1572 \arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
1573 \arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
1574 \arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
1575 \param[in] extpolarity:
1576 only one parameter can be selected which is shown as below:
1577 \arg TIMER_ETP_FALLING: active low or falling edge active
1578 \arg TIMER_ETP_RISING: active high or rising edge active
1579 \param[in] extfilter: a value between 0 and 15
1580 \param[out] none
1581 \retval none
1582 */
timer_external_clock_mode0_config(uint32_t timer_periph,uint32_t extprescaler,uint32_t extpolarity,uint32_t extfilter)1583 void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
1584 {
1585 uint32_t ctl;
1586
1587 /* configure TIMER external trigger input */
1588 timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
1589
1590 /* set the SMC bit,TRGS bit */
1591 ctl = TIMER_SMCFG(timer_periph);
1592 ctl &= (~(uint32_t)(TIMER_SMCFG_SMC | TIMER_SMCFG_TRGS));
1593 ctl |= (uint32_t)(TIMER_SLAVE_MODE_EXTERNAL0 | TIMER_SMCFG_TRGSEL_ETIFP);
1594 TIMER_SMCFG(timer_periph) = ctl;
1595 }
1596
1597 /*!
1598 \brief configure TIMER the external clock mode1
1599 \param[in] timer_periph: TIMERx(x=1,2)
1600 \param[in] extprescaler:
1601 only one parameter can be selected which is shown as below:
1602 \arg TIMER_EXT_TRI_PSC_OFF: no divided
1603 \arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
1604 \arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
1605 \arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
1606 \param[in] extpolarity:
1607 only one parameter can be selected which is shown as below:
1608 \arg TIMER_ETP_FALLING: active low or falling edge active
1609 \arg TIMER_ETP_RISING: active high or rising edge active
1610 \param[in] extfilter: a value between 0 and 15
1611 \param[out] none
1612 \retval none
1613 */
timer_external_clock_mode1_config(uint32_t timer_periph,uint32_t extprescaler,uint32_t extpolarity,uint32_t extfilter)1614 void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter)
1615 {
1616 /* configure TIMER external trigger input */
1617 timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
1618
1619 TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_SMC1;
1620 }
1621
1622 /*!
1623 \brief disable TIMER the external clock mode1
1624 \param[in] timer_periph: TIMERx(x=1,2)
1625 \param[out] none
1626 \retval none
1627 */
timer_external_clock_mode1_disable(uint32_t timer_periph)1628 void timer_external_clock_mode1_disable(uint32_t timer_periph)
1629 {
1630 TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC1;
1631 }
1632
1633
1634 /*!
1635 \brief configure TIMER channel remap function
1636 \param[in] timer_periph: please refer to the following parameters
1637 \param[in] remap:
1638 only one parameter can be selected which is shown as below:
1639 \arg TIMER8_CI0_RMP_GPIO: timer8 channel 0 input is connected to GPIO(TIMER8_CH0) TIMERx(x=8)
1640 \arg TIMER8_CI0_RMP_LXTAL: timer8 channel 0 input is connected to the LXTAL TIMERx(x=8)
1641 \arg TIMER8_CI0_RMP_HXTAL_DIV32: timer8 channel 0 input is connected to HXTAL/32 clock TIMERx(x=8)
1642 \arg TIMER8_CI0_RMP_CKOUTSEL: timer8 channel 0 input is connected to CKOUTSEL TIMERx(x=8)
1643
1644 \arg TIMER11_CI0_RMP_GPIO: timer11 channel 0 input is connected to GPIO(TIMER11_CH0) TIMERx(x=11)
1645 \arg TIMER11_CI0_RMP_IRC32K: timer11 channel 0 input is connected to the IRC32K TIMERx(x=11)
1646 \arg TIMER11_CI0_RMP_LXTAL: timer11 channel 0 input is connected to LXTAL clock TIMERx(x=11)
1647 \arg TIMER11_CI0_RMP_RTC_OUT: timer11 channel 0 input is connected to RTC_OUT TIMERx(x=11)
1648 \param[out] none
1649 \retval none
1650 */
timer_channel_remap_config(uint32_t timer_periph,uint32_t remap)1651 void timer_channel_remap_config(uint32_t timer_periph, uint32_t remap)
1652 {
1653 TIMER_IRMP(timer_periph) = (uint32_t)remap;
1654 }
1655 /*!
1656 \brief configure TIMER write CHxVAL register selection
1657 \param[in] timer_periph: TIMERx(x=1,2,8,11)
1658 \param[in] ccsel:
1659 only one parameter can be selected which is shown as below:
1660 \arg TIMER_CHVSEL_DISABLE: no effect
1661 \arg TIMER_CHVSEL_ENABLE: when write the CHxVAL register, if the write value is same as the CHxVAL value, the write access is ignored
1662 \param[out] none
1663 \retval none
1664 */
timer_write_chxval_register_config(uint32_t timer_periph,uint16_t ccsel)1665 void timer_write_chxval_register_config(uint32_t timer_periph, uint16_t ccsel)
1666 {
1667 if(TIMER_CHVSEL_ENABLE == ccsel) {
1668 TIMER_CFG(timer_periph) |= (uint32_t)TIMER_CFG_CHVSEL;
1669 } else if(TIMER_CHVSEL_DISABLE == ccsel) {
1670 TIMER_CFG(timer_periph) &= ~(uint32_t)TIMER_CFG_CHVSEL;
1671 } else {
1672 /* illegal parameters */
1673 }
1674 }
1675
1676 /*!
1677 \brief get TIMER flags
1678 \param[in] timer_periph: please refer to the following parameters
1679 \param[in] flag: the timer interrupt flags
1680 only one parameter can be selected which is shown as below:
1681 \arg TIMER_FLAG_UP: update flag,TIMERx(x=1,2,5,6,8,11)
1682 \arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=1,2,8,11)
1683 \arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=1,2,8,11)
1684 \arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=1,2)
1685 \arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=1,2)
1686 \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=1,2,8,11)
1687 \arg TIMER_FLAG_CH0O: channel 0 overcapture flag,TIMERx(x=1,2,8,11)
1688 \arg TIMER_FLAG_CH1O: channel 1 overcapture flag,TIMERx(x=1,2,8,11)
1689 \arg TIMER_FLAG_CH2O: channel 2 overcapture flag,TIMERx(x=1,2)
1690 \arg TIMER_FLAG_CH3O: channel 3 overcapture flag,TIMERx(x=1,2)
1691 \param[out] none
1692 \retval FlagStatus: SET or RESET
1693 */
timer_flag_get(uint32_t timer_periph,uint32_t flag)1694 FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
1695 {
1696 if(RESET != (TIMER_INTF(timer_periph) & flag)) {
1697 return SET;
1698 } else {
1699 return RESET;
1700 }
1701 }
1702
1703 /*!
1704 \brief clear TIMER flags
1705 \param[in] timer_periph: please refer to the following parameters
1706 \param[in] flag: the timer interrupt flags
1707 only one parameter can be selected which is shown as below:
1708 \arg TIMER_FLAG_UP: update flag,TIMERx(x=1,2,5,6,8,11)
1709 \arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=1,2,8,11)
1710 \arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=1,2,8,11)
1711 \arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=1,2)
1712 \arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=1,2)
1713 \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=1,2,8,11)
1714 \arg TIMER_FLAG_CH0O: channel 0 overcapture flag,TIMERx(x=1,2,8,11)
1715 \arg TIMER_FLAG_CH1O: channel 1 overcapture flag,TIMERx(x=1,2,8,11)
1716 \arg TIMER_FLAG_CH2O: channel 2 overcapture flag,TIMERx(x=1,2)
1717 \arg TIMER_FLAG_CH3O: channel 3 overcapture flag,TIMERx(x=1,2)
1718 \param[out] none
1719 \retval none
1720 */
timer_flag_clear(uint32_t timer_periph,uint32_t flag)1721 void timer_flag_clear(uint32_t timer_periph, uint32_t flag)
1722 {
1723 TIMER_INTF(timer_periph) = (~(uint32_t)flag);
1724 }
1725
1726 /*!
1727 \brief enable the TIMER interrupt
1728 \param[in] timer_periph: please refer to the following parameters
1729 \param[in] interrupt: timer interrupt enable source
1730 only one parameter can be selected which is shown as below:
1731 \arg TIMER_INT_UP: update interrupt enable, TIMERx(x=1,2,3,6,8,11)
1732 \arg TIMER_INT_CH0: channel 0 interrupt enable, TIMERx(x=1,2,8,11)
1733 \arg TIMER_INT_CH1: channel 1 interrupt enable, TIMERx(x=1,2,8,11)
1734 \arg TIMER_INT_CH2: channel 2 interrupt enable, TIMERx(x=1,2)
1735 \arg TIMER_INT_CH3: channel 3 interrupt enable, TIMERx(x=1,2)
1736 \arg TIMER_INT_TRG: trigger interrupt enable, TIMERx(x=1,2,8,11)
1737 \param[out] none
1738 \retval none
1739 */
timer_interrupt_enable(uint32_t timer_periph,uint32_t interrupt)1740 void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
1741 {
1742 TIMER_DMAINTEN(timer_periph) |= (uint32_t) interrupt;
1743 }
1744
1745 /*!
1746 \brief disable the TIMER interrupt
1747 \param[in] timer_periph: please refer to the following parameters
1748 \param[in] interrupt: timer interrupt source disable
1749 only one parameter can be selected which is shown as below:
1750 \arg TIMER_INT_UP: update interrupt enable, TIMERx(x=1,2,3,6,8,11)
1751 \arg TIMER_INT_CH0: channel 0 interrupt enable, TIMERx(x=1,2,8,11)
1752 \arg TIMER_INT_CH1: channel 1 interrupt enable, TIMERx(x=1,2,8,11)
1753 \arg TIMER_INT_CH2: channel 2 interrupt enable, TIMERx(x=1,2)
1754 \arg TIMER_INT_CH3: channel 3 interrupt enable, TIMERx(x=1,2)
1755 \arg TIMER_INT_TRG: trigger interrupt enable, TIMERx(x=1,2,8,11)
1756 \param[out] none
1757 \retval none
1758 */
timer_interrupt_disable(uint32_t timer_periph,uint32_t interrupt)1759 void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt)
1760 {
1761 TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt);
1762 }
1763
1764 /*!
1765 \brief get timer interrupt flag
1766 \param[in] timer_periph: please refer to the following parameters
1767 \param[in] int_flag: the timer interrupt flag
1768 only one parameter can be selected which is shown as below:
1769 \arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=1,2,5,6,8,11)
1770 \arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=1,2,8,11)
1771 \arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=1,2,8,11)
1772 \arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=1,2)
1773 \arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=1,2)
1774 \arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=1,2,8,11)
1775 \param[out] none
1776 \retval FlagStatus: SET or RESET
1777 */
timer_interrupt_flag_get(uint32_t timer_periph,uint32_t int_flag)1778 FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t int_flag)
1779 {
1780 uint32_t val;
1781 val = (TIMER_DMAINTEN(timer_periph) & int_flag);
1782 if((RESET != (TIMER_INTF(timer_periph) & int_flag)) && (RESET != val)) {
1783 return SET;
1784 } else {
1785 return RESET;
1786 }
1787 }
1788
1789 /*!
1790 \brief clear TIMER interrupt flag
1791 \param[in] timer_periph: please refer to the following parameters
1792 \param[in] int_flag: the timer interrupt flag
1793 only one parameter can be selected which is shown as below:
1794 \arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=1,2,5,6,8,11)
1795 \arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=1,2,8,11)
1796 \arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=1,2,8,11)
1797 \arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=1,2)
1798 \arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=1,2)
1799 \arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=1,2,8,11)
1800 \param[out] none
1801 \retval none
1802 */
timer_interrupt_flag_clear(uint32_t timer_periph,uint32_t int_flag)1803 void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t int_flag)
1804 {
1805 TIMER_INTF(timer_periph) = (~(uint32_t)int_flag);
1806 }
1807