1 /**************************************************************************//**
2 * @file timer_pwm.h
3 * @version V1.01
4 * @brief M2L31 series Timer PWM Controller(Timer PWM) driver header file
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #ifndef __TIMER_PWM_H__
10 #define __TIMER_PWM_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
18 /** @addtogroup Standard_Driver Standard Driver
19 @{
20 */
21
22 /** @addtogroup TIMER_PWM_Driver TIMER PWM Driver
23 @{
24 */
25
26 /** @addtogroup TIMER_PWM_EXPORTED_CONSTANTS TIMER PWM Exported Constants
27 @{
28 */
29 /*---------------------------------------------------------------------------------------------------------*/
30 /* TPWM Output Channel Constant Definitions */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define TPWM_CH0 (BIT0) /*!< Indicate PWMx_CH0 \hideinitializer */
33
34 /*---------------------------------------------------------------------------------------------------------*/
35 /* TPWM Output Channel Selection Definitions */
36 /*---------------------------------------------------------------------------------------------------------*/
37 #define TPWM_TOUT_PIN_FROM_TX (0UL << TIMER_PWMPOCTL_POSEL_Pos) /*!< Indicate PWMx output to Tx pins \hideinitializer */
38 #define TPWM_TOUT_PIN_FROM_TX_EXT (1UL << TIMER_PWMPOCTL_POSEL_Pos) /*!< Indicate PWMx output to Tx_ext pins \hideinitializer */
39
40 /*---------------------------------------------------------------------------------------------------------*/
41 /* TPWM Counter Mode Constant Definitions */
42 /*---------------------------------------------------------------------------------------------------------*/
43 #define TPWM_AUTO_RELOAD_MODE (0UL) /*!< Auto-reload mode \hideinitializer */
44 #define TPWM_ONE_SHOT_MODE (1UL) /*!< One-shot mode \hideinitializer */
45
46 /*---------------------------------------------------------------------------------------------------------*/
47 /* TPWM Trigger EADC/DAC/PDMA/LPADC Source Select Constant Definitions */
48 /*---------------------------------------------------------------------------------------------------------*/
49 #define TPWM_TRIGGER_AT_PERIOD_POINT (0UL << TIMER_PWMTRGCTL_TRGSEL_Pos) /*!< Timer PWM trigger EADC/DAC/PDMA/LPADC while counter period point event occurred \hideinitializer */
50 #define TPWM_TRIGGER_AT_COMPARE_POINT (1UL << TIMER_PWMTRGCTL_TRGSEL_Pos) /*!< Timer PWM trigger EADC/DAC/PDMA/LPADC while counter compare point event occurred \hideinitializer */
51 #define TPWM_TRIGGER_AT_PERIOD_OR_COMPARE_POINT (2UL << TIMER_PWMTRGCTL_TRGSEL_Pos) /*!< Timer PWM trigger EADC/DAC/PDMA/LPADC while counter period or compare point event occurred \hideinitializer */
52
53 /*---------------------------------------------------------------------------------------------------------*/
54 /* Interrupt Flag Accumulator Constant Definitions */
55 /*---------------------------------------------------------------------------------------------------------*/
56 #define TPWM_IFA_PERIOD_POINT (1U) /*!< Timer PWM counter equal to period \hideinitializer */
57 #define TPWM_IFA_COMPARE_UP_COUNT_POINT (2U) /*!< Timer PWM counter up count to comparator value \hideinitializer */
58
59 /*@}*/ /* end of group TIMER_PWM_EXPORTED_CONSTANTS */
60
61
62 /** @addtogroup TIMER_PWM_EXPORTED_FUNCTIONS TIMER PWM Exported Functions
63 @{
64 */
65
66 /**
67 * @brief Enable TPWM Counter Mode
68 *
69 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
70 *
71 * @return None
72 *
73 * @details This macro is used to enable specified Timer channel as PWM counter mode, then timer counter mode is invalid.
74 * @note All registers about time counter function will be cleared to 0 and timer clock source will be changed to PCLKx automatically after executing this macro.
75 * \hideinitializer
76 */
77 #define TPWM_ENABLE_PWM_MODE(timer) ((timer)->CTL |= TIMER_CTL_FUNCSEL_Msk)
78
79 /**
80 * @brief Disable TPWM Counter Mode
81 *
82 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
83 *
84 * @return None
85 *
86 * @details This macro is used to disable specified Timer channel as PWM counter mode, then timer counter mode is available.
87 * @note All registers about TPWM counter function will be cleared to 0 after executing this macro.
88 * \hideinitializer
89 */
90 #define TPWM_DISABLE_PWM_MODE(timer) ((timer)->CTL &= ~TIMER_CTL_FUNCSEL_Msk)
91
92 /**
93 * @brief Start TPWM Counter
94 *
95 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
96 *
97 * @return None
98 *
99 * @details This macro is used to enable TPWM generator and start counter counting.
100 * \hideinitializer
101 */
102 #define TPWM_START_COUNTER(timer) ((timer)->PWMCTL |= TIMER_PWMCTL_CNTEN_Msk)
103
104 /**
105 * @brief Stop TPWM Counter
106 *
107 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
108 *
109 * @return None
110 *
111 * @details This macro is used to stop TPWM counter after current period is completed.
112 * \hideinitializer
113 */
114 #define TPWM_STOP_COUNTER(timer) ((timer)->PWMPERIOD = 0x0UL)
115
116 /**
117 * @brief Set Counter Clock Prescaler
118 *
119 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
120 *
121 * @param[in] u32Prescaler Clock prescaler of specified channel. Valid values are between 0x0~0xFF.
122 *
123 * @return None
124 *
125 * @details This macro is used to set the prescaler of specified TIMER PWM.
126 * @note If prescaler is 0, then there is no scaling in counter clock source.
127 * \hideinitializer
128 */
129 #define TPWM_SET_PRESCALER(timer, u32Prescaler) ((timer)->PWMCLKPSC = (u32Prescaler))
130
131 /**
132 * @brief Get Counter Clock Prescaler
133 *
134 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
135 *
136 * @return Target prescaler setting, CLKPSC (TIMERx_PWMCLKPSC[7:0])
137 *
138 * @details Get the prescaler setting, the target counter clock divider is (CLKPSC + 1).
139 * \hideinitializer
140 */
141 #define TPWM_GET_PRESCALER(timer) ((timer)->PWMCLKPSC)
142
143 /**
144 * @brief Set Counter Period
145 *
146 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
147 *
148 * @param[in] u32Period Period of specified channel. Valid values are between 0x0~0xFFFF.
149 *
150 * @return None
151 *
152 * @details This macro is used to set the period of specified TIMER PWM.
153 * \hideinitializer
154 */
155 #define TPWM_SET_PERIOD(timer, u32Period) ((timer)->PWMPERIOD = (u32Period))
156
157 /**
158 * @brief Get Counter Period
159 *
160 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
161 *
162 * @return Target period setting, PERIOD (TIMERx_PWMPERIOD[15:0])
163 *
164 * @details This macro is used to get the period of specified TIMER PWM.
165 * \hideinitializer
166 */
167 #define TPWM_GET_PERIOD(timer) ((timer)->PWMPERIOD)
168
169 /**
170 * @brief Set Comparator Value
171 *
172 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
173 *
174 * @param[in] u32Cmp Comparator of specified channel. Valid values are between 0x0~0xFFFF.
175 *
176 * @return None
177 *
178 * @details This macro is used to set the comparator value of specified TIMER PWM.
179 * \hideinitializer
180 */
181 #define TPWM_SET_CMPDAT(timer, u32Cmp) ((timer)->PWMCMPDAT = (u32Cmp))
182
183 /**
184 * @brief Get Comparator Value
185 *
186 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
187 *
188 * @return Target comparator setting, CMPDAT (TIMERx_PWMCMPDAT[15:0])
189 *
190 * @details This macro is used to get the comparator value of specified TIMER PWM.
191 * \hideinitializer
192 */
193 #define TPWM_GET_CMPDAT(timer) ((timer)->PWMCMPDAT)
194
195 /**
196 * @brief Clear Counter
197 *
198 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
199 *
200 * @return None
201 *
202 * @details This macro is used to clear counter of specified TIMER PWM.
203 * \hideinitializer
204 */
205 #define TPWM_CLEAR_COUNTER(timer) ((timer)->PWMCNTCLR = TIMER_PWMCNTCLR_CNTCLR_Msk)
206
207 /**
208 * @brief Enable Output Function
209 *
210 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
211 *
212 * @param[in] u32Channel Enable specified channel output function. Valid values are:
213 * - \ref TPWM_CH0
214 *
215 * @return None
216 *
217 * @details This macro is used to enable output function of specified output pins.
218 * @note If the corresponding bit in u32ChMask parameter is 0, then output function will be disabled in this channel.
219 * \hideinitializer
220 */
221 #define TPWM_ENABLE_OUTPUT(timer, u32Channel) ((timer)->PWMPOCTL = ((timer)->PWMPOCTL & ~(TIMER_PWMPOCTL_POEN_Msk)) | (u32Channel))
222
223 /**
224 * @brief Select Toggle-output Pin
225 *
226 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
227 * @param[in] u32ToutSel Toggle-output pin selection, valid values are:
228 * - \ref TPWM_TOUT_PIN_FROM_TX
229 * - \ref TPWM_TOUT_PIN_FROM_TX_EXT
230 *
231 * @return None
232 *
233 * @details This macro is used to select TPWM toggle-output pin is output on Tx or Tx_EXT pin.
234 */
235 #define TPWM_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->PWMPOCTL = ((timer)->PWMPOCTL & ~TIMER_PWMPOCTL_POSEL_Msk) | (u32ToutSel))
236
237 /**
238 * @brief Set Output Inverse
239 *
240 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
241 *
242 * @param[in] u32Channel Set specified channel output is inversed or not. Valid values are:
243 * - \ref TPWM_CH0
244 *
245 * @return None
246 *
247 * @details This macro is used to enable output inverse of specified output pins.
248 * @note If u32ChMask parameter is 0, then output inverse function will be disabled.
249 * \hideinitializer
250 */
251 #define TPWM_SET_OUTPUT_INVERSE(timer, u32Channel) ((timer)->PWMPOLCTL = (u32Channel))
252
253 /**
254 * @brief Enable Period Event Interrupt
255 *
256 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
257 *
258 * @return None
259 *
260 * @details This macro is used to enable the period event interrupt function.
261 * \hideinitializer
262 */
263 #define TPWM_ENABLE_PERIOD_INT(timer) ((timer)->PWMINTEN0 |= TIMER_PWMINTEN0_PIEN_Msk)
264
265 /**
266 * @brief Disable Period Event Interrupt
267 *
268 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
269 *
270 * @return None
271 *
272 * @details This macro is used to disable the period event interrupt function.
273 * \hideinitializer
274 */
275 #define TPWM_DISABLE_PERIOD_INT(timer) ((timer)->PWMINTEN0 &= ~TIMER_PWMINTEN0_PIEN_Msk)
276
277 /**
278 * @brief Get Period Event Interrupt Flag
279 *
280 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
281 *
282 * @retval 0 Period event interrupt did not occur
283 * @retval 1 Period event interrupt occurred
284 *
285 * @details This macro indicates period event occurred or not.
286 * \hideinitializer
287 */
288 #define TPWM_GET_PERIOD_INT_FLAG(timer) (((timer)->PWMINTSTS0 & TIMER_PWMINTSTS0_PIF_Msk)? 1 : 0)
289
290 /**
291 * @brief Clear Period Event Interrupt Flag
292 *
293 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
294 *
295 * @return None
296 *
297 * @details This macro clears period event interrupt flag.
298 * \hideinitializer
299 */
300 #define TPWM_CLEAR_PERIOD_INT_FLAG(timer) ((timer)->PWMINTSTS0 = TIMER_PWMINTSTS0_PIF_Msk)
301
302 /**
303 * @brief Enable Compare Up Event Interrupt
304 *
305 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
306 *
307 * @return None
308 *
309 * @details This macro is used to enable the compare up event interrupt function.
310 * \hideinitializer
311 */
312 #define TPWM_ENABLE_CMP_UP_INT(timer) ((timer)->PWMINTEN0 |= TIMER_PWMINTEN0_CMPUIEN_Msk)
313
314 /**
315 * @brief Disable Compare Up Event Interrupt
316 *
317 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
318 *
319 * @return None
320 *
321 * @details This macro is used to disable the compare up event interrupt function.
322 * \hideinitializer
323 */
324 #define TPWM_DISABLE_CMP_UP_INT(timer) ((timer)->PWMINTEN0 &= ~TIMER_PWMINTEN0_CMPUIEN_Msk)
325
326 /**
327 * @brief Get Compare Up Event Interrupt Flag
328 *
329 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
330 *
331 * @retval 0 Compare up event interrupt did not occur
332 * @retval 1 Compare up event interrupt occurred
333 *
334 * @details This macro indicates compare up event occurred or not.
335 * \hideinitializer
336 */
337 #define TPWM_GET_CMP_UP_INT_FLAG(timer) (((timer)->PWMINTSTS0 & TIMER_PWMINTSTS0_CMPUIF_Msk)? 1 : 0)
338
339 /**
340 * @brief Clear Compare Up Event Interrupt Flag
341 *
342 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
343 *
344 * @return None
345 *
346 * @details This macro clears compare up event interrupt flag.
347 * \hideinitializer
348 */
349 #define TPWM_CLEAR_CMP_UP_INT_FLAG(timer) ((timer)->PWMINTSTS0 = TIMER_PWMINTSTS0_CMPUIF_Msk)
350
351 /**
352 * @brief Get Counter Reach Maximum Count Status
353 *
354 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
355 *
356 * @retval 0 Timer PWM counter never counts to maximum value
357 * @retval 1 Timer PWM counter counts to maximum value, 0xFFFF
358 *
359 * @details This macro indicates Timer PWM counter has count to 0xFFFF or not.
360 * \hideinitializer
361 */
362 #define TPWM_GET_REACH_MAX_CNT_STATUS(timer) (((timer)->PWMSTATUS & TIMER_PWMSTATUS_CNTMAXF_Msk)? 1 : 0)
363
364 /**
365 * @brief Clear Counter Reach Maximum Count Status
366 *
367 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
368 *
369 * @return None
370 *
371 * @details This macro clears reach maximum count status.
372 * \hideinitializer
373 */
374 #define TPWM_CLEAR_REACH_MAX_CNT_STATUS(timer) ((timer)->PWMSTATUS = TIMER_PWMSTATUS_CNTMAXF_Msk)
375
376 /**
377 * @brief Get Trigger LPADC Status
378 *
379 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
380 *
381 * @retval 0 Trigger LPADC start conversion is not occur
382 * @retval 1 Specified counter event has trigger LPADC start conversion
383 *
384 * @details This macro is used to indicate TPWM counter event has triggered LPADC start conversion.
385 * \hideinitializer
386 */
387 #define TPWM_GET_TRG_LPADC_STATUS(timer) (((timer)->PWMSTATUS & TIMER_PWMSTATUS_LPADCTRGF_Msk)? 1 : 0)
388
389 /**
390 * @brief Clear Trigger LPADC Status
391 *
392 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
393 *
394 * @return None
395 *
396 * @details This macro is used to clear TPWM counter event trigger LPADC status.
397 * \hideinitializer
398 */
399 #define TPWM_CLEAR_TRG_LPADC_STATUS(timer) ((timer)->PWMSTATUS = TIMER_PWMSTATUS_LPADCTRGF_Msk)
400
401 /**
402 * @brief Get Trigger EADC Status
403 *
404 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
405 *
406 * @retval 0 Trigger EADC start conversion is not occur
407 * @retval 1 Specified counter event has trigger EADC start conversion
408 *
409 * @details This macro is used to indicate TPWM counter event has triggered EADC start conversion.
410 * \hideinitializer
411 */
412 #define TPWM_GET_TRG_EADC_STATUS(timer) (((timer)->PWMSTATUS & TIMER_PWMSTATUS_EADCTRGF_Msk)? 1 : 0)
413
414 /**
415 * @brief Clear Trigger EADC Status
416 *
417 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
418 *
419 * @return None
420 *
421 * @details This macro is used to clear TPWM counter event trigger EADC status.
422 * \hideinitializer
423 */
424 #define TPWM_CLEAR_TRG_EADC_STATUS(timer) ((timer)->PWMSTATUS = TIMER_PWMSTATUS_EADCTRGF_Msk)
425
426 /**
427 * @brief Get Trigger DAC Status
428 *
429 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
430 *
431 * @retval 0 Trigger DAC start conversion is not occur
432 * @retval 1 Specified counter event has trigger DAC start conversion
433 *
434 * @details This macro is used to indicate TPWM counter event has triggered DAC start conversion.
435 * \hideinitializer
436 */
437 #define TPWM_GET_TRG_DAC_STATUS(timer) (((timer)->PWMSTATUS & TIMER_PWMSTATUS_DACTRGF_Msk)? 1 : 0)
438
439 /**
440 * @brief Clear Trigger DAC Status
441 *
442 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
443 *
444 * @return None
445 *
446 * @details This macro is used to clear TPWM counter event trigger DAC status.
447 * \hideinitializer
448 */
449 #define TPWM_CLEAR_TRG_DAC_STATUS(timer) ((timer)->PWMSTATUS = TIMER_PWMSTATUS_DACTRGF_Msk)
450
451 /**
452 * @brief Get Trigger PDMA Status
453 *
454 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
455 *
456 * @retval 0 Trigger PDMA start conversion is not occur
457 * @retval 1 Specified counter event has trigger PDMA start conversion
458 *
459 * @details This macro is used to indicate TPWM counter event has triggered PDMA start conversion.
460 * \hideinitializer
461 */
462 #define TPWM_GET_TRG_PDMA_STATUS(timer) (((timer)->PWMSTATUS & TIMER_PWMSTATUS_PDMATRGF_Msk)? 1 : 0)
463
464 /**
465 * @brief Clear Trigger PDMA Status
466 *
467 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
468 *
469 * @return None
470 *
471 * @details This macro is used to clear TPWM counter event trigger PDMA status.
472 * \hideinitializer
473 */
474 #define TPWM_CLEAR_TRG_PDMA_STATUS(timer) ((timer)->PWMSTATUS = TIMER_PWMSTATUS_PDMATRGF_Msk)
475
476 uint32_t TPWM_ConfigOutputFreqAndDuty(TIMER_T *timer, uint32_t u32Frequency, uint32_t u32DutyCycle);
477 void TPWM_EnableCounter(TIMER_T *timer);
478 void TPWM_DisableCounter(TIMER_T *timer);
479 void TPWM_EnableTrigger(TIMER_T *timer, uint32_t u32TargetMask, uint32_t u32Condition);
480 void TPWM_DisableTrigger(TIMER_T *timer, uint32_t u32TargetMask);
481
482 /**
483 * @brief Enable Trigger EADC
484 *
485 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
486 * @param[in] u32Condition The condition to trigger EADC. It could be one of following conditions:
487 * - \ref TPWM_TRIGGER_AT_PERIOD_POINT
488 * - \ref TPWM_TRIGGER_AT_COMPARE_POINT
489 * - \ref TPWM_TRIGGER_AT_PERIOD_OR_COMPARE_POINT
490 * @return None
491 *
492 * @details This function is used to enable specified counter compare event to trigger EADC.
493 */
494 #define TPWM_EnableTriggerEADC(timer, u32Condition) TPWM_EnableTrigger(timer, TIMER_PWMTRGCTL_PWMTRGEADC_Msk, u32Condition)
495
496 /**
497 * @brief Disable Trigger EADC
498 *
499 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
500 *
501 * @return None
502 *
503 * @details This function is used to disable counter compare event to trigger EADC.
504 */
505 #define TPWM_DisableTriggerEADC(timer) TPWM_DisableTrigger(timer, TIMER_PWMTRGCTL_PWMTRGEADC_Msk)
506
507 /**
508 * @brief Enable Trigger DAC
509 *
510 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
511 * @param[in] u32Condition The condition to trigger DAC. It could be one of following conditions:
512 * - \ref TPWM_TRIGGER_AT_PERIOD_POINT
513 * - \ref TPWM_TRIGGER_AT_COMPARE_POINT
514 * - \ref TPWM_TRIGGER_AT_PERIOD_OR_COMPARE_POINT
515 * @return None
516 *
517 * @details This function is used to enable specified counter compare event to trigger DAC.
518 */
519 #define TPWM_EnableTriggerDAC(timer, u32Condition) TPWM_EnableTrigger(timer, TIMER_PWMTRGCTL_PWMTRGDAC_Msk, u32Condition)
520
521 /**
522 * @brief Disable Trigger DAC
523 *
524 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
525 *
526 * @return None
527 *
528 * @details This function is used to disable counter compare event to trigger DAC.
529 */
530 #define TPWM_DisableTriggerDAC(timer) TPWM_DisableTrigger(timer, TIMER_PWMTRGCTL_PWMTRGDAC_Msk)
531
532 /**
533 * @brief Enable Trigger PDMA
534 *
535 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
536 * @param[in] u32Condition The condition to trigger PDMA. It could be one of following conditions:
537 * - \ref TPWM_TRIGGER_AT_PERIOD_POINT
538 * - \ref TPWM_TRIGGER_AT_COMPARE_POINT
539 * - \ref TPWM_TRIGGER_AT_PERIOD_OR_COMPARE_POINT
540 * @return None
541 *
542 * @details This function is used to enable specified counter compare event to trigger PDMA.
543 */
544 #define TPWM_EnableTriggerPDMA(timer, u32Condition) TPWM_EnableTrigger(timer, TIMER_PWMTRGCTL_PWMTRGPDMA_Msk, u32Condition)
545
546 /**
547 * @brief Disable Trigger PDMA
548 *
549 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
550 *
551 * @return None
552 *
553 * @details This function is used to disable counter compare event to trigger PDMA.
554 */
555 #define TPWM_DisableTriggerPDMA(timer) TPWM_DisableTrigger(timer, TIMER_PWMTRGCTL_PWMTRGPDMA_Msk)
556
557 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
558 __STATIC_INLINE void TPWM_EnableWakeup(TIMER_T *timer);
559 __STATIC_INLINE void TPWM_DisableWakeup(TIMER_T *timer);
560 __STATIC_INLINE uint32_t TPWM_GetWakeupFlag(TIMER_T *timer);
561 __STATIC_INLINE void TPWM_ClearWakeupFlag(TIMER_T *timer);
562
563 /**
564 * @brief Enable TPWM Interrupt Wake-up Function
565 *
566 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
567 *
568 * @return None
569 *
570 * @details This function is used to enable the TPWM interrupt Wake-up function and interrupt source could be period interrupt, \n
571 * or compare interrupt.
572 * @note To wake the system from Power-down mode, PCLKx source must be ether LXT or LIRC.
573 * \hideinitializer
574 */
TPWM_EnableWakeup(TIMER_T * timer)575 __STATIC_INLINE void TPWM_EnableWakeup(TIMER_T *timer)
576 {
577 timer->PWMCTL |= TIMER_PWMCTL_PWMINTWKEN_Msk;
578 }
579
580 /**
581 * @brief Disable TPWM Interrupt Wake-up Function
582 *
583 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
584 *
585 * @return None
586 *
587 * @details This function is used to disable the TPWM interrupt Wake-up function.
588 * \hideinitializer
589 */
TPWM_DisableWakeup(TIMER_T * timer)590 __STATIC_INLINE void TPWM_DisableWakeup(TIMER_T *timer)
591 {
592 timer->PWMCTL &= ~TIMER_PWMCTL_PWMINTWKEN_Msk;
593 }
594
595 /**
596 * @brief Get TPWM Wake-up Flag
597 *
598 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
599 *
600 * @retval 0 TPWM does not cause CPU wake-up
601 * @retval 1 TPWM interrupt event cause CPU wake-up
602 *
603 * @details This function indicates TPWM interrupt event has waked up system or not.
604 * \hideinitializer
605 */
TPWM_GetWakeupFlag(TIMER_T * timer)606 __STATIC_INLINE uint32_t TPWM_GetWakeupFlag(TIMER_T *timer)
607 {
608 return ((timer->PWMSTATUS & TIMER_PWMSTATUS_PWMINTWKF_Msk) ? 1 : 0);
609 }
610
611 /**
612 * @brief Clear TPWM Wake-up Flag
613 *
614 * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3.
615 *
616 * @return None
617 *
618 * @details This function clears TPWM Wake-up flag.
619 * \hideinitializer
620 */
TPWM_ClearWakeupFlag(TIMER_T * timer)621 __STATIC_INLINE void TPWM_ClearWakeupFlag(TIMER_T *timer)
622 {
623 timer->PWMSTATUS = TIMER_PWMSTATUS_PWMINTWKF_Msk;
624 }
625
626 void TPWM_EnableAcc(TIMER_T *timer, uint32_t u32IntFlagCnt, uint32_t u32IntAccSrc);
627 void TPWM_DisableAcc(TIMER_T *timer);
628 void TPWM_EnableAccInt(TIMER_T *timer);
629 void TPWM_DisableAccInt(TIMER_T *timer);
630 void TPWM_ClearAccInt(TIMER_T *timer);
631 uint32_t TPWM_GetAccInt(TIMER_T *timer);
632 void TPWM_EnableAccPDMA(TIMER_T *timer);
633 void TPWM_DisableAccPDMA(TIMER_T *timer);
634 void TPWM_EnableAccStopMode(TIMER_T *timer);
635 void TPWM_DisableAccStopMode(TIMER_T *timer);
636
637 /*@}*/ /* end of group TIMER_PWM_EXPORTED_FUNCTIONS */
638
639 /*@}*/ /* end of group TIMER_PWM_Driver */
640
641 /*@}*/ /* end of group Standard_Driver */
642
643 #ifdef __cplusplus
644 }
645 #endif
646
647 #endif /* __TIMER_PWM_H__ */
648
649 /*** (C) COPYRIGHT 2020 Nuvoton Technology Corp. ***/
650