Update bl702_pwm.c

This commit is contained in:
Ben V. Brown
2022-06-23 23:53:19 +10:00
parent f7078da587
commit ec25561d4c

View File

@@ -90,14 +90,14 @@ static BL_Err_Type PWM_IntHandler(IRQn_Type intPeriph);
* @{ * @{
*/ */
/****************************************************************************/ /** /****************************************************************************
* @brief PWM interrupt handle * @brief PWM interrupt handle
* *
* @param intPeriph: Select the peripheral, such as PWM0_IRQn * @param intPeriph: Select the peripheral, such as PWM0_IRQn
* *
* @return SUCCESS * @return SUCCESS
* *
*******************************************************************************/ *******************************************************************************/
#ifndef BFLB_USE_HAL_DRIVER #ifndef BFLB_USE_HAL_DRIVER
static BL_Err_Type PWM_IntHandler(IRQn_Type intPeriph) { static BL_Err_Type PWM_IntHandler(IRQn_Type intPeriph) {
uint32_t i; uint32_t i;
@@ -145,14 +145,14 @@ static BL_Err_Type PWM_IntHandler(IRQn_Type intPeriph) {
* @{ * @{
*/ */
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel init * @brief PWM channel init
* *
* @param chCfg: PWM configuration * @param chCfg: PWM configuration
* *
* @return SUCCESS * @return SUCCESS
* *
*******************************************************************************/ *******************************************************************************/
BL_Err_Type PWM_Channel_Init(PWM_CH_CFG_Type *chCfg) { BL_Err_Type PWM_Channel_Init(PWM_CH_CFG_Type *chCfg) {
uint32_t tmpVal; uint32_t tmpVal;
uint32_t timeoutCnt = PWM_STOP_TIMEOUT_COUNT; uint32_t timeoutCnt = PWM_STOP_TIMEOUT_COUNT;
@@ -200,24 +200,20 @@ BL_Err_Type PWM_Channel_Init(PWM_CH_CFG_Type *chCfg) {
// PWM_IntMask(chCfg->ch, PWM_INT_PULSE_CNT, chCfg->intPulseCnt != 0 ? UNMASK : MASK); // PWM_IntMask(chCfg->ch, PWM_INT_PULSE_CNT, chCfg->intPulseCnt != 0 ? UNMASK : MASK);
CPU_Interrupt_Disable(PWM_IRQn); CPU_Interrupt_Disable(PWM_IRQn);
// #ifndef BFLB_USE_HAL_DRIVER
// Interrupt_Handler_Register(PWM_IRQn, PWM_IRQHandler);
// #endif
return SUCCESS; return SUCCESS;
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel update source memory address and len * @brief PWM channel update source memory address and len
* *
* @param ch: PWM channel * @param ch: PWM channel
* @param period: period * @param period: period
* @param threshold1: threshold1 * @param threshold1: threshold1
* @param threshold2: threshold2 * @param threshold2: threshold2
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Update(PWM_CH_ID_Type ch, uint16_t period, uint16_t threshold1, uint16_t threshold2) { void PWM_Channel_Update(PWM_CH_ID_Type ch, uint16_t period, uint16_t threshold1, uint16_t threshold2) {
/* Get channel register */ /* Get channel register */
uint32_t PWMx = PWM_Get_Channel_Reg(ch); uint32_t PWMx = PWM_Get_Channel_Reg(ch);
@@ -231,15 +227,15 @@ void PWM_Channel_Update(PWM_CH_ID_Type ch, uint16_t period, uint16_t threshold1,
BL_WR_REG(PWMx, PWM_PERIOD, period); BL_WR_REG(PWMx, PWM_PERIOD, period);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel update clock divider * @brief PWM channel update clock divider
* *
* @param ch: PWM channel * @param ch: PWM channel
* @param div: Clock divider * @param div: Clock divider
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Set_Div(PWM_CH_ID_Type ch, uint16_t div) { void PWM_Channel_Set_Div(PWM_CH_ID_Type ch, uint16_t div) {
/* Get channel register */ /* Get channel register */
uint32_t PWMx = PWM_Get_Channel_Reg(ch); uint32_t PWMx = PWM_Get_Channel_Reg(ch);
@@ -250,15 +246,15 @@ void PWM_Channel_Set_Div(PWM_CH_ID_Type ch, uint16_t div) {
BL_WR_REG(PWMx, PWM_CLKDIV, div); BL_WR_REG(PWMx, PWM_CLKDIV, div);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel update threshold1 * @brief PWM channel update threshold1
* *
* @param ch: PWM channel * @param ch: PWM channel
* @param threshold1: threshold1 * @param threshold1: threshold1
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Set_Threshold1(PWM_CH_ID_Type ch, uint16_t threshold1) { void PWM_Channel_Set_Threshold1(PWM_CH_ID_Type ch, uint16_t threshold1) {
/* Get channel register */ /* Get channel register */
uint32_t PWMx = PWM_Get_Channel_Reg(ch); uint32_t PWMx = PWM_Get_Channel_Reg(ch);
@@ -270,15 +266,15 @@ void PWM_Channel_Set_Threshold1(PWM_CH_ID_Type ch, uint16_t threshold1) {
BL_WR_REG(PWMx, PWM_THRE1, threshold1); BL_WR_REG(PWMx, PWM_THRE1, threshold1);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel update threshold2 * @brief PWM channel update threshold2
* *
* @param ch: PWM channel * @param ch: PWM channel
* @param threshold2: threshold2 * @param threshold2: threshold2
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Set_Threshold2(PWM_CH_ID_Type ch, uint16_t threshold2) { void PWM_Channel_Set_Threshold2(PWM_CH_ID_Type ch, uint16_t threshold2) {
/* Get channel register */ /* Get channel register */
uint32_t PWMx = PWM_Get_Channel_Reg(ch); uint32_t PWMx = PWM_Get_Channel_Reg(ch);
@@ -290,15 +286,15 @@ void PWM_Channel_Set_Threshold2(PWM_CH_ID_Type ch, uint16_t threshold2) {
BL_WR_REG(PWMx, PWM_THRE2, threshold2); BL_WR_REG(PWMx, PWM_THRE2, threshold2);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel update period * @brief PWM channel update period
* *
* @param ch: PWM channel * @param ch: PWM channel
* @param period: period * @param period: period
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Set_Period(PWM_CH_ID_Type ch, uint16_t period) { void PWM_Channel_Set_Period(PWM_CH_ID_Type ch, uint16_t period) {
/* Get channel register */ /* Get channel register */
uint32_t PWMx = PWM_Get_Channel_Reg(ch); uint32_t PWMx = PWM_Get_Channel_Reg(ch);
@@ -310,17 +306,17 @@ void PWM_Channel_Set_Period(PWM_CH_ID_Type ch, uint16_t period) {
BL_WR_REG(PWMx, PWM_PERIOD, period); BL_WR_REG(PWMx, PWM_PERIOD, period);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM get configuration * @brief PWM get configuration
* *
* @param ch: PWM channel * @param ch: PWM channel
* @param period: period pointer * @param period: period pointer
* @param threshold1: threshold1 pointer * @param threshold1: threshold1 pointer
* @param threshold2: threshold2 pointer * @param threshold2: threshold2 pointer
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Get(PWM_CH_ID_Type ch, uint16_t *period, uint16_t *threshold1, uint16_t *threshold2) { void PWM_Channel_Get(PWM_CH_ID_Type ch, uint16_t *period, uint16_t *threshold1, uint16_t *threshold2) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -338,14 +334,14 @@ void PWM_Channel_Get(PWM_CH_ID_Type ch, uint16_t *period, uint16_t *threshold1,
*period = BL_GET_REG_BITS_VAL(tmpVal, PWM_PERIOD); *period = BL_GET_REG_BITS_VAL(tmpVal, PWM_PERIOD);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM enable * @brief PWM enable
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Enable(PWM_CH_ID_Type ch) { void PWM_Channel_Enable(PWM_CH_ID_Type ch) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -359,14 +355,14 @@ void PWM_Channel_Enable(PWM_CH_ID_Type ch) {
BL_WR_REG(PWMx, PWM_CONFIG, BL_CLR_REG_BIT(tmpVal, PWM_STOP_EN)); BL_WR_REG(PWMx, PWM_CONFIG, BL_CLR_REG_BIT(tmpVal, PWM_STOP_EN));
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM disable * @brief PWM disable
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Disable(PWM_CH_ID_Type ch) { void PWM_Channel_Disable(PWM_CH_ID_Type ch) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -381,15 +377,15 @@ void PWM_Channel_Disable(PWM_CH_ID_Type ch) {
PWM_IntMask(ch, PWM_INT_PULSE_CNT, MASK); PWM_IntMask(ch, PWM_INT_PULSE_CNT, MASK);
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel software mode enable or disable * @brief PWM channel software mode enable or disable
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* @param enable: Enable or disable * @param enable: Enable or disable
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_SW_Mode(PWM_CH_ID_Type ch, BL_Fun_Type enable) { void PWM_SW_Mode(PWM_CH_ID_Type ch, BL_Fun_Type enable) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -402,15 +398,15 @@ void PWM_SW_Mode(PWM_CH_ID_Type ch, BL_Fun_Type enable) {
BL_WR_REG(PWMx, PWM_CONFIG, BL_SET_REG_BITS_VAL(tmpVal, PWM_SW_MODE, enable)); BL_WR_REG(PWMx, PWM_CONFIG, BL_SET_REG_BITS_VAL(tmpVal, PWM_SW_MODE, enable));
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel force output high or low * @brief PWM channel force output high or low
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* @param value: Output value * @param value: Output value
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_SW_Force_Value(PWM_CH_ID_Type ch, uint8_t value) { void PWM_SW_Force_Value(PWM_CH_ID_Type ch, uint8_t value) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -423,14 +419,14 @@ void PWM_SW_Force_Value(PWM_CH_ID_Type ch, uint8_t value) {
BL_WR_REG(PWMx, PWM_CONFIG, BL_SET_REG_BITS_VAL(tmpVal, PWM_SW_FORCE_VAL, value)); BL_WR_REG(PWMx, PWM_CONFIG, BL_SET_REG_BITS_VAL(tmpVal, PWM_SW_FORCE_VAL, value));
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM channel force output high * @brief PWM channel force output high
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Channel_Fource_Output(PWM_CH_ID_Type ch) { void PWM_Channel_Fource_Output(PWM_CH_ID_Type ch) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -443,16 +439,16 @@ void PWM_Channel_Fource_Output(PWM_CH_ID_Type ch) {
BL_WR_REG(PWMx, PWM_CONFIG, BL_SET_REG_BIT(tmpVal, PWM_SW_MODE)); BL_WR_REG(PWMx, PWM_CONFIG, BL_SET_REG_BIT(tmpVal, PWM_SW_MODE));
} }
/****************************************************************************/ /** /****************************************************************************
* @brief Mask/Unmask the PWM interrupt * @brief Mask/Unmask the PWM interrupt
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* @param intType: Specifies the interrupt type * @param intType: Specifies the interrupt type
* @param intMask: Enable/Disable Specified interrupt type * @param intMask: Enable/Disable Specified interrupt type
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_IntMask(PWM_CH_ID_Type ch, PWM_INT_Type intType, BL_Mask_Type intMask) { void PWM_IntMask(PWM_CH_ID_Type ch, PWM_INT_Type intType, BL_Mask_Type intMask) {
uint32_t tmpVal; uint32_t tmpVal;
/* Get channel register */ /* Get channel register */
@@ -492,28 +488,28 @@ void PWM_IntMask(PWM_CH_ID_Type ch, PWM_INT_Type intType, BL_Mask_Type intMask)
} }
} }
/****************************************************************************/ /** /****************************************************************************
* @brief Install PWM interrupt callback function * @brief Install PWM interrupt callback function
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* @param intType: PWM interrupt type * @param intType: PWM interrupt type
* @param cbFun: Pointer to interrupt callback function. The type should be void (*fn)(void) * @param cbFun: Pointer to interrupt callback function. The type should be void (*fn)(void)
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
void PWM_Int_Callback_Install(PWM_CH_ID_Type ch, uint32_t intType, intCallback_Type *cbFun) { PWMIntCbfArra[ch][intType] = cbFun; } void PWM_Int_Callback_Install(PWM_CH_ID_Type ch, uint32_t intType, intCallback_Type *cbFun) { PWMIntCbfArra[ch][intType] = cbFun; }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM smart configure according to frequency and duty cycle function * @brief PWM smart configure according to frequency and duty cycle function
* *
* @param ch: PWM channel number * @param ch: PWM channel number
* @param frequency: PWM frequency * @param frequency: PWM frequency
* @param dutyCycle: PWM duty cycle * @param dutyCycle: PWM duty cycle
* *
* @return SUCCESS or TIMEOUT * @return SUCCESS or TIMEOUT
* *
*******************************************************************************/ *******************************************************************************/
BL_Err_Type PWM_Smart_Configure(PWM_CH_ID_Type ch, uint32_t frequency, uint8_t dutyCycle) { BL_Err_Type PWM_Smart_Configure(PWM_CH_ID_Type ch, uint32_t frequency, uint8_t dutyCycle) {
uint32_t tmpVal; uint32_t tmpVal;
uint16_t clkDiv, period, threshold2; uint16_t clkDiv, period, threshold2;
@@ -573,14 +569,14 @@ BL_Err_Type PWM_Smart_Configure(PWM_CH_ID_Type ch, uint32_t frequency, uint8_t d
return SUCCESS; return SUCCESS;
} }
/****************************************************************************/ /** /****************************************************************************
* @brief PWM interrupt function * @brief PWM interrupt function
* *
* @param None * @param None
* *
* @return None * @return None
* *
*******************************************************************************/ *******************************************************************************/
#ifndef BFLB_USE_HAL_DRIVER #ifndef BFLB_USE_HAL_DRIVER
void PWM_IRQHandler(void) { PWM_IntHandler(PWM_IRQn); } void PWM_IRQHandler(void) { PWM_IntHandler(PWM_IRQn); }
#endif #endif