M480 BSP V3.05.006
The Board Support Package for M480 Series
bpwm.h
Go to the documentation of this file.
1/**************************************************************************/
9#ifndef __BPWM_H__
10#define __BPWM_H__
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17
29#define BPWM_CHANNEL_NUM (6)
30#define BPWM_CH_0_MASK (0x1UL)
31#define BPWM_CH_1_MASK (0x2UL)
32#define BPWM_CH_2_MASK (0x4UL)
33#define BPWM_CH_3_MASK (0x8UL)
34#define BPWM_CH_4_MASK (0x10UL)
35#define BPWM_CH_5_MASK (0x20UL)
37/*---------------------------------------------------------------------------------------------------------*/
38/* Counter Type Constant Definitions */
39/*---------------------------------------------------------------------------------------------------------*/
40#define BPWM_UP_COUNTER (0UL)
41#define BPWM_DOWN_COUNTER (1UL)
42#define BPWM_UP_DOWN_COUNTER (2UL)
44/*---------------------------------------------------------------------------------------------------------*/
45/* Aligned Type Constant Definitions */
46/*---------------------------------------------------------------------------------------------------------*/
47#define BPWM_EDGE_ALIGNED (1UL)
48#define BPWM_CENTER_ALIGNED (2UL)
50/*---------------------------------------------------------------------------------------------------------*/
51/* Output Level Constant Definitions */
52/*---------------------------------------------------------------------------------------------------------*/
53#define BPWM_OUTPUT_NOTHING (0UL)
54#define BPWM_OUTPUT_LOW (1UL)
55#define BPWM_OUTPUT_HIGH (2UL)
56#define BPWM_OUTPUT_TOGGLE (3UL)
58/*---------------------------------------------------------------------------------------------------------*/
59/* Synchronous Start Function Control Constant Definitions */
60/*---------------------------------------------------------------------------------------------------------*/
61#define BPWM_SSCTL_SSRC_PWM0 (0UL<<BPWM_SSCTL_SSRC_Pos)
62#define BPWM_SSCTL_SSRC_PWM1 (1UL<<BPWM_SSCTL_SSRC_Pos)
63#define BPWM_SSCTL_SSRC_BPWM0 (2UL<<BPWM_SSCTL_SSRC_Pos)
64#define BPWM_SSCTL_SSRC_BPWM1 (3UL<<BPWM_SSCTL_SSRC_Pos)
66/*---------------------------------------------------------------------------------------------------------*/
67/* Trigger Source Select Constant Definitions */
68/*---------------------------------------------------------------------------------------------------------*/
69#define BPWM_TRIGGER_ADC_EVEN_ZERO_POINT (0UL)
70#define BPWM_TRIGGER_ADC_EVEN_PERIOD_POINT (1UL)
71#define BPWM_TRIGGER_ADC_EVEN_ZERO_OR_PERIOD_POINT (2UL)
72#define BPWM_TRIGGER_ADC_EVEN_CMP_UP_COUNT_POINT (3UL)
73#define BPWM_TRIGGER_ADC_EVEN_CMP_DOWN_COUNT_POINT (4UL)
74#define BPWM_TRIGGER_ADC_ODD_CMP_UP_COUNT_POINT (8UL)
75#define BPWM_TRIGGER_ADC_ODD_CMP_DOWN_COUNT_POINT (9UL)
77/*---------------------------------------------------------------------------------------------------------*/
78/* Capture Control Constant Definitions */
79/*---------------------------------------------------------------------------------------------------------*/
80#define BPWM_CAPTURE_INT_RISING_LATCH (1UL)
81#define BPWM_CAPTURE_INT_FALLING_LATCH (0x100UL)
83/*---------------------------------------------------------------------------------------------------------*/
84/* Duty Interrupt Type Constant Definitions */
85/*---------------------------------------------------------------------------------------------------------*/
86#define BPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP (1 << BPWM_INTEN_CMPDIENn_Pos)
87#define BPWM_DUTY_INT_UP_COUNT_MATCH_CMP (1 << BPWM_INTEN_CMPUIENn_Pos)
89/*---------------------------------------------------------------------------------------------------------*/
90/* Load Mode Constant Definitions */
91/*---------------------------------------------------------------------------------------------------------*/
92#define BPWM_LOAD_MODE_IMMEDIATE (1 << BPWM_CTL0_IMMLDENn_Pos)
93#define BPWM_LOAD_MODE_CENTER (1 << BPWM_CTL0_CTRLDn_Pos)
95/*---------------------------------------------------------------------------------------------------------*/
96/* Clock Source Select Constant Definitions */
97/*---------------------------------------------------------------------------------------------------------*/
98#define BPWM_CLKSRC_BPWM_CLK (0UL)
99#define BPWM_CLKSRC_TIMER0 (1UL)
100#define BPWM_CLKSRC_TIMER1 (2UL)
101#define BPWM_CLKSRC_TIMER2 (3UL)
102#define BPWM_CLKSRC_TIMER3 (4UL) /* end of group BPWM_EXPORTED_CONSTANTS */
105
106
125#define BPWM_ENABLE_TIMER_SYNC(bpwm, u32ChannelMask, u32SyncSrc) ((bpwm)->SSCTL = ((bpwm)->SSCTL & ~BPWM_SSCTL_SSRC_Msk) | (u32SyncSrc) | BPWM_SSCTL_SSEN0_Msk)
126
136#define BPWM_DISABLE_TIMER_SYNC(bpwm, u32ChannelMask) ((bpwm)->SSCTL &= ~BPWM_SSCTL_SSEN0_Msk)
137
146#define BPWM_TRIGGER_SYNC_START(bpwm) ((bpwm)->SSTRG = BPWM_SSTRG_CNTSEN_Msk)
147
156#define BPWM_ENABLE_OUTPUT_INVERTER(bpwm, u32ChannelMask) ((bpwm)->POLCTL = (u32ChannelMask))
157
165#define BPWM_GET_CAPTURE_RISING_DATA(bpwm, u32ChannelNum) ((bpwm)->CAPDAT[(u32ChannelNum)].RCAPDAT)
166
174#define BPWM_GET_CAPTURE_FALLING_DATA(bpwm, u32ChannelNum) ((bpwm)->CAPDAT[(u32ChannelNum)].FCAPDAT)
175
187#define BPWM_MASK_OUTPUT(bpwm, u32ChannelMask, u32LevelMask) \
188 { \
189 (bpwm)->MSKEN = (u32ChannelMask); \
190 (bpwm)->MSK = (u32LevelMask); \
191 }
192
201#define BPWM_SET_PRESCALER(bpwm, u32ChannelNum, u32Prescaler) ((bpwm)->CLKPSC = (u32Prescaler))
202
212#define BPWM_SET_CMR(bpwm, u32ChannelNum, u32CMR) ((bpwm)->CMPDAT[(u32ChannelNum)] = (u32CMR))
213
221#define BPWM_GET_CMR(bpwm, u32ChannelNum) ((bpwm)->CMPDAT[(u32ChannelNum)])
222
233#define BPWM_SET_CNR(bpwm, u32ChannelNum, u32CNR) ((bpwm)->PERIOD = (u32CNR))
234
242#define BPWM_GET_CNR(bpwm, u32ChannelNum) ((bpwm)->PERIOD)
243
255#define BPWM_SET_ALIGNED_TYPE(bpwm, u32ChannelMask, u32AlignedType) ((bpwm)->CTL1 = (u32AlignedType))
256
265#define BPWM_CLR_COUNTER(bpwm, u32ChannelMask) ((bpwm)->CNTCLR = (BPWM_CNTCLR_CNTCLR0_Msk))
266
296#define BPWM_SET_OUTPUT_LEVEL(bpwm, u32ChannelMask, u32ZeroLevel, u32CmpUpLevel, u32PeriodLevel, u32CmpDownLevel) \
297 do{ \
298 int i; \
299 for(i = 0; i < 6; i++) { \
300 if((u32ChannelMask) & (1 << i)) { \
301 (bpwm)->WGCTL0 = (((bpwm)->WGCTL0 & ~(3UL << (2 * i))) | ((u32ZeroLevel) << (2 * i))); \
302 (bpwm)->WGCTL0 = (((bpwm)->WGCTL0 & ~(3UL << (BPWM_WGCTL0_PRDPCTLn_Pos + (2 * i)))) | ((u32PeriodLevel) << (BPWM_WGCTL0_PRDPCTLn_Pos + (2 * i)))); \
303 (bpwm)->WGCTL1 = (((bpwm)->WGCTL1 & ~(3UL << (2 * i))) | ((u32CmpUpLevel) << (2 * i))); \
304 (bpwm)->WGCTL1 = (((bpwm)->WGCTL1 & ~(3UL << (BPWM_WGCTL1_CMPDCTLn_Pos + (2 * i)))) | ((u32CmpDownLevel) << (BPWM_WGCTL1_CMPDCTLn_Pos + (2 * i)))); \
305 } \
306 } \
307 }while(0)
308
309
310/*---------------------------------------------------------------------------------------------------------*/
311/* Define BPWM functions prototype */
312/*---------------------------------------------------------------------------------------------------------*/
313uint32_t BPWM_ConfigCaptureChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge);
314uint32_t BPWM_ConfigOutputChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle);
315void BPWM_Start(BPWM_T *bpwm, uint32_t u32ChannelMask);
316void BPWM_Stop(BPWM_T *bpwm, uint32_t u32ChannelMask);
317void BPWM_ForceStop(BPWM_T *bpwm, uint32_t u32ChannelMask);
318void BPWM_EnableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition);
319void BPWM_DisableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum);
320void BPWM_ClearADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition);
321uint32_t BPWM_GetADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
322void BPWM_EnableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask);
323void BPWM_DisableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask);
324void BPWM_EnableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask);
325void BPWM_DisableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask);
326void BPWM_EnableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge);
327void BPWM_DisableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge);
328void BPWM_ClearCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge);
329uint32_t BPWM_GetCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
330void BPWM_EnableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType);
331void BPWM_DisableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum);
332void BPWM_ClearDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
333uint32_t BPWM_GetDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
334void BPWM_EnablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType);
335void BPWM_DisablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum);
336void BPWM_ClearPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
337uint32_t BPWM_GetPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
338void BPWM_EnableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum);
339void BPWM_DisableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum);
340void BPWM_ClearZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
341uint32_t BPWM_GetZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
342void BPWM_EnableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode);
343void BPWM_DisableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode);
344void BPWM_SetClockSource(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel);
345uint32_t BPWM_GetWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
346void BPWM_ClearWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum);
347
348 /* end of group BPWM_EXPORTED_FUNCTIONS */
350 /* end of group BPWM_Driver */
352 /* end of group Standard_Driver */
354
355#ifdef __cplusplus
356}
357#endif
358
359#endif /* __BPWM_H__ */
360
361/*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
void BPWM_EnableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)
Enable selected channel to trigger ADC.
Definition: bpwm.c:269
void BPWM_ClearCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Clear capture interrupt of selected channel.
Definition: bpwm.c:442
void BPWM_Start(BPWM_T *bpwm, uint32_t u32ChannelMask)
Start BPWM module.
Definition: bpwm.c:217
void BPWM_ClearWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear the time-base counter reached its maximum value flag of selected channel.
Definition: bpwm.c:733
void BPWM_EnableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)
Enable capture of selected channel(s)
Definition: bpwm.c:344
uint32_t BPWM_GetWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get the time-base counter reached its maximum value flag of selected channel.
Definition: bpwm.c:718
void BPWM_ClearDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear duty interrupt flag of selected channel.
Definition: bpwm.c:505
void BPWM_DisablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable period interrupt of selected channel.
Definition: bpwm.c:552
void BPWM_Stop(BPWM_T *bpwm, uint32_t u32ChannelMask)
Stop BPWM module.
Definition: bpwm.c:232
void BPWM_EnableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
Enable load mode of selected channel.
Definition: bpwm.c:663
void BPWM_DisableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Disable capture interrupt of selected channel.
Definition: bpwm.c:425
uint32_t BPWM_GetCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get capture interrupt of selected channel.
Definition: bpwm.c:459
void BPWM_EnablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntPeriodType)
Enable period interrupt of selected channel.
Definition: bpwm.c:537
uint32_t BPWM_ConfigOutputChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)
This function Configure BPWM generator and get the nearest frequency in edge aligned auto-reload mode...
Definition: bpwm.c:130
uint32_t BPWM_GetZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get zero interrupt of selected channel.
Definition: bpwm.c:646
uint32_t BPWM_GetDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get duty interrupt flag of selected channel.
Definition: bpwm.c:521
void BPWM_EnableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)
Enable capture interrupt of selected channel.
Definition: bpwm.c:408
void BPWM_DisableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)
Disable capture of selected channel(s)
Definition: bpwm.c:360
void BPWM_DisableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable duty interrupt of selected channel.
Definition: bpwm.c:490
void BPWM_ClearADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)
Clear selected channel trigger ADC flag.
Definition: bpwm.c:314
void BPWM_DisableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)
Disables BPWM output generation of selected channel(s)
Definition: bpwm.c:391
uint32_t BPWM_ConfigCaptureChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)
Configure BPWM capture and get the nearest unit time.
Definition: bpwm.c:35
void BPWM_EnableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)
Enables BPWM output generation of selected channel(s)
Definition: bpwm.c:376
void BPWM_ClearZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear zero interrupt of selected channel.
Definition: bpwm.c:629
uint32_t BPWM_GetPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get period interrupt of selected channel.
Definition: bpwm.c:584
void BPWM_EnableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)
Enable duty interrupt of selected channel.
Definition: bpwm.c:476
uint32_t BPWM_GetADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Get selected channel trigger ADC flag.
Definition: bpwm.c:329
void BPWM_DisableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)
Disable load mode of selected channel.
Definition: bpwm.c:680
void BPWM_ForceStop(BPWM_T *bpwm, uint32_t u32ChannelMask)
Stop BPWM generation immediately by clear channel enable bit.
Definition: bpwm.c:247
void BPWM_SetClockSource(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)
Set BPWM clock source.
Definition: bpwm.c:701
void BPWM_ClearPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)
Clear period interrupt of selected channel.
Definition: bpwm.c:567
void BPWM_DisableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable zero interrupt of selected channel.
Definition: bpwm.c:614
void BPWM_EnableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)
Enable zero interrupt of selected channel.
Definition: bpwm.c:599
void BPWM_DisableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum)
Disable selected channel to trigger ADC.
Definition: bpwm.c:292