1 /**************************************************************************//**
2  * @file     epwm.c
3  * @version  V3.00
4  * @brief    M2354 series EPWM driver source file
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8  *****************************************************************************/
9 #include "NuMicro.h"
10 
11 /** @addtogroup Standard_Driver Standard Driver
12   @{
13 */
14 
15 /** @addtogroup EPWM_Driver EPWM Driver
16   @{
17 */
18 
19 
20 /** @addtogroup EPWM_EXPORTED_FUNCTIONS EPWM Exported Functions
21   @{
22 */
23 
24 /**
25  * @brief Configure EPWM capture and get the nearest unit time.
26  * @param[in] epwm The pointer of the specified EPWM module
27  *                - EPWM0 : EPWM Group 0
28  *                - EPWM1 : EPWM Group 1
29  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
30  * @param[in] u32UnitTimeNsec The unit time of counter
31  * @param[in] u32CaptureEdge The condition to latch the counter. This parameter is not used
32  * @return The nearest unit time in nano second.
33  * @details This function is used to Configure EPWM capture and get the nearest unit time.
34  */
EPWM_ConfigCaptureChannel(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32UnitTimeNsec,uint32_t u32CaptureEdge)35 uint32_t EPWM_ConfigCaptureChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
36 {
37     uint32_t u32PWMClockSrc;
38     uint32_t u32NearestUnitTimeNsec = 0;
39     uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
40     uint8_t u8BreakLoop = 0U;
41 
42     (void)u32CaptureEdge;
43 
44     /* clock source is from PCLK */
45     if((epwm == EPWM0) || (epwm == EPWM0_NS))
46     {
47         u32PWMClockSrc = CLK_GetPCLK0Freq();
48     }
49     else /* if((epwm == EPWM1)||(epwm == EPWM1_NS)) */
50     {
51         u32PWMClockSrc = CLK_GetPCLK1Freq();
52     }
53 
54     u32PWMClockSrc /= 1000UL;
55     for(u32Prescale = 1U; u32Prescale <= 0x1000U; u32Prescale++)
56     {
57         u32NearestUnitTimeNsec = (1000000UL * u32Prescale) / u32PWMClockSrc;
58         if(u32NearestUnitTimeNsec < u32UnitTimeNsec)
59         {
60             if(u32Prescale == 0x1000U)  /* limit to the maximum unit time(nano second) */
61             {
62                 u8BreakLoop = 1U;
63             }
64             if(!((1000000UL * (u32Prescale + 1UL) > (u32NearestUnitTimeNsec * u32PWMClockSrc))))
65             {
66                 u8BreakLoop = 1U;
67             }
68         }
69         else
70         {
71             u8BreakLoop = 1U;
72         }
73         if(u8BreakLoop)
74         {
75             break;
76         }
77     }
78 
79     /* convert to real register value */
80     u32Prescale = u32Prescale - 1U;
81     /* every two channels share a prescaler */
82     EPWM_SET_PRESCALER(epwm, u32ChannelNum, u32Prescale);
83 
84     /* set EPWM to down count type(edge aligned) */
85     (epwm)->CTL1 = ((epwm)->CTL1 & ~(EPWM_CTL1_CNTTYPE0_Msk << (u32ChannelNum << 1))) | (1UL << (u32ChannelNum << 1));
86     /* set EPWM to auto-reload mode */
87     (epwm)->CTL1 &= ~(EPWM_CTL1_CNTMODE0_Msk << u32ChannelNum);
88     EPWM_SET_CNR(epwm, u32ChannelNum, u32CNR);
89 
90     return (u32NearestUnitTimeNsec);
91 }
92 
93 /**
94  * @brief This function Configure EPWM generator and get the nearest frequency in edge aligned(up counter type) auto-reload mode
95  * @param[in] epwm The pointer of the specified EPWM module
96  *                - EPWM0 : EPWM Group 0
97  *                - EPWM1 : EPWM Group 1
98  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
99  * @param[in] u32Frequency Target generator frequency
100  * @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...
101  * @return Nearest frequency clock in nano second
102  * @note Since every two channels, (0 & 1), (2 & 3), shares a prescaler. Call this API to configure EPWM frequency may affect
103  *       existing frequency of other channel.
104  * @note This function is used for initial stage.
105  *       To change duty cycle later, it should get the configured period value and calculate the new comparator value.
106  */
EPWM_ConfigOutputChannel(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Frequency,uint32_t u32DutyCycle)107 uint32_t EPWM_ConfigOutputChannel(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
108 {
109     uint32_t u32PWMClockSrc;
110     uint32_t i;
111     uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;
112 
113     /* clock source is from PCLK */
114     if((epwm == EPWM0) || (epwm == EPWM0_NS))
115     {
116         u32PWMClockSrc = CLK_GetPCLK0Freq();
117     }
118     else /* if((epwm == EPWM1)||(epwm == EPWM1_NS)) */
119     {
120         u32PWMClockSrc = CLK_GetPCLK1Freq();
121     }
122 
123     for(u32Prescale = 1U; u32Prescale < 0xFFFU; u32Prescale++)/* prescale could be 0~0xFFF */
124     {
125         i = (u32PWMClockSrc / u32Frequency) / u32Prescale;
126         /* If target value is larger than CNR, need to use a larger prescaler */
127         if(i <= (0x10000U))
128         {
129             u32CNR = i;
130             break;
131         }
132     }
133     /* Store return value here 'cos we're gonna change u32Prescale & u32CNR to the real value to fill into register */
134     i = u32PWMClockSrc / (u32Prescale * u32CNR);
135 
136     /* convert to real register value */
137     u32Prescale = u32Prescale - 1U;
138     /* every two channels share a prescaler */
139     EPWM_SET_PRESCALER(epwm, u32ChannelNum, u32Prescale);
140     /* set EPWM to up counter type(edge aligned) and auto-reload mode */
141     (epwm)->CTL1 = ((epwm)->CTL1 & ~((EPWM_CTL1_CNTTYPE0_Msk << (u32ChannelNum << 1)) | (EPWM_CTL1_CNTMODE0_Msk << u32ChannelNum)));
142 
143     u32CNR = u32CNR - 1U;
144     EPWM_SET_CNR(epwm, u32ChannelNum, u32CNR);
145     EPWM_SET_CMR(epwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1UL) / 100UL);
146 
147     (epwm)->WGCTL0 = ((epwm)->WGCTL0 & ~((EPWM_WGCTL0_PRDPCTL0_Msk | EPWM_WGCTL0_ZPCTL0_Msk) << (u32ChannelNum << 1))) | \
148                      (EPWM_OUTPUT_HIGH << (u32ChannelNum << 1UL << EPWM_WGCTL0_ZPCTL0_Pos));
149     (epwm)->WGCTL1 = ((epwm)->WGCTL1 & ~((EPWM_WGCTL1_CMPDCTL0_Msk | EPWM_WGCTL1_CMPUCTL0_Msk) << (u32ChannelNum << 1))) | \
150                      (EPWM_OUTPUT_LOW << (u32ChannelNum << 1UL << EPWM_WGCTL1_CMPUCTL0_Pos));
151 
152     return(i);
153 }
154 
155 /**
156  * @brief Start EPWM module
157  * @param[in] epwm The pointer of the specified EPWM module
158  *                - EPWM0 : EPWM Group 0
159  *                - EPWM1 : EPWM Group 1
160  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
161  *                           Bit 0 is channel 0, bit 1 is channel 1...
162  * @return None
163  * @details This function is used to start EPWM module.
164  */
EPWM_Start(EPWM_T * epwm,uint32_t u32ChannelMask)165 void EPWM_Start(EPWM_T *epwm, uint32_t u32ChannelMask)
166 {
167     (epwm)->CNTEN |= u32ChannelMask;
168 }
169 
170 /**
171  * @brief Stop EPWM module
172  * @param[in] epwm The pointer of the specified EPWM module
173  *                - EPWM0 : EPWM Group 0
174  *                - EPWM1 : EPWM Group 1
175  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
176  *                           Bit 0 is channel 0, bit 1 is channel 1...
177  * @return None
178  * @details This function is used to stop EPWM module.
179  */
EPWM_Stop(EPWM_T * epwm,uint32_t u32ChannelMask)180 void EPWM_Stop(EPWM_T *epwm, uint32_t u32ChannelMask)
181 {
182     uint32_t i;
183     for(i = 0UL; i < EPWM_CHANNEL_NUM; i ++)
184     {
185         if(u32ChannelMask & (1UL << i))
186         {
187             (epwm)->PERIOD[i] = 0UL;
188         }
189     }
190 }
191 
192 /**
193  * @brief Stop EPWM generation immediately by clear channel enable bit
194  * @param[in] epwm The pointer of the specified EPWM module
195  *                - EPWM0 : EPWM Group 0
196  *                - EPWM1 : EPWM Group 1
197  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
198  *                           Bit 0 is channel 0, bit 1 is channel 1...
199  * @return None
200  * @details This function is used to stop EPWM generation immediately by clear channel enable bit.
201  */
EPWM_ForceStop(EPWM_T * epwm,uint32_t u32ChannelMask)202 void EPWM_ForceStop(EPWM_T *epwm, uint32_t u32ChannelMask)
203 {
204     (epwm)->CNTEN &= ~u32ChannelMask;
205 }
206 
207 /**
208  * @brief Enable selected channel to trigger ADC
209  * @param[in] epwm The pointer of the specified EPWM module
210  *                - EPWM0 : EPWM Group 0
211  *                - EPWM1 : EPWM Group 1
212  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
213  * @param[in] u32Condition The condition to trigger ADC. Combination of following conditions:
214  *                  - \ref EPWM_TRG_ADC_EVEN_ZERO
215  *                  - \ref EPWM_TRG_ADC_EVEN_PERIOD
216  *                  - \ref EPWM_TRG_ADC_EVEN_ZERO_PERIOD
217  *                  - \ref EPWM_TRG_ADC_EVEN_COMPARE_UP
218  *                  - \ref EPWM_TRG_ADC_EVEN_COMPARE_DOWN
219  *                  - \ref EPWM_TRG_ADC_ODD_ZERO
220  *                  - \ref EPWM_TRG_ADC_ODD_PERIOD
221  *                  - \ref EPWM_TRG_ADC_ODD_ZERO_PERIOD
222  *                  - \ref EPWM_TRG_ADC_ODD_COMPARE_UP
223  *                  - \ref EPWM_TRG_ADC_ODD_COMPARE_DOWN
224  *                  - \ref EPWM_TRG_ADC_CH_0_FREE_CMP_UP
225  *                  - \ref EPWM_TRG_ADC_CH_0_FREE_CMP_DOWN
226  *                  - \ref EPWM_TRG_ADC_CH_2_FREE_CMP_UP
227  *                  - \ref EPWM_TRG_ADC_CH_2_FREE_CMP_DOWN
228  *                  - \ref EPWM_TRG_ADC_CH_4_FREE_CMP_UP
229  *                  - \ref EPWM_TRG_ADC_CH_4_FREE_CMP_DOWN
230  * @return None
231  * @details This function is used to enable selected channel to trigger ADC.
232  */
EPWM_EnableADCTrigger(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Condition)233 void EPWM_EnableADCTrigger(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
234 {
235     if(u32ChannelNum < 4UL)
236     {
237         (epwm)->EADCTS0 &= ~((EPWM_EADCTS0_TRGSEL0_Msk) << (u32ChannelNum << 3));
238         (epwm)->EADCTS0 |= ((EPWM_EADCTS0_TRGEN0_Msk | u32Condition) << (u32ChannelNum << 3));
239     }
240     else
241     {
242         (epwm)->EADCTS1 &= ~((EPWM_EADCTS1_TRGSEL4_Msk) << ((u32ChannelNum - 4UL) << 3));
243         (epwm)->EADCTS1 |= ((EPWM_EADCTS1_TRGEN4_Msk | u32Condition) << ((u32ChannelNum - 4UL) << 3));
244     }
245 }
246 
247 /**
248  * @brief Disable selected channel to trigger ADC
249  * @param[in] epwm The pointer of the specified EPWM module
250  *                - EPWM0 : EPWM Group 0
251  *                - EPWM1 : EPWM Group 1
252  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
253  * @return None
254  * @details This function is used to disable selected channel to trigger ADC.
255  */
EPWM_DisableADCTrigger(EPWM_T * epwm,uint32_t u32ChannelNum)256 void EPWM_DisableADCTrigger(EPWM_T *epwm, uint32_t u32ChannelNum)
257 {
258     if(u32ChannelNum < 4UL)
259     {
260         (epwm)->EADCTS0 &= ~(EPWM_EADCTS0_TRGEN0_Msk << (u32ChannelNum << 3));
261     }
262     else
263     {
264         (epwm)->EADCTS1 &= ~(EPWM_EADCTS1_TRGEN4_Msk << ((u32ChannelNum - 4UL) << 3));
265     }
266 }
267 
268 /**
269  * @brief Enable and configure trigger ADC prescale
270  * @param[in] epwm The pointer of the specified EPWM module
271  *                - EPWM0 : EPWM Group 0
272  *                - EPWM1 : EPWM Group 1
273  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
274  * @param[in] u32Prescale ADC prescale. Valid values are between 0 to 0xF.
275  * @param[in] u32PrescaleCnt ADC prescale counter. Valid values are between 0 to 0xF.
276  * @retval 0 Success.
277  * @retval -1 Failed.
278  * @details This function is used to enable and configure trigger ADC prescale.
279  * @note User can configure only when ADC trigger prescale is disabled.
280  * @note ADC prescale counter must less than ADC prescale.
281  */
EPWM_EnableADCTriggerPrescale(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Prescale,uint32_t u32PrescaleCnt)282 int32_t EPWM_EnableADCTriggerPrescale(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Prescale, uint32_t u32PrescaleCnt)
283 {
284     /* User can write only when PSCENn(n = 0 ~ 5) is 0 */
285     if((epwm)->EADCPSCCTL & (1UL << u32ChannelNum))
286         return (-1);
287 
288     if(u32ChannelNum < 4UL)
289     {
290         (epwm)->EADCPSC0 = ((epwm)->EADCPSC0 & ~((EPWM_EADCPSC0_EADCPSC0_Msk) << (u32ChannelNum << 3))) | \
291                            (u32Prescale << (u32ChannelNum << 3));
292         (epwm)->EADCPSCNT0 = ((epwm)->EADCPSCNT0 & ~((EPWM_EADCPSCNT0_PSCNT0_Msk) << (u32ChannelNum << 3))) | \
293                              (u32PrescaleCnt << (u32ChannelNum << 3));
294     }
295     else
296     {
297         (epwm)->EADCPSC1 = ((epwm)->EADCPSC1 & ~((EPWM_EADCPSC1_EADCPSC4_Msk) << ((u32ChannelNum - 4UL) << 3))) | \
298                            (u32Prescale << ((u32ChannelNum - 4UL) << 3));
299         (epwm)->EADCPSCNT1 = ((epwm)->EADCPSCNT1 & ~((EPWM_EADCPSCNT1_PSCNT4_Msk) << ((u32ChannelNum - 4UL) << 3))) | \
300                              (u32PrescaleCnt << ((u32ChannelNum - 4UL) << 3));
301     }
302 
303     (epwm)->EADCPSCCTL |= EPWM_EADCPSCCTL_PSCEN0_Msk << u32ChannelNum;
304 
305     return 0;
306 }
307 
308 /**
309  * @brief Disable Trigger ADC prescale function
310  * @param[in] epwm The pointer of the specified EPWM module
311  *                - EPWM0 : EPWM Group 0
312  *                - EPWM1 : EPWM Group 1
313  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
314  * @return None
315  * @details This function is used to disable trigger ADC prescale.
316  */
EPWM_DisableADCTriggerPrescale(EPWM_T * epwm,uint32_t u32ChannelNum)317 void EPWM_DisableADCTriggerPrescale(EPWM_T *epwm, uint32_t u32ChannelNum)
318 {
319     (epwm)->EADCPSCCTL &= ~(EPWM_EADCPSCCTL_PSCEN0_Msk << u32ChannelNum);
320 }
321 
322 /**
323  * @brief Clear selected channel trigger ADC flag
324  * @param[in] epwm The pointer of the specified EPWM module
325  *                - EPWM0 : EPWM Group 0
326  *                - EPWM1 : EPWM Group 1
327  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
328  * @param[in] u32Condition This parameter is not used
329  * @return None
330  * @details This function is used to clear selected channel trigger ADC flag.
331  */
EPWM_ClearADCTriggerFlag(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Condition)332 void EPWM_ClearADCTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
333 {
334     (void)u32Condition;
335     (epwm)->STATUS = (EPWM_STATUS_EADCTRGF0_Msk << u32ChannelNum);
336 }
337 
338 /**
339  * @brief Get selected channel trigger ADC flag
340  * @param[in] epwm The pointer of the specified EPWM module
341  *                - EPWM0 : EPWM Group 0
342  *                - EPWM1 : EPWM Group 1
343  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
344  * @retval 0 The specified channel trigger ADC to start of conversion flag is not set
345  * @retval 1 The specified channel trigger ADC to start of conversion flag is set
346  * @details This function is used to get EPWM trigger ADC to start of conversion flag for specified channel.
347  */
EPWM_GetADCTriggerFlag(EPWM_T * epwm,uint32_t u32ChannelNum)348 uint32_t EPWM_GetADCTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
349 {
350     return (((epwm)->STATUS & (EPWM_STATUS_EADCTRGF0_Msk << u32ChannelNum)) ? 1UL : 0UL);
351 }
352 
353 /**
354  * @brief Enable selected channel to trigger DAC
355  * @param[in] epwm The pointer of the specified EPWM module
356  *                - EPWM0 : EPWM Group 0
357  *                - EPWM1 : EPWM Group 1
358  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
359  * @param[in] u32Condition The condition to trigger DAC. Combination of following conditions:
360  *                  - \ref EPWM_TRIGGER_DAC_ZERO
361  *                  - \ref EPWM_TRIGGER_DAC_PERIOD
362  *                  - \ref EPWM_TRIGGER_DAC_COMPARE_UP
363  *                  - \ref EPWM_TRIGGER_DAC_COMPARE_DOWN
364  * @return None
365  * @details This function is used to enable selected channel to trigger DAC.
366  */
EPWM_EnableDACTrigger(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Condition)367 void EPWM_EnableDACTrigger(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
368 {
369     (epwm)->DACTRGEN |= (u32Condition << u32ChannelNum);
370 }
371 
372 /**
373  * @brief Disable selected channel to trigger DAC
374  * @param[in] epwm The pointer of the specified EPWM module
375  *                - EPWM0 : EPWM Group 0
376  *                - EPWM1 : EPWM Group 1
377  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
378  * @return None
379  * @details This function is used to disable selected channel to trigger DAC.
380  */
EPWM_DisableDACTrigger(EPWM_T * epwm,uint32_t u32ChannelNum)381 void EPWM_DisableDACTrigger(EPWM_T *epwm, uint32_t u32ChannelNum)
382 {
383     (epwm)->DACTRGEN &= ~((EPWM_TRIGGER_DAC_ZERO | EPWM_TRIGGER_DAC_PERIOD | EPWM_TRIGGER_DAC_COMPARE_UP | EPWM_TRIGGER_DAC_COMPARE_DOWN) << u32ChannelNum);
384 }
385 
386 /**
387  * @brief Clear selected channel trigger DAC flag
388  * @param[in] epwm The pointer of the specified EPWM module
389  *                - EPWM0 : EPWM Group 0
390  *                - EPWM1 : EPWM Group 1
391  * @param[in] u32ChannelNum EPWM channel number. This parameter is not used
392  * @param[in] u32Condition The condition to trigger DAC. This parameter is not used
393  * @return None
394  * @details This function is used to clear selected channel trigger DAC flag.
395  */
EPWM_ClearDACTriggerFlag(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Condition)396 void EPWM_ClearDACTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Condition)
397 {
398     (void)u32ChannelNum;
399     (void)u32Condition;
400     (epwm)->STATUS = EPWM_STATUS_DACTRGF_Msk;
401 }
402 
403 /**
404  * @brief Get selected channel trigger DAC flag
405  * @param[in] epwm The pointer of the specified EPWM module
406  *                - EPWM0 : EPWM Group 0
407  *                - EPWM1 : EPWM Group 1
408  * @param[in] u32ChannelNum EPWM channel number. This parameter is not used
409  * @retval 0 The specified channel trigger DAC to start of conversion flag is not set
410  * @retval 1 The specified channel trigger DAC to start of conversion flag is set
411  * @details This function is used to get selected channel trigger DAC flag.
412  */
EPWM_GetDACTriggerFlag(EPWM_T * epwm,uint32_t u32ChannelNum)413 uint32_t EPWM_GetDACTriggerFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
414 {
415     (void)u32ChannelNum;
416     return (((epwm)->STATUS & EPWM_STATUS_DACTRGF_Msk) ? 1UL : 0UL);
417 }
418 
419 /**
420  * @brief This function enable fault brake of selected channel(s)
421  * @param[in] epwm The pointer of the specified EPWM module
422  *                - EPWM0 : EPWM Group 0
423  *                - EPWM1 : EPWM Group 1
424  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
425  * @param[in] u32LevelMask Output high or low while fault brake occurs, each bit represent the level of a channel
426  *                         while fault brake occurs. Bit 0 represents channel 0, bit 1 represents channel 1...
427  * @param[in] u32BrakeSource Fault brake source, could be one of following source
428  *                  - \ref EPWM_FB_EDGE_ADCRM
429  *                  - \ref EPWM_FB_EDGE_ACMP0
430  *                  - \ref EPWM_FB_EDGE_ACMP1
431  *                  - \ref EPWM_FB_EDGE_BKP0
432  *                  - \ref EPWM_FB_EDGE_BKP1
433  *                  - \ref EPWM_FB_EDGE_SYS_CSS
434  *                  - \ref EPWM_FB_EDGE_SYS_BOD
435  *                  - \ref EPWM_FB_EDGE_SYS_RAM
436  *                  - \ref EPWM_FB_EDGE_SYS_COR
437  *                  - \ref EPWM_FB_LEVEL_ADCRM
438  *                  - \ref EPWM_FB_LEVEL_ACMP0
439  *                  - \ref EPWM_FB_LEVEL_ACMP1
440  *                  - \ref EPWM_FB_LEVEL_BKP0
441  *                  - \ref EPWM_FB_LEVEL_BKP1
442  *                  - \ref EPWM_FB_LEVEL_SYS_CSS
443  *                  - \ref EPWM_FB_LEVEL_SYS_BOD
444  *                  - \ref EPWM_FB_LEVEL_SYS_RAM
445  *                  - \ref EPWM_FB_LEVEL_SYS_COR
446  * @return None
447  * @details This function is used to enable fault brake of selected channel(s).
448  *          The write-protection function should be disabled before using this function.
449  */
EPWM_EnableFaultBrake(EPWM_T * epwm,uint32_t u32ChannelMask,uint32_t u32LevelMask,uint32_t u32BrakeSource)450 void EPWM_EnableFaultBrake(EPWM_T *epwm, uint32_t u32ChannelMask, uint32_t u32LevelMask, uint32_t u32BrakeSource)
451 {
452     uint32_t i;
453 
454     for(i = 0UL; i < EPWM_CHANNEL_NUM; i++)
455     {
456         if(u32ChannelMask & (1UL << i))
457         {
458             if((u32BrakeSource == EPWM_FB_EDGE_SYS_CSS) || (u32BrakeSource == EPWM_FB_EDGE_SYS_BOD) || \
459                     (u32BrakeSource == EPWM_FB_EDGE_SYS_RAM) || (u32BrakeSource == EPWM_FB_EDGE_SYS_COR) || \
460                     (u32BrakeSource == EPWM_FB_LEVEL_SYS_CSS) || (u32BrakeSource == EPWM_FB_LEVEL_SYS_BOD) || \
461                     (u32BrakeSource == EPWM_FB_LEVEL_SYS_RAM) || (u32BrakeSource == EPWM_FB_LEVEL_SYS_COR))
462             {
463                 (epwm)->BRKCTL[i >> 1] |= (u32BrakeSource & (EPWM_BRKCTL0_1_SYSEBEN_Msk | EPWM_BRKCTL0_1_SYSLBEN_Msk));
464                 (epwm)->FAILBRK |= (u32BrakeSource & 0xFUL);
465             }
466             else
467             {
468                 (epwm)->BRKCTL[i >> 1] |= u32BrakeSource;
469             }
470         }
471 
472         if(u32LevelMask & (1UL << i))
473         {
474             if((i & 0x1UL) == 0UL)
475             {
476                 /* set brake action as high level for even channel */
477                 (epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAEVEN_Msk;
478                 (epwm)->BRKCTL[i >> 1] |= ((3UL) << EPWM_BRKCTL0_1_BRKAEVEN_Pos);
479             }
480             else
481             {
482                 /* set brake action as high level for odd channel */
483                 (epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAODD_Msk;
484                 (epwm)->BRKCTL[i >> 1] |= ((3UL) << EPWM_BRKCTL0_1_BRKAODD_Pos);
485             }
486         }
487         else
488         {
489             if((i & 0x1UL) == 0UL)
490             {
491                 /* set brake action as low level for even channel */
492                 (epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAEVEN_Msk;
493                 (epwm)->BRKCTL[i >> 1] |= ((2UL) << EPWM_BRKCTL0_1_BRKAEVEN_Pos);
494             }
495             else
496             {
497                 /* set brake action as low level for odd channel */
498                 (epwm)->BRKCTL[i >> 1] &= ~EPWM_BRKCTL0_1_BRKAODD_Msk;
499                 (epwm)->BRKCTL[i >> 1] |= ((2UL) << EPWM_BRKCTL0_1_BRKAODD_Pos);
500             }
501         }
502     }
503 }
504 
505 /**
506  * @brief Enable capture of selected channel(s)
507  * @param[in] epwm The pointer of the specified EPWM module
508  *                - EPWM0 : EPWM Group 0
509  *                - EPWM1 : EPWM Group 1
510  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
511  *                           Bit 0 is channel 0, bit 1 is channel 1...
512  * @return None
513  * @details This function is used to enable capture of selected channel(s).
514  */
EPWM_EnableCapture(EPWM_T * epwm,uint32_t u32ChannelMask)515 void EPWM_EnableCapture(EPWM_T *epwm, uint32_t u32ChannelMask)
516 {
517     (epwm)->CAPINEN |= u32ChannelMask;
518     (epwm)->CAPCTL |= u32ChannelMask;
519 }
520 
521 /**
522  * @brief Disable capture of selected channel(s)
523  * @param[in] epwm The pointer of the specified EPWM module
524  *                - EPWM0 : EPWM Group 0
525  *                - EPWM1 : EPWM Group 1
526  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
527  *                           Bit 0 is channel 0, bit 1 is channel 1...
528  * @return None
529  * @details This function is used to disable capture of selected channel(s).
530  */
EPWM_DisableCapture(EPWM_T * epwm,uint32_t u32ChannelMask)531 void EPWM_DisableCapture(EPWM_T *epwm, uint32_t u32ChannelMask)
532 {
533     (epwm)->CAPINEN &= ~u32ChannelMask;
534     (epwm)->CAPCTL &= ~u32ChannelMask;
535 }
536 
537 /**
538  * @brief Enables EPWM output generation of selected channel(s)
539  * @param[in] epwm The pointer of the specified EPWM module
540  *                - EPWM0 : EPWM Group 0
541  *                - EPWM1 : EPWM Group 1
542  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
543  *                           Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...
544  * @return None
545  * @details This function is used to enable EPWM output generation of selected channel(s).
546  */
EPWM_EnableOutput(EPWM_T * epwm,uint32_t u32ChannelMask)547 void EPWM_EnableOutput(EPWM_T *epwm, uint32_t u32ChannelMask)
548 {
549     (epwm)->POEN |= u32ChannelMask;
550 }
551 
552 /**
553  * @brief Disables EPWM output generation of selected channel(s)
554  * @param[in] epwm The pointer of the specified EPWM module
555  *                - EPWM0 : EPWM Group 0
556  *                - EPWM1 : EPWM Group 1
557  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel
558  *                           Set bit 0 to 1 disables channel 0 output, set bit 1 to 1 disables channel 1 output...
559  * @return None
560  * @details This function is used to disable EPWM output generation of selected channel(s).
561  */
EPWM_DisableOutput(EPWM_T * epwm,uint32_t u32ChannelMask)562 void EPWM_DisableOutput(EPWM_T *epwm, uint32_t u32ChannelMask)
563 {
564     (epwm)->POEN &= ~u32ChannelMask;
565 }
566 
567 /**
568  * @brief Enables PDMA transfer of selected channel for EPWM capture
569  * @param[in] epwm The pointer of the specified EPWM module
570  *                - EPWM0 : EPWM Group 0
571  *                - EPWM1 : EPWM Group 1
572  * @param[in] u32ChannelNum EPWM channel number.
573  * @param[in] u32RisingFirst The capture order is rising, falling first. Every two channels share the same setting. Valid values are TRUE and FALSE.
574  * @param[in] u32Mode Captured data transferred by PDMA interrupt type. It could be either
575  *              - \ref EPWM_CAPTURE_PDMA_RISING_LATCH
576  *              - \ref EPWM_CAPTURE_PDMA_FALLING_LATCH
577  *              - \ref EPWM_CAPTURE_PDMA_RISING_FALLING_LATCH
578  * @return None
579  * @details This function is used to enable PDMA transfer of selected channel(s) for EPWM capture.
580  * @note This function can only selects even or odd channel of pairs to do PDMA transfer.
581  */
EPWM_EnablePDMA(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32RisingFirst,uint32_t u32Mode)582 void EPWM_EnablePDMA(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32RisingFirst, uint32_t u32Mode)
583 {
584     uint32_t u32IsOddCh;
585     u32IsOddCh = u32ChannelNum & 0x1UL;
586     (epwm)->PDMACTL = ((epwm)->PDMACTL & ~((EPWM_PDMACTL_CHSEL0_1_Msk | EPWM_PDMACTL_CAPORD0_1_Msk | EPWM_PDMACTL_CAPMOD0_1_Msk) << ((u32ChannelNum >> 1) << 3))) | \
587                       (((u32IsOddCh << EPWM_PDMACTL_CHSEL0_1_Pos) | (u32RisingFirst << EPWM_PDMACTL_CAPORD0_1_Pos) | \
588                         u32Mode | EPWM_PDMACTL_CHEN0_1_Msk) << ((u32ChannelNum >> 1) << 3));
589 }
590 
591 /**
592  * @brief Disables PDMA transfer of selected channel for EPWM capture
593  * @param[in] epwm The pointer of the specified EPWM module
594  *                - EPWM0 : EPWM Group 0
595  *                - EPWM1 : EPWM Group 1
596  * @param[in] u32ChannelNum EPWM channel number.
597  * @return None
598  * @details This function is used to enable PDMA transfer of selected channel(s) for EPWM capture.
599  */
EPWM_DisablePDMA(EPWM_T * epwm,uint32_t u32ChannelNum)600 void EPWM_DisablePDMA(EPWM_T *epwm, uint32_t u32ChannelNum)
601 {
602     (epwm)->PDMACTL &= ~(EPWM_PDMACTL_CHEN0_1_Msk << ((u32ChannelNum >> 1) << 3));
603 }
604 
605 /**
606  * @brief Enable Dead zone of selected channel
607  * @param[in] epwm The pointer of the specified EPWM module
608  *                - EPWM0 : EPWM Group 0
609  *                - EPWM1 : EPWM Group 1
610  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
611  * @param[in] u32Duration Dead zone length in EPWM clock count, valid values are between 0~0xFFF, but 0 means there is no Dead zone.
612  * @return None
613  * @details This function is used to enable Dead zone of selected channel.
614  *          The write-protection function should be disabled before using this function.
615  * @note Every two channels share the same setting.
616  */
EPWM_EnableDeadZone(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Duration)617 void EPWM_EnableDeadZone(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Duration)
618 {
619     /* every two channels share the same setting */
620     (epwm)->DTCTL[(u32ChannelNum) >> 1] &= ~EPWM_DTCTL0_1_DTCNT_Msk;
621     (epwm)->DTCTL[(u32ChannelNum) >> 1] |= EPWM_DTCTL0_1_DTEN_Msk | u32Duration;
622 }
623 
624 /**
625  * @brief Disable Dead zone of selected channel
626  * @param[in] epwm The pointer of the specified EPWM module
627  *                - EPWM0 : EPWM Group 0
628  *                - EPWM1 : EPWM Group 1
629  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
630  * @return None
631  * @details This function is used to disable Dead zone of selected channel.
632  *          The write-protection function should be disabled before using this function.
633  */
EPWM_DisableDeadZone(EPWM_T * epwm,uint32_t u32ChannelNum)634 void EPWM_DisableDeadZone(EPWM_T *epwm, uint32_t u32ChannelNum)
635 {
636     /* every two channels shares the same setting */
637     (epwm)->DTCTL[(u32ChannelNum) >> 1] &= ~EPWM_DTCTL0_1_DTEN_Msk;
638 }
639 
640 /**
641  * @brief Enable capture interrupt of selected channel.
642  * @param[in] epwm The pointer of the specified EPWM module
643  *                - EPWM0 : EPWM Group 0
644  *                - EPWM1 : EPWM Group 1
645  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
646  * @param[in] u32Edge Rising or falling edge to latch counter.
647  *              - \ref EPWM_CAPTURE_INT_RISING_LATCH
648  *              - \ref EPWM_CAPTURE_INT_FALLING_LATCH
649  * @return None
650  * @details This function is used to enable capture interrupt of selected channel.
651  */
EPWM_EnableCaptureInt(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Edge)652 void EPWM_EnableCaptureInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Edge)
653 {
654     (epwm)->CAPIEN |= (u32Edge << u32ChannelNum);
655 }
656 
657 /**
658  * @brief Disable capture interrupt of selected channel.
659  * @param[in] epwm The pointer of the specified EPWM module
660  *                - EPWM0 : EPWM Group 0
661  *                - EPWM1 : EPWM Group 1
662  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
663  * @param[in] u32Edge Rising or falling edge to latch counter.
664  *              - \ref EPWM_CAPTURE_INT_RISING_LATCH
665  *              - \ref EPWM_CAPTURE_INT_FALLING_LATCH
666  * @return None
667  * @details This function is used to disable capture interrupt of selected channel.
668  */
EPWM_DisableCaptureInt(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Edge)669 void EPWM_DisableCaptureInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Edge)
670 {
671     (epwm)->CAPIEN &= ~(u32Edge << u32ChannelNum);
672 }
673 
674 /**
675  * @brief Clear capture interrupt of selected channel.
676  * @param[in] epwm The pointer of the specified EPWM module
677  *                - EPWM0 : EPWM Group 0
678  *                - EPWM1 : EPWM Group 1
679  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
680  * @param[in] u32Edge Rising or falling edge to latch counter.
681  *              - \ref EPWM_CAPTURE_INT_RISING_LATCH
682  *              - \ref EPWM_CAPTURE_INT_FALLING_LATCH
683  * @return None
684  * @details This function is used to clear capture interrupt of selected channel.
685  */
EPWM_ClearCaptureIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32Edge)686 void EPWM_ClearCaptureIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32Edge)
687 {
688     (epwm)->CAPIF = (u32Edge << u32ChannelNum);
689 }
690 
691 /**
692  * @brief Get capture interrupt of selected channel.
693  * @param[in] epwm The pointer of the specified EPWM module
694  *                - EPWM0 : EPWM Group 0
695  *                - EPWM1 : EPWM Group 1
696  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
697  * @retval 0 No capture interrupt
698  * @retval 1 Rising edge latch interrupt
699  * @retval 2 Falling edge latch interrupt
700  * @retval 3 Rising and falling latch interrupt
701  * @details This function is used to get capture interrupt of selected channel.
702  */
EPWM_GetCaptureIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)703 uint32_t EPWM_GetCaptureIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
704 {
705     uint32_t u32CapIf = 0UL;
706 
707     u32CapIf = ((((epwm)->CAPIF & (EPWM_CAPIF_CFLIF0_Msk << u32ChannelNum)) ? 1UL : 0UL) << 1);
708     u32CapIf |= (((epwm)->CAPIF & (EPWM_CAPIF_CRLIF0_Msk << u32ChannelNum)) ? 1UL : 0UL);
709     return u32CapIf;
710 }
711 /**
712  * @brief Enable duty interrupt of selected channel
713  * @param[in] epwm The pointer of the specified EPWM module
714  *                - EPWM0 : EPWM Group 0
715  *                - EPWM1 : EPWM Group 1
716  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
717  * @param[in] u32IntDutyType Duty interrupt type, could be either
718  *              - \ref EPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP
719  *              - \ref EPWM_DUTY_INT_UP_COUNT_MATCH_CMP
720  * @return None
721  * @details This function is used to enable duty interrupt of selected channel.
722  */
EPWM_EnableDutyInt(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32IntDutyType)723 void EPWM_EnableDutyInt(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
724 {
725     (epwm)->INTEN0 |= (u32IntDutyType << u32ChannelNum);
726 }
727 
728 /**
729  * @brief Disable duty interrupt of selected channel
730  * @param[in] epwm The pointer of the specified EPWM module
731  *                - EPWM0 : EPWM Group 0
732  *                - EPWM1 : EPWM Group 1
733  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
734  * @return None
735  * @details This function is used to disable duty interrupt of selected channel.
736  */
EPWM_DisableDutyInt(EPWM_T * epwm,uint32_t u32ChannelNum)737 void EPWM_DisableDutyInt(EPWM_T *epwm, uint32_t u32ChannelNum)
738 {
739     (epwm)->INTEN0 &= ~((EPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP | EPWM_DUTY_INT_UP_COUNT_MATCH_CMP) << u32ChannelNum);
740 }
741 
742 /**
743  * @brief Clear duty interrupt flag of selected channel
744  * @param[in] epwm The pointer of the specified EPWM module
745  *                - EPWM0 : EPWM Group 0
746  *                - EPWM1 : EPWM Group 1
747  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
748  * @return None
749  * @details This function is used to clear duty interrupt flag of selected channel.
750  */
EPWM_ClearDutyIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)751 void EPWM_ClearDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
752 {
753     (epwm)->INTSTS0 = (EPWM_INTSTS0_CMPUIF0_Msk | EPWM_INTSTS0_CMPDIF0_Msk) << u32ChannelNum;
754 }
755 
756 /**
757  * @brief Get duty interrupt flag of selected channel
758  * @param[in] epwm The pointer of the specified EPWM module
759  *                - EPWM0 : EPWM Group 0
760  *                - EPWM1 : EPWM Group 1
761  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
762  * @return Duty interrupt flag of specified channel
763  * @retval 0 Duty interrupt did not occur
764  * @retval 1 Duty interrupt occurred
765  * @details This function is used to get duty interrupt flag of selected channel.
766  */
EPWM_GetDutyIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)767 uint32_t EPWM_GetDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
768 {
769     return ((((epwm)->INTSTS0 & ((EPWM_INTSTS0_CMPDIF0_Msk | EPWM_INTSTS0_CMPUIF0_Msk) << u32ChannelNum))) ? 1UL : 0UL);
770 }
771 
772 /**
773  * @brief This function enable fault brake interrupt
774  * @param[in] epwm The pointer of the specified EPWM module
775  * @param[in] u32BrakeSource Fault brake source.
776  *              - \ref EPWM_FB_EDGE
777  *              - \ref EPWM_FB_LEVEL
778  * @return None
779  * @details This function is used to enable fault brake interrupt.
780  *          The write-protection function should be disabled before using this function.
781  * @note Every two channels share the same setting.
782  */
EPWM_EnableFaultBrakeInt(EPWM_T * epwm,uint32_t u32BrakeSource)783 void EPWM_EnableFaultBrakeInt(EPWM_T *epwm, uint32_t u32BrakeSource)
784 {
785     (epwm)->INTEN1 |= (0x7UL << u32BrakeSource);
786 }
787 
788 /**
789  * @brief This function disable fault brake interrupt
790  * @param[in] epwm The pointer of the specified EPWM module
791  * @param[in] u32BrakeSource Fault brake source.
792  *              - \ref EPWM_FB_EDGE
793  *              - \ref EPWM_FB_LEVEL
794  * @return None
795  * @details This function is used to disable fault brake interrupt.
796  *          The write-protection function should be disabled before using this function.
797  * @note Every two channels share the same setting.
798  */
EPWM_DisableFaultBrakeInt(EPWM_T * epwm,uint32_t u32BrakeSource)799 void EPWM_DisableFaultBrakeInt(EPWM_T *epwm, uint32_t u32BrakeSource)
800 {
801     (epwm)->INTEN1 &= ~(0x7UL << u32BrakeSource);
802 }
803 
804 /**
805  * @brief This function clear fault brake interrupt of selected source
806  * @param[in] epwm The pointer of the specified EPWM module
807  * @param[in] u32BrakeSource Fault brake source.
808  *              - \ref EPWM_FB_EDGE
809  *              - \ref EPWM_FB_LEVEL
810  * @return None
811  * @details This function is used to clear fault brake interrupt of selected source.
812  *          The write-protection function should be disabled before using this function.
813  */
EPWM_ClearFaultBrakeIntFlag(EPWM_T * epwm,uint32_t u32BrakeSource)814 void EPWM_ClearFaultBrakeIntFlag(EPWM_T *epwm, uint32_t u32BrakeSource)
815 {
816     (epwm)->INTSTS1 = (0x3fUL << u32BrakeSource);
817 }
818 
819 /**
820  * @brief This function get fault brake interrupt flag of selected source
821  * @param[in] epwm The pointer of the specified EPWM module
822  * @param[in] u32BrakeSource Fault brake source, could be either
823  *              - \ref EPWM_FB_EDGE
824  *              - \ref EPWM_FB_LEVEL
825  * @return Fault brake interrupt flag of specified source
826  * @retval 0 Fault brake interrupt did not occurred
827  * @retval 1 Fault brake interrupt occurred
828  * @details This function is used to get fault brake interrupt flag of selected source.
829  */
EPWM_GetFaultBrakeIntFlag(EPWM_T * epwm,uint32_t u32BrakeSource)830 uint32_t EPWM_GetFaultBrakeIntFlag(EPWM_T *epwm, uint32_t u32BrakeSource)
831 {
832     return (((epwm)->INTSTS1 & (0x3fUL << u32BrakeSource)) ? 1UL : 0UL);
833 }
834 
835 /**
836  * @brief Enable period interrupt of selected channel
837  * @param[in] epwm The pointer of the specified EPWM module
838  *                - EPWM0 : EPWM Group 0
839  *                - EPWM1 : EPWM Group 1
840  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
841  * @param[in] u32IntPeriodType Period interrupt type. This parameter is not used.
842  * @return None
843  * @details This function is used to enable period interrupt of selected channel.
844  */
EPWM_EnablePeriodInt(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32IntPeriodType)845 void EPWM_EnablePeriodInt(EPWM_T *epwm, uint32_t u32ChannelNum,  uint32_t u32IntPeriodType)
846 {
847     (void)u32IntPeriodType;
848     (epwm)->INTEN0 |= (EPWM_INTEN0_PIEN0_Msk << u32ChannelNum);
849 }
850 
851 /**
852  * @brief Disable period interrupt of selected channel
853  * @param[in] epwm The pointer of the specified EPWM module
854  *                - EPWM0 : EPWM Group 0
855  *                - EPWM1 : EPWM Group 1
856  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
857  * @return None
858  * @details This function is used to disable period interrupt of selected channel.
859  */
EPWM_DisablePeriodInt(EPWM_T * epwm,uint32_t u32ChannelNum)860 void EPWM_DisablePeriodInt(EPWM_T *epwm, uint32_t u32ChannelNum)
861 {
862     (epwm)->INTEN0 &= ~(EPWM_INTEN0_PIEN0_Msk << u32ChannelNum);
863 }
864 
865 /**
866  * @brief Clear period interrupt of selected channel
867  * @param[in] epwm The pointer of the specified EPWM module
868  *                - EPWM0 : EPWM Group 0
869  *                - EPWM1 : EPWM Group 1
870  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
871  * @return None
872  * @details This function is used to clear period interrupt of selected channel.
873  */
EPWM_ClearPeriodIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)874 void EPWM_ClearPeriodIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
875 {
876     (epwm)->INTSTS0 = (EPWM_INTSTS0_PIF0_Msk << u32ChannelNum);
877 }
878 
879 /**
880  * @brief Get period interrupt of selected channel
881  * @param[in] epwm The pointer of the specified EPWM module
882  *                - EPWM0 : EPWM Group 0
883  *                - EPWM1 : EPWM Group 1
884  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
885  * @return Period interrupt flag of specified channel
886  * @retval 0 Period interrupt did not occur
887  * @retval 1 Period interrupt occurred
888  * @details This function is used to get period interrupt of selected channel.
889  */
EPWM_GetPeriodIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)890 uint32_t EPWM_GetPeriodIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
891 {
892     return ((((epwm)->INTSTS0 & (EPWM_INTSTS0_PIF0_Msk << u32ChannelNum))) ? 1UL : 0UL);
893 }
894 
895 /**
896  * @brief Enable zero interrupt of selected channel
897  * @param[in] epwm The pointer of the specified EPWM module
898  *                - EPWM0 : EPWM Group 0
899  *                - EPWM1 : EPWM Group 1
900  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
901  * @return None
902  * @details This function is used to enable zero interrupt of selected channel.
903  */
EPWM_EnableZeroInt(EPWM_T * epwm,uint32_t u32ChannelNum)904 void EPWM_EnableZeroInt(EPWM_T *epwm, uint32_t u32ChannelNum)
905 {
906     (epwm)->INTEN0 |= (EPWM_INTEN0_ZIEN0_Msk << u32ChannelNum);
907 }
908 
909 /**
910  * @brief Disable zero interrupt of selected channel
911  * @param[in] epwm The pointer of the specified EPWM module
912  *                - EPWM0 : EPWM Group 0
913  *                - EPWM1 : EPWM Group 1
914  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
915  * @return None
916  * @details This function is used to disable zero interrupt of selected channel.
917  */
EPWM_DisableZeroInt(EPWM_T * epwm,uint32_t u32ChannelNum)918 void EPWM_DisableZeroInt(EPWM_T *epwm, uint32_t u32ChannelNum)
919 {
920     (epwm)->INTEN0 &= ~(EPWM_INTEN0_ZIEN0_Msk << u32ChannelNum);
921 }
922 
923 /**
924  * @brief Clear zero interrupt of selected channel
925  * @param[in] epwm The pointer of the specified EPWM module
926  *                - EPWM0 : EPWM Group 0
927  *                - EPWM1 : EPWM Group 1
928  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
929  * @return None
930  * @details This function is used to clear zero interrupt of selected channel.
931  */
EPWM_ClearZeroIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)932 void EPWM_ClearZeroIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
933 {
934     (epwm)->INTSTS0 = (EPWM_INTSTS0_ZIF0_Msk << u32ChannelNum);
935 }
936 
937 /**
938  * @brief Get zero interrupt of selected channel
939  * @param[in] epwm The pointer of the specified EPWM module
940  *                - EPWM0 : EPWM Group 0
941  *                - EPWM1 : EPWM Group 1
942  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
943  * @return Zero interrupt flag of specified channel
944  * @retval 0 Zero interrupt did not occur
945  * @retval 1 Zero interrupt occurred
946  * @details This function is used to get zero interrupt of selected channel.
947  */
EPWM_GetZeroIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)948 uint32_t EPWM_GetZeroIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
949 {
950     return ((((epwm)->INTSTS0 & (EPWM_INTSTS0_ZIF0_Msk << u32ChannelNum))) ? 1UL : 0UL);
951 }
952 
953 /**
954  * @brief Enable interrupt flag accumulator of selected channel
955  * @param[in] epwm The pointer of the specified EPWM module
956  *                - EPWM0 : EPWM Group 0
957  *                - EPWM1 : EPWM Group 1
958  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
959  * @param[in] u32IntFlagCnt Interrupt flag counter. Valid values are between 0~65535.
960  * @param[in] u32IntAccSrc Interrupt flag accumulator source selection.
961  *              - \ref EPWM_IFA_ZERO_POINT
962  *              - \ref EPWM_IFA_PERIOD_POINT
963  *              - \ref EPWM_IFA_COMPARE_UP_COUNT_POINT
964  *              - \ref EPWM_IFA_COMPARE_DOWN_COUNT_POINT
965  * @return None
966  * @details This function is used to enable interrupt flag accumulator of selected channel.
967  */
EPWM_EnableAcc(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32IntFlagCnt,uint32_t u32IntAccSrc)968 void EPWM_EnableAcc(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32IntFlagCnt, uint32_t u32IntAccSrc)
969 {
970     (epwm)->IFA[u32ChannelNum] = (((epwm)->IFA[u32ChannelNum] & ~((EPWM_IFA0_IFACNT_Msk | EPWM_IFA0_IFASEL_Msk))) | \
971                                   (EPWM_IFA0_IFAEN_Msk | (u32IntAccSrc << EPWM_IFA0_IFASEL_Pos) | u32IntFlagCnt));
972 }
973 
974 /**
975  * @brief Disable interrupt flag accumulator of selected channel
976  * @param[in] epwm The pointer of the specified EPWM module
977  *                - EPWM0 : EPWM Group 0
978  *                - EPWM1 : EPWM Group 1
979  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
980  * @return None
981  * @details This function is used to Disable interrupt flag accumulator of selected channel.
982  */
EPWM_DisableAcc(EPWM_T * epwm,uint32_t u32ChannelNum)983 void EPWM_DisableAcc(EPWM_T *epwm, uint32_t u32ChannelNum)
984 {
985     (epwm)->IFA[u32ChannelNum] = ((epwm)->IFA[u32ChannelNum] & ~(EPWM_IFA0_IFAEN_Msk));
986 }
987 
988 /**
989  * @brief Enable interrupt flag accumulator interrupt of selected channel
990  * @param[in] epwm The pointer of the specified EPWM module
991  *                - EPWM0 : EPWM Group 0
992  *                - EPWM1 : EPWM Group 1
993  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
994  * @return None
995  * @details This function is used to enable interrupt flag accumulator interrupt of selected channel.
996  */
EPWM_EnableAccInt(EPWM_T * epwm,uint32_t u32ChannelNum)997 void EPWM_EnableAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
998 {
999     (epwm)->AINTEN |= (1UL << (u32ChannelNum));
1000 }
1001 
1002 /**
1003  * @brief Disable interrupt flag accumulator interrupt of selected channel
1004  * @param[in] epwm The pointer of the specified EPWM module
1005  *                - EPWM0 : EPWM Group 0
1006  *                - EPWM1 : EPWM Group 1
1007  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1008  * @return None
1009  * @details This function is used to disable interrupt flag accumulator interrupt of selected channel.
1010  */
EPWM_DisableAccInt(EPWM_T * epwm,uint32_t u32ChannelNum)1011 void EPWM_DisableAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1012 {
1013     (epwm)->AINTEN &= ~(1UL << (u32ChannelNum));
1014 }
1015 
1016 /**
1017  * @brief Clear interrupt flag accumulator interrupt of selected channel
1018  * @param[in] epwm The pointer of the specified EPWM module
1019  *                - EPWM0 : EPWM Group 0
1020  *                - EPWM1 : EPWM Group 1
1021  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1022  * @return None
1023  * @details This function is used to clear interrupt flag accumulator interrupt of selected channel.
1024  */
EPWM_ClearAccInt(EPWM_T * epwm,uint32_t u32ChannelNum)1025 void EPWM_ClearAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1026 {
1027     (epwm)->AINTSTS = (1UL << (u32ChannelNum));
1028 }
1029 
1030 /**
1031  * @brief Get interrupt flag accumulator interrupt of selected channel
1032  * @param[in] epwm The pointer of the specified EPWM module
1033  *                - EPWM0 : EPWM Group 0
1034  *                - EPWM1 : EPWM Group 1
1035  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1036  * @retval 0 Accumulator interrupt did not occur
1037  * @retval 1 Accumulator interrupt occurred
1038  * @details This function is used to Get interrupt flag accumulator interrupt of selected channel.
1039  */
EPWM_GetAccInt(EPWM_T * epwm,uint32_t u32ChannelNum)1040 uint32_t EPWM_GetAccInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1041 {
1042     return (((epwm)->AINTSTS & (1UL << (u32ChannelNum))) ? 1UL : 0UL);
1043 }
1044 
1045 /**
1046  * @brief Enable accumulator PDMA of selected channel
1047  * @param[in] epwm The pointer of the specified EPWM module
1048  *                - EPWM0 : EPWM Group 0
1049  *                - EPWM1 : EPWM Group 1
1050  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1051  * @return None
1052  * @details This function is used to enable accumulator interrupt trigger PDMA of selected channel.
1053  */
EPWM_EnableAccPDMA(EPWM_T * epwm,uint32_t u32ChannelNum)1054 void EPWM_EnableAccPDMA(EPWM_T *epwm, uint32_t u32ChannelNum)
1055 {
1056     (epwm)->APDMACTL |= (1UL << (u32ChannelNum));
1057 }
1058 
1059 /**
1060  * @brief Disable accumulator PDMA of selected channel
1061  * @param[in] epwm The pointer of the specified EPWM module
1062  *                - EPWM0 : EPWM Group 0
1063  *                - EPWM1 : EPWM Group 1
1064  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1065  * @return None
1066  * @details This function is used to disable accumulator interrupt trigger PDMA of selected channel.
1067  */
EPWM_DisableAccPDMA(EPWM_T * epwm,uint32_t u32ChannelNum)1068 void EPWM_DisableAccPDMA(EPWM_T *epwm, uint32_t u32ChannelNum)
1069 {
1070     (epwm)->APDMACTL &= ~(1UL << (u32ChannelNum));
1071 }
1072 
1073 /**
1074  * @brief Enable interrupt flag accumulator stop mode of selected channel
1075  * @param[in] epwm The pointer of the specified EPWM module
1076  *                - EPWM0 : EPWM Group 0
1077  *                - EPWM1 : EPWM Group 1
1078  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1079  * @return None
1080  * @details This function is used to enable interrupt flag accumulator stop mode of selected channel.
1081  */
EPWM_EnableAccStopMode(EPWM_T * epwm,uint32_t u32ChannelNum)1082 void EPWM_EnableAccStopMode(EPWM_T *epwm, uint32_t u32ChannelNum)
1083 {
1084     (epwm)->IFA[u32ChannelNum] |= EPWM_IFA0_STPMOD_Msk;
1085 }
1086 
1087 /**
1088  * @brief Disable interrupt flag accumulator stop mode of selected channel
1089  * @param[in] epwm The pointer of the specified EPWM module
1090  *                - EPWM0 : EPWM Group 0
1091  *                - EPWM1 : EPWM Group 1
1092  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1093  * @return None
1094  * @details This function is used to disable interrupt flag accumulator stop mode of selected channel.
1095  */
EPWM_DisableAccStopMode(EPWM_T * epwm,uint32_t u32ChannelNum)1096 void EPWM_DisableAccStopMode(EPWM_T *epwm, uint32_t u32ChannelNum)
1097 {
1098     (epwm)->IFA[u32ChannelNum] &= ~EPWM_IFA0_STPMOD_Msk;
1099 }
1100 
1101 /**
1102  * @brief Clear free trigger duty interrupt flag of selected channel
1103  * @param[in] epwm The pointer of the specified EPWM module
1104  *                - EPWM0 : EPWM Group 0
1105  *                - EPWM1 : EPWM Group 1
1106  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1107  * @return None
1108  * @details This function is used to clear free trigger duty interrupt flag of selected channel.
1109  */
EPWM_ClearFTDutyIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)1110 void EPWM_ClearFTDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
1111 {
1112     (epwm)->FTCI = ((EPWM_FTCI_FTCMU0_Msk | EPWM_FTCI_FTCMD0_Msk) << (u32ChannelNum >> 1));
1113 }
1114 
1115 /**
1116  * @brief Get free trigger duty interrupt flag of selected channel
1117  * @param[in] epwm The pointer of the specified EPWM module
1118  *                - EPWM0 : EPWM Group 0
1119  *                - EPWM1 : EPWM Group 1
1120  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1121  * @return Duty interrupt flag of specified channel
1122  * @retval 0 Free trigger duty interrupt did not occur
1123  * @retval 1 Free trigger duty interrupt occurred
1124  * @details This function is used to get free trigger duty interrupt flag of selected channel.
1125  */
EPWM_GetFTDutyIntFlag(EPWM_T * epwm,uint32_t u32ChannelNum)1126 uint32_t EPWM_GetFTDutyIntFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
1127 {
1128     return (((epwm)->FTCI & ((EPWM_FTCI_FTCMU0_Msk | EPWM_FTCI_FTCMD0_Msk) << (u32ChannelNum >> 1))) ? 1UL : 0UL);
1129 }
1130 
1131 /**
1132  * @brief Enable load mode of selected channel
1133  * @param[in] epwm The pointer of the specified EPWM module
1134  *                - EPWM0 : EPWM Group 0
1135  *                - EPWM1 : EPWM Group 1
1136  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1137  * @param[in] u32LoadMode EPWM counter loading mode.
1138  *              - \ref EPWM_LOAD_MODE_IMMEDIATE
1139  *              - \ref EPWM_LOAD_MODE_WINDOW
1140  *              - \ref EPWM_LOAD_MODE_CENTER
1141  * @return None
1142  * @details This function is used to enable load mode of selected channel.
1143  */
EPWM_EnableLoadMode(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32LoadMode)1144 void EPWM_EnableLoadMode(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
1145 {
1146     (epwm)->CTL0 |= (u32LoadMode << u32ChannelNum);
1147 }
1148 
1149 /**
1150  * @brief Disable load mode of selected channel
1151  * @param[in] epwm The pointer of the specified EPWM module
1152  *                - EPWM0 : EPWM Group 0
1153  *                - EPWM1 : EPWM Group 1
1154  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1155  * @param[in] u32LoadMode EPWM counter loading mode.
1156  *              - \ref EPWM_LOAD_MODE_IMMEDIATE
1157  *              - \ref EPWM_LOAD_MODE_WINDOW
1158  *              - \ref EPWM_LOAD_MODE_CENTER
1159  * @return None
1160  * @details This function is used to disable load mode of selected channel.
1161  */
EPWM_DisableLoadMode(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32LoadMode)1162 void EPWM_DisableLoadMode(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
1163 {
1164     (epwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum);
1165 }
1166 
1167 /**
1168  * @brief Configure synchronization phase of selected channel
1169  * @param[in] epwm The pointer of the specified EPWM module
1170  *                - EPWM0 : EPWM Group 0
1171  *                - EPWM1 : EPWM Group 1
1172  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1173  * @param[in] u32SyncSrc EPWM synchronize source selection.
1174  *              - \ref EPWM_SYNC_OUT_FROM_SYNCIN_SWSYNC
1175  *              - \ref EPWM_SYNC_OUT_FROM_COUNT_TO_ZERO
1176  *              - \ref EPWM_SYNC_OUT_FROM_COUNT_TO_COMPARATOR
1177  *              - \ref EPWM_SYNC_OUT_DISABLE
1178  * @param[in] u32Direction Phase direction. Control EPWM counter count decrement or increment  after synchronizing.
1179  *              - \ref EPWM_PHS_DIR_DECREMENT
1180  *              - \ref EPWM_PHS_DIR_INCREMENT
1181  * @param[in] u32StartPhase Synchronous start phase value. Valid values are between 0~65535.
1182  * @return None
1183  * @details This function is used to configure synchronization phase of selected channel.
1184  * @note Every two channels share the same setting.
1185  */
EPWM_ConfigSyncPhase(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32SyncSrc,uint32_t u32Direction,uint32_t u32StartPhase)1186 void EPWM_ConfigSyncPhase(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32SyncSrc, uint32_t u32Direction, uint32_t u32StartPhase)
1187 {
1188     /* every two channels shares the same setting */
1189     u32ChannelNum >>= 1;
1190     (epwm)->SYNC = (((epwm)->SYNC & ~((EPWM_SYNC_SINSRC0_Msk << (u32ChannelNum << 1)) | (EPWM_SYNC_PHSDIR0_Msk << u32ChannelNum))) | \
1191                     (u32Direction << EPWM_SYNC_PHSDIR0_Pos << u32ChannelNum) | (u32SyncSrc << EPWM_SYNC_SINSRC0_Pos) << (u32ChannelNum << 1));
1192     (epwm)->PHS[(u32ChannelNum)] = u32StartPhase;
1193 }
1194 
1195 
1196 /**
1197  * @brief Enable SYNC phase of selected channel(s)
1198  * @param[in] epwm The pointer of the specified EPWM module
1199  *                - EPWM0 : EPWM Group 0
1200  *                - EPWM1 : EPWM Group 1
1201  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
1202  *                           Bit 0 is channel 0, bit 1 is channel 1...
1203  * @return None
1204  * @details This function is used to enable SYNC phase of selected channel(s).
1205  * @note Every two channels share the same setting.
1206  */
EPWM_EnableSyncPhase(EPWM_T * epwm,uint32_t u32ChannelMask)1207 void EPWM_EnableSyncPhase(EPWM_T *epwm, uint32_t u32ChannelMask)
1208 {
1209     uint32_t i;
1210     for(i = 0UL; i < EPWM_CHANNEL_NUM; i ++)
1211     {
1212         if(u32ChannelMask & (1UL << i))
1213         {
1214             (epwm)->SYNC |= (EPWM_SYNC_PHSEN0_Msk << (i >> 1));
1215         }
1216     }
1217 }
1218 
1219 /**
1220  * @brief Disable SYNC phase of selected channel(s)
1221  * @param[in] epwm The pointer of the specified EPWM module
1222  *                - EPWM0 : EPWM Group 0
1223  *                - EPWM1 : EPWM Group 1
1224  * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.
1225  *                           Bit 0 is channel 0, bit 1 is channel 1...
1226  * @return None
1227  * @details This function is used to disable SYNC phase of selected channel(s).
1228  * @note Every two channels share the same setting.
1229  */
EPWM_DisableSyncPhase(EPWM_T * epwm,uint32_t u32ChannelMask)1230 void EPWM_DisableSyncPhase(EPWM_T *epwm, uint32_t u32ChannelMask)
1231 {
1232     uint32_t i;
1233     for(i = 0UL; i < EPWM_CHANNEL_NUM; i ++)
1234     {
1235         if(u32ChannelMask & (1UL << i))
1236         {
1237             (epwm)->SYNC &= ~(EPWM_SYNC_PHSEN0_Msk << (i >> 1));
1238         }
1239     }
1240 }
1241 
1242 /**
1243  * @brief Enable EPWM SYNC_IN noise filter function
1244  * @param[in] epwm The pointer of the specified EPWM module
1245  *                - EPWM0 : EPWM Group 0
1246  *                - EPWM1 : EPWM Group 1
1247  * @param[in] u32ClkCnt SYNC Edge Detector Filter Count. This controls the counter number of edge detector.
1248  *            The valid value is 0~7.
1249  * @param[in] u32ClkDivSel SYNC Edge Detector Filter Clock Selection.
1250  *              - \ref EPWM_NF_CLK_DIV_1
1251  *              - \ref EPWM_NF_CLK_DIV_2
1252  *              - \ref EPWM_NF_CLK_DIV_4
1253  *              - \ref EPWM_NF_CLK_DIV_8
1254  *              - \ref EPWM_NF_CLK_DIV_16
1255  *              - \ref EPWM_NF_CLK_DIV_32
1256  *              - \ref EPWM_NF_CLK_DIV_64
1257  *              - \ref EPWM_NF_CLK_DIV_128
1258  * @return None
1259  * @details This function is used to enable EPWM SYNC_IN noise filter function.
1260  */
EPWM_EnableSyncNoiseFilter(EPWM_T * epwm,uint32_t u32ClkCnt,uint32_t u32ClkDivSel)1261 void EPWM_EnableSyncNoiseFilter(EPWM_T *epwm, uint32_t u32ClkCnt, uint32_t u32ClkDivSel)
1262 {
1263     (epwm)->SYNC = ((epwm)->SYNC & ~(EPWM_SYNC_SFLTCNT_Msk | EPWM_SYNC_SFLTCSEL_Msk)) | \
1264                    ((u32ClkCnt << EPWM_SYNC_SFLTCNT_Pos) | (u32ClkDivSel << EPWM_SYNC_SFLTCSEL_Pos) | EPWM_SYNC_SNFLTEN_Msk);
1265 }
1266 
1267 /**
1268  * @brief Disable EPWM SYNC_IN noise filter function
1269  * @param[in] epwm The pointer of the specified EPWM module
1270  *                - EPWM0 : EPWM Group 0
1271  *                - EPWM1 : EPWM Group 1
1272  * @return None
1273  * @details This function is used to Disable EPWM SYNC_IN noise filter function.
1274  */
EPWM_DisableSyncNoiseFilter(EPWM_T * epwm)1275 void EPWM_DisableSyncNoiseFilter(EPWM_T *epwm)
1276 {
1277     (epwm)->SYNC &= ~EPWM_SYNC_SNFLTEN_Msk;
1278 }
1279 
1280 /**
1281  * @brief Enable EPWM SYNC input pin inverse function
1282  * @param[in] epwm The pointer of the specified EPWM module
1283  *                - EPWM0 : EPWM Group 0
1284  *                - EPWM1 : EPWM Group 1
1285  * @return None
1286  * @details This function is used to enable EPWM SYNC input pin inverse function.
1287  */
EPWM_EnableSyncPinInverse(EPWM_T * epwm)1288 void EPWM_EnableSyncPinInverse(EPWM_T *epwm)
1289 {
1290     (epwm)->SYNC |= EPWM_SYNC_SINPINV_Msk;
1291 }
1292 
1293 /**
1294  * @brief Disable EPWM SYNC input pin inverse function
1295  * @param[in] epwm The pointer of the specified EPWM module
1296  *                - EPWM0 : EPWM Group 0
1297  *                - EPWM1 : EPWM Group 1
1298  * @return None
1299  * @details This function is used to Disable EPWM SYNC input pin inverse function.
1300  */
EPWM_DisableSyncPinInverse(EPWM_T * epwm)1301 void EPWM_DisableSyncPinInverse(EPWM_T *epwm)
1302 {
1303     (epwm)->SYNC &= (~EPWM_SYNC_SINPINV_Msk);
1304 }
1305 
1306 /**
1307  * @brief Set EPWM clock source
1308  * @param[in] epwm The pointer of the specified EPWM module
1309  *                - EPWM0 : EPWM Group 0
1310  *                - EPWM1 : EPWM Group 1
1311  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1312  * @param[in] u32ClkSrcSel EPWM external clock source.
1313  *              - \ref EPWM_CLKSRC_EPWM_CLK
1314  *              - \ref EPWM_CLKSRC_TIMER0
1315  *              - \ref EPWM_CLKSRC_TIMER1
1316  *              - \ref EPWM_CLKSRC_TIMER2
1317  *              - \ref EPWM_CLKSRC_TIMER3
1318  * @return None
1319  * @details This function is used to set EPWM clock source.
1320  * @note Every two channels share the same setting.
1321  * @note If the clock source of EPWM counter is selected from TIMERn interrupt events, the TRGEPWM(TIMERn_TRGCTL[1], n=0,1..3) bit must be set as 1.
1322  */
EPWM_SetClockSource(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32ClkSrcSel)1323 void EPWM_SetClockSource(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)
1324 {
1325     (epwm)->CLKSRC = ((epwm)->CLKSRC & ~(EPWM_CLKSRC_ECLKSRC0_Msk << ((u32ChannelNum >> 1) << 3))) | \
1326                      (u32ClkSrcSel << ((u32ChannelNum >> 1) << 3));
1327 }
1328 
1329 /**
1330  * @brief Enable EPWM brake noise filter function
1331  * @param[in] epwm The pointer of the specified EPWM module
1332  *                - EPWM0 : EPWM Group 0
1333  *                - EPWM1 : EPWM Group 1
1334  * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
1335  * @param[in] u32ClkCnt SYNC Edge Detector Filter Count. This controls the counter number of edge detector
1336  * @param[in] u32ClkDivSel SYNC Edge Detector Filter Clock Selection.
1337  *              - \ref EPWM_NF_CLK_DIV_1
1338  *              - \ref EPWM_NF_CLK_DIV_2
1339  *              - \ref EPWM_NF_CLK_DIV_4
1340  *              - \ref EPWM_NF_CLK_DIV_8
1341  *              - \ref EPWM_NF_CLK_DIV_16
1342  *              - \ref EPWM_NF_CLK_DIV_32
1343  *              - \ref EPWM_NF_CLK_DIV_64
1344  *              - \ref EPWM_NF_CLK_DIV_128
1345  * @return None
1346  * @details This function is used to enable EPWM brake noise filter function.
1347  */
EPWM_EnableBrakeNoiseFilter(EPWM_T * epwm,uint32_t u32BrakePinNum,uint32_t u32ClkCnt,uint32_t u32ClkDivSel)1348 void EPWM_EnableBrakeNoiseFilter(EPWM_T *epwm, uint32_t u32BrakePinNum, uint32_t u32ClkCnt, uint32_t u32ClkDivSel)
1349 {
1350     (epwm)->BNF = ((epwm)->BNF & ~((EPWM_BNF_BRK0FCNT_Msk | EPWM_BNF_BRK0NFSEL_Msk) << (u32BrakePinNum << 3))) | \
1351                   (((u32ClkCnt << EPWM_BNF_BRK0FCNT_Pos) | (u32ClkDivSel << EPWM_BNF_BRK0NFSEL_Pos) | EPWM_BNF_BRK0NFEN_Msk) << (u32BrakePinNum << 3));
1352 }
1353 
1354 /**
1355  * @brief Disable EPWM brake noise filter function
1356  * @param[in] epwm The pointer of the specified EPWM module
1357  *                - EPWM0 : EPWM Group 0
1358  *                - EPWM1 : EPWM Group 1
1359  * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
1360  * @return None
1361  * @details This function is used to disable EPWM brake noise filter function.
1362  */
EPWM_DisableBrakeNoiseFilter(EPWM_T * epwm,uint32_t u32BrakePinNum)1363 void EPWM_DisableBrakeNoiseFilter(EPWM_T *epwm, uint32_t u32BrakePinNum)
1364 {
1365     (epwm)->BNF &= ~(EPWM_BNF_BRK0NFEN_Msk << (u32BrakePinNum << 3));
1366 }
1367 
1368 /**
1369  * @brief Enable EPWM brake pin inverse function
1370  * @param[in] epwm The pointer of the specified EPWM module
1371  *                - EPWM0 : EPWM Group 0
1372  *                - EPWM1 : EPWM Group 1
1373  * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
1374  * @return None
1375  * @details This function is used to enable EPWM brake pin inverse function.
1376  */
EPWM_EnableBrakePinInverse(EPWM_T * epwm,uint32_t u32BrakePinNum)1377 void EPWM_EnableBrakePinInverse(EPWM_T *epwm, uint32_t u32BrakePinNum)
1378 {
1379     (epwm)->BNF |= (EPWM_BNF_BRK0PINV_Msk << (u32BrakePinNum << 3));
1380 }
1381 
1382 /**
1383  * @brief Disable EPWM brake pin inverse function
1384  * @param[in] epwm The pointer of the specified EPWM module
1385  *                - EPWM0 : EPWM Group 0
1386  *                - EPWM1 : EPWM Group 1
1387  * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
1388  * @return None
1389  * @details This function is used to disable EPWM brake pin inverse function.
1390  */
EPWM_DisableBrakePinInverse(EPWM_T * epwm,uint32_t u32BrakePinNum)1391 void EPWM_DisableBrakePinInverse(EPWM_T *epwm, uint32_t u32BrakePinNum)
1392 {
1393     (epwm)->BNF &= ~(EPWM_BNF_BRK0PINV_Msk << (u32BrakePinNum * (uint32_t)EPWM_BNF_BRK1NFEN_Pos));
1394 }
1395 
1396 /**
1397  * @brief Set EPWM brake pin source
1398  * @param[in] epwm The pointer of the specified EPWM module
1399  *                - EPWM0 : EPWM Group 0
1400  *                - EPWM1 : EPWM Group 1
1401  * @param[in] u32BrakePinNum Brake pin selection. Valid values are 0 or 1.
1402  * @param[in] u32SelAnotherModule Select to another module. Valid values are TRUE or FALSE.
1403  * @return None
1404  * @details This function is used to set EPWM brake pin source.
1405  */
EPWM_SetBrakePinSource(EPWM_T * epwm,uint32_t u32BrakePinNum,uint32_t u32SelAnotherModule)1406 void EPWM_SetBrakePinSource(EPWM_T *epwm, uint32_t u32BrakePinNum, uint32_t u32SelAnotherModule)
1407 {
1408     (epwm)->BNF = ((epwm)->BNF & ~(EPWM_BNF_BK0SRC_Msk << (u32BrakePinNum << 3))) | (u32SelAnotherModule << ((uint32_t)EPWM_BNF_BK0SRC_Pos + (u32BrakePinNum << 3)));
1409 }
1410 
1411 /**
1412  * @brief Set EPWM leading edge blanking function
1413  * @param[in] epwm The pointer of the specified EPWM module
1414  *                - EPWM0 : EPWM Group 0
1415  *                - EPWM1 : EPWM Group 1
1416  * @param[in] u32TrigSrcSel Leading edge blanking source selection.
1417  *              - \ref EPWM_LEBCTL_SRCEN0
1418  *              - \ref EPWM_LEBCTL_SRCEN2
1419  *              - \ref EPWM_LEBCTL_SRCEN4
1420  *              - \ref EPWM_LEBCTL_SRCEN0_2
1421  *              - \ref EPWM_LEBCTL_SRCEN0_4
1422  *              - \ref EPWM_LEBCTL_SRCEN2_4
1423  *              - \ref EPWM_LEBCTL_SRCEN0_2_4
1424  * @param[in] u32TrigType  Leading edge blanking trigger type.
1425  *              - \ref EPWM_LEBCTL_TRGTYPE_RISING
1426  *              - \ref EPWM_LEBCTL_TRGTYPE_FALLING
1427  *              - \ref EPWM_LEBCTL_TRGTYPE_RISING_OR_FALLING
1428  * @param[in] u32BlankingCnt  Leading Edge Blanking Counter. Valid values are between 1~512.
1429                               This counter value decides leading edge blanking window size, and this counter clock base is ECLK.
1430  * @param[in] u32BlankingEnable Enable EPWM leading edge blanking function. Valid values are TRUE (ENABLE) or FALSE (DISABLE).
1431  *              - \ref FALSE
1432  *              - \ref TRUE
1433  * @return None
1434  * @details This function is used to configure EPWM leading edge blanking function that blank the false trigger from ACMP brake source which may cause by EPWM output transition.
1435  * @note EPWM leading edge blanking function is only used for brake source from ACMP.
1436  */
EPWM_SetLeadingEdgeBlanking(EPWM_T * epwm,uint32_t u32TrigSrcSel,uint32_t u32TrigType,uint32_t u32BlankingCnt,uint32_t u32BlankingEnable)1437 void EPWM_SetLeadingEdgeBlanking(EPWM_T *epwm, uint32_t u32TrigSrcSel, uint32_t u32TrigType, uint32_t u32BlankingCnt, uint32_t u32BlankingEnable)
1438 {
1439     (epwm)->LEBCTL = (u32TrigType) | (u32TrigSrcSel) | (u32BlankingEnable);
1440     /* Blanking window size = LEBCNT + 1, so LEBCNT = u32BlankingCnt - 1 */
1441     (epwm)->LEBCNT = (u32BlankingCnt) - 1UL;
1442 }
1443 
1444 /**
1445  * @brief Get the time-base counter reached its maximum value flag of selected channel
1446  * @param[in] epwm The pointer of the specified EPWM module
1447  *                - EPWM0 : EPWM Group 0
1448  *                - EPWM1 : EPWM Group 1
1449  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1450  * @return Count to max interrupt flag of specified channel
1451  * @retval 0 Count to max interrupt did not occur
1452  * @retval 1 Count to max interrupt occurred
1453  * @details This function is used to get the time-base counter reached its maximum value flag of selected channel.
1454  */
EPWM_GetWrapAroundFlag(EPWM_T * epwm,uint32_t u32ChannelNum)1455 uint32_t EPWM_GetWrapAroundFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
1456 {
1457     return (((epwm)->STATUS & (EPWM_STATUS_CNTMAXF0_Msk << u32ChannelNum)) ? 1UL : 0UL);
1458 }
1459 
1460 /**
1461  * @brief Clear the time-base counter reached its maximum value flag of selected channel
1462  * @param[in] epwm The pointer of the specified EPWM module
1463  *                - EPWM0 : EPWM Group 0
1464  *                - EPWM1 : EPWM Group 1
1465  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5
1466  * @return None
1467  * @details This function is used to clear the time-base counter reached its maximum value flag of selected channel.
1468  */
EPWM_ClearWrapAroundFlag(EPWM_T * epwm,uint32_t u32ChannelNum)1469 void EPWM_ClearWrapAroundFlag(EPWM_T *epwm, uint32_t u32ChannelNum)
1470 {
1471     (epwm)->STATUS = (EPWM_STATUS_CNTMAXF0_Msk << u32ChannelNum);
1472 }
1473 
1474 /**
1475  * @brief Enable fault detect of selected channel.
1476  * @param[in] epwm The pointer of the specified EPWM module.
1477  *                - EPWM0 : EPWM Group 0
1478  *                - EPWM1 : EPWM Group 1
1479  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1480  * @param[in] u32AfterPrescaler Fault Detect Clock Source is from prescaler output. Valid values are TRUE (after prescaler) or FALSE (before prescaler).
1481  * @param[in] u32ClkSel Fault Detect Clock Select.
1482  *              - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_1
1483  *              - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_2
1484  *              - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_4
1485  *              - \ref EPWM_FDCTL_FDCKSEL_CLK_DIV_8
1486  * @return None
1487  * @details This function is used to enable fault detect of selected channel.
1488  */
EPWM_EnableFaultDetect(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32AfterPrescaler,uint32_t u32ClkSel)1489 void EPWM_EnableFaultDetect(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32AfterPrescaler, uint32_t u32ClkSel)
1490 {
1491     (epwm)->FDEN = ((epwm)->FDEN & ~(EPWM_FDEN_FDCKS0_Msk << (u32ChannelNum))) | \
1492                    ((EPWM_FDEN_FDEN0_Msk | ((u32AfterPrescaler) << EPWM_FDEN_FDCKS0_Pos)) << (u32ChannelNum));
1493     (epwm)->FDCTL[(u32ChannelNum)] = ((epwm)->FDCTL[(u32ChannelNum)] & ~EPWM_FDCTL0_FDCKSEL_Msk) | (u32ClkSel);
1494 }
1495 
1496 /**
1497  * @brief Disable fault detect of selected channel.
1498  * @param[in] epwm The pointer of the specified EPWM module.
1499  *                - EPWM0 : EPWM Group 0
1500  *                - EPWM1 : EPWM Group 1
1501  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1502  * @return None
1503  * @details This function is used to disable fault detect of selected channel.
1504  */
EPWM_DisableFaultDetect(EPWM_T * epwm,uint32_t u32ChannelNum)1505 void EPWM_DisableFaultDetect(EPWM_T *epwm, uint32_t u32ChannelNum)
1506 {
1507     (epwm)->FDEN &= ~(EPWM_FDEN_FDEN0_Msk << (u32ChannelNum));
1508 }
1509 
1510 /**
1511  * @brief Enable fault detect output of selected channel.
1512  * @param[in] epwm The pointer of the specified EPWM module.
1513  *                - EPWM0 : EPWM Group 0
1514  *                - EPWM1 : EPWM Group 1
1515  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1516  * @return None
1517  * @details This function is used to enable fault detect output of selected channel.
1518  */
EPWM_EnableFaultDetectOutput(EPWM_T * epwm,uint32_t u32ChannelNum)1519 void EPWM_EnableFaultDetectOutput(EPWM_T *epwm, uint32_t u32ChannelNum)
1520 {
1521     (epwm)->FDEN &= ~(EPWM_FDEN_FDODIS0_Msk << (u32ChannelNum));
1522 }
1523 
1524 /**
1525  * @brief Disable fault detect output of selected channel.
1526  * @param[in] epwm The pointer of the specified EPWM module.
1527  *                - EPWM0 : EPWM Group 0
1528  *                - EPWM1 : EPWM Group 1
1529  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1530  * @return None
1531  * @details This function is used to disable fault detect output of selected channel.
1532  */
EPWM_DisableFaultDetectOutput(EPWM_T * epwm,uint32_t u32ChannelNum)1533 void EPWM_DisableFaultDetectOutput(EPWM_T *epwm, uint32_t u32ChannelNum)
1534 {
1535     (epwm)->FDEN |= (EPWM_FDEN_FDODIS0_Msk << (u32ChannelNum));
1536 }
1537 
1538 /**
1539  * @brief Enable fault detect deglitch function of selected channel.
1540  * @param[in] epwm The pointer of the specified EPWM module.
1541  *                - EPWM0 : EPWM Group 0
1542  *                - EPWM1 : EPWM Group 1
1543  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1544  * @param[in] u32DeglitchSmpCycle Deglitch Sampling Cycle. Valid values are between 0~7.
1545  * @return None
1546  * @details This function is used to enable fault detect deglitch function of selected channel.
1547  */
EPWM_EnableFaultDetectDeglitch(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32DeglitchSmpCycle)1548 void EPWM_EnableFaultDetectDeglitch(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32DeglitchSmpCycle)
1549 {
1550     (epwm)->FDCTL[(u32ChannelNum)] = ((epwm)->FDCTL[(u32ChannelNum)] & (~EPWM_FDCTL0_DGSMPCYC_Msk)) | \
1551                                      (EPWM_FDCTL0_FDDGEN_Msk | ((u32DeglitchSmpCycle) << EPWM_FDCTL0_DGSMPCYC_Pos));
1552 }
1553 
1554 /**
1555  * @brief Disable fault detect deglitch function of selected channel.
1556  * @param[in] epwm The pointer of the specified EPWM module.
1557  *                - EPWM0 : EPWM Group 0
1558  *                - EPWM1 : EPWM Group 1
1559  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1560  * @return None
1561  * @details This function is used to disable fault detect deglitch function of selected channel.
1562  */
EPWM_DisableFaultDetectDeglitch(EPWM_T * epwm,uint32_t u32ChannelNum)1563 void EPWM_DisableFaultDetectDeglitch(EPWM_T *epwm, uint32_t u32ChannelNum)
1564 {
1565     (epwm)->FDCTL[(u32ChannelNum)] &= ~EPWM_FDCTL0_FDDGEN_Msk;
1566 }
1567 
1568 /**
1569  * @brief Enable fault detect mask function of selected channel.
1570  * @param[in] epwm The pointer of the specified EPWM module.
1571  *                - EPWM0 : EPWM Group 0
1572  *                - EPWM1 : EPWM Group 1
1573  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1574  * @param[in] u32MaskCnt Transition mask counter. Valid values are between 0~0x7F.
1575  * @return None
1576  * @details This function is used to enable fault detect mask function of selected channel.
1577  */
EPWM_EnableFaultDetectMask(EPWM_T * epwm,uint32_t u32ChannelNum,uint32_t u32MaskCnt)1578 void EPWM_EnableFaultDetectMask(EPWM_T *epwm, uint32_t u32ChannelNum, uint32_t u32MaskCnt)
1579 {
1580     (epwm)->FDCTL[(u32ChannelNum)] = ((epwm)->FDCTL[(u32ChannelNum)] & (~EPWM_FDCTL0_TRMSKCNT_Msk)) | (EPWM_FDCTL0_FDMSKEN_Msk | (u32MaskCnt));
1581 }
1582 
1583 /**
1584  * @brief Disable fault detect mask function of selected channel.
1585  * @param[in] epwm The pointer of the specified EPWM module.
1586  *                - EPWM0 : EPWM Group 0
1587  *                - EPWM1 : EPWM Group 1
1588  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1589  * @return None
1590  * @details This function is used to disable fault detect mask function of selected channel.
1591  */
EPWM_DisableFaultDetectMask(EPWM_T * epwm,uint32_t u32ChannelNum)1592 void EPWM_DisableFaultDetectMask(EPWM_T *epwm, uint32_t u32ChannelNum)
1593 {
1594     (epwm)->FDCTL[(u32ChannelNum)] &= ~EPWM_FDCTL0_FDMSKEN_Msk;
1595 }
1596 
1597 /**
1598  * @brief Enable fault detect interrupt of selected channel.
1599  * @param[in] epwm The pointer of the specified EPWM module.
1600  *                - EPWM0 : EPWM Group 0
1601  *                - EPWM1 : EPWM Group 1
1602  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1603  * @return None
1604  * @details This function is used to enable fault detect interrupt of selected channel.
1605  */
EPWM_EnableFaultDetectInt(EPWM_T * epwm,uint32_t u32ChannelNum)1606 void EPWM_EnableFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1607 {
1608     (epwm)->FDIEN |= (EPWM_FDIEN_FDIEN0_Msk << (u32ChannelNum));
1609 }
1610 
1611 /**
1612  * @brief Disable fault detect interrupt of selected channel.
1613  * @param[in] epwm The pointer of the specified EPWM module.
1614  *                - EPWM0 : EPWM Group 0
1615  *                - EPWM1 : EPWM Group 1
1616  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1617  * @return None
1618  * @details This function is used to disable fault detect interrupt of selected channel.
1619  */
EPWM_DisableFaultDetectInt(EPWM_T * epwm,uint32_t u32ChannelNum)1620 void EPWM_DisableFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1621 {
1622     (epwm)->FDIEN &= ~(EPWM_FDIEN_FDIEN0_Msk << (u32ChannelNum));
1623 }
1624 
1625 /**
1626  * @brief Clear fault detect interrupt of selected channel.
1627  * @param[in] epwm The pointer of the specified EPWM module.
1628  *                - EPWM0 : EPWM Group 0
1629  *                - EPWM1 : EPWM Group 1
1630  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1631  * @return None
1632  * @details This function is used to clear fault detect interrupt of selected channel.
1633  */
EPWM_ClearFaultDetectInt(EPWM_T * epwm,uint32_t u32ChannelNum)1634 void EPWM_ClearFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1635 {
1636     (epwm)->FDSTS = (EPWM_FDSTS_FDIF0_Msk << (u32ChannelNum));
1637 }
1638 
1639 /**
1640  * @brief Get fault detect interrupt of selected channel.
1641  * @param[in] epwm The pointer of the specified EPWM module.
1642  *                - EPWM0 : EPWM Group 0
1643  *                - EPWM1 : EPWM Group 1
1644  * @param[in] u32ChannelNum EPWM channel number. Valid values are between 0~5.
1645  * @retval 0 Fault detect interrupt did not occur.
1646  * @retval 1 Fault detect interrupt occurred.
1647  * @details This function is used to Get fault detect interrupt of selected channel.
1648  */
EPWM_GetFaultDetectInt(EPWM_T * epwm,uint32_t u32ChannelNum)1649 uint32_t EPWM_GetFaultDetectInt(EPWM_T *epwm, uint32_t u32ChannelNum)
1650 {
1651     return (((epwm)->FDSTS & (EPWM_FDSTS_FDIF0_Msk << (u32ChannelNum))) ? 1UL : 0UL);
1652 }
1653 
1654 /**@}*/ /* end of group EPWM_EXPORTED_FUNCTIONS */
1655 
1656 /**@}*/ /* end of group EPWM_Driver */
1657 
1658 /**@}*/ /* end of group Standard_Driver */
1659