📄 lh7a400_dcdc_driver.c
字号:
/*
* get PMPFREQ register contents, mask-out desired field,
* then shift into LSB position as needed.
*/
switch (power)
{
case EXTERN_POWER: // get PWM1 LOW field
ret = (DCDC->pmpfreq & PWM1_LOW_DATA_MASK)
>> PWM1_LOW_DATA_POSITION; // into LSB
break;
default:
case BATTERY_POWER: // get PWM1 HIGH field
ret = (DCDC->pmpfreq & PWM1_HIGH_DATA_MASK)
>> PWM1_HIGH_DATA_POSITION; // into LSB
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm0_disable
*
* Purpose:
* Disables output on the PWM0 channel of the LH7A400.
*
* Processing:
* - save old PWM1 duty-cycle data
* - set ALL PWM0 duty cycles to ZERO
* - write new Duty-Cycle Register data
*
* Parameters: None.
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
* This is a "destructive" function in that it sets the
* duty-cycle to ZERO for both the LOW and HIGH register fields.
* This function disables the entire PWM0 channel.
* To just turn off one part of the channel,
* use pwm0_set_dutycycle() to set one POWER_TYPE field to ZERO.
*
* This function is "destructive":
* ALL previous PWM0 duty-cycle values are lost
* ( All PWM1 values and PWM0-prescaler values are saved )
*
**********************************************************************/
void LH7A400_pwm0_disable(void)
{
UNS_32 old_pmpcon1_data;
/* save previous register contents .. clear out PWM0 data */
old_pmpcon1_data = DCDC->pmpcon & ~PWM0_ALL_DATA_MASK;
/* set disabling ZERO to PWM0 HIGH & LOW fields */
DCDC->pmpcon = old_pmpcon1_data |
PMPCON_DRV0_DTYHI(0) |
PMPCON_DRV0_DTYLO(0);
}
/***********************************************************************
*
* Function: LH7A400_pwm1_disable
*
* Purpose:
* Disables output on the PWM1 channel of the LH7A400.
*
* Processing:
* - save old PWM0 duty-cycle data
* - set ALL PWM1 duty cycles to ZERO
* - write new Duty-Cycle Register data
*
* Parameters: None.
*
* Outputs: None
*
* Returns: Nothing
*
* Notes:
* This is a "destructive" function in that it sets the
* duty-cycle to ZERO for both the LOW and HIGH register fields.
* This function disables the entire PWM1 channel.
* To just turn off one part of the channel,
* use pwm1_set_dutycycle() to set one POWER_TYPE field to ZERO.
*
* This function is "destructive":
* ALL previous PWM1 duty-cycle values are lost
* ( All PWM0 values and PWM1-prescaler values are saved )
*
**********************************************************************/
void LH7A400_pwm1_disable(void)
{
UNS_32 old_pmpcon0_data;
/* save previous register contents .. clear out PWM1 data */
old_pmpcon0_data = DCDC->pmpcon & ~PWM1_ALL_DATA_MASK;
/* set disabling ZERO to PWM0 HIGH & LOW fields */
DCDC->pmpcon = old_pmpcon0_data |
PMPCON_DRV1_DTYHI(0) |
PMPCON_DRV1_DTYLO(0);
}
/***********************************************************************
*
* Function: LH7A400_pwm0_increase_duty_cycle
*
* Purpose:
* increase PWM0 duty cycle by ONE for selected power-type
*
* Processing:
* - read current PWM0 Duty-Cycles
* - increase selected power-type field by 1
* - write back out
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access:
* EXTERN_POWER or BATTERY_POWER or ALL_POWER_TYPES
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER | ALL_POWER_TYPES
*
*
* Outputs: None
*
* Returns: None
* success: _NO_ERROR
* failure: _ERROR (checks if already at MAX)
*
* Notes:
* For power == ALL_POWER_TYPES, _ERROR return does not specify
* which one power-ype or both were already at MAX.
*
*
**********************************************************************/
INT_8 LH7A400_pwm0_increase_duty_cycle (UNS_8 power)
{
INT_8 ret;
ret = _NO_ERROR;
switch (power)
{
case EXTERN_POWER: // inc. PWM0 LOW field
if ((DCDC->pmpcon & PWM0_LOW_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM0_LOW_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM0_LOW_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
break;
case BATTERY_POWER: // inc. PWM0 HIGH field
if ((DCDC->pmpcon & PWM0_HIGH_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM0_HIGH_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM0_HIGH_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
break;
case ALL_POWER_TYPES: // inc. PWM0 LOW & HIGH fields
if ((DCDC->pmpcon & PWM0_LOW_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM0_LOW_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM0_LOW_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
if ((DCDC->pmpcon & PWM0_HIGH_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM0_HIGH_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM0_HIGH_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
break;
default:
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm0_decrease_duty_cycle
*
* Purpose:
* decrease PWM0 duty cycle by ONE for selected power-type
*
* Processing:
* - read current PWM0 Duty-Cycles
* - decrease selected power-type field by 1
* - write back out
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access:
* EXTERN_POWER or BATTERY_POWER or ALL_POWER_TYPES
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER | ALL_POWER_TYPES
*
*
* Outputs: None
*
* Returns: None
* success: _NO_ERROR
* failure: _ERROR (checks if already at MAX)
*
* Notes:
* For power == ALL_POWER_TYPES, _ERROR return does not specify
* which one power-ype or both were already at MAX.
*
*
**********************************************************************/
INT_8 LH7A400_pwm0_decrease_duty_cycle (UNS_8 power)
{
INT_8 ret;
ret = _NO_ERROR;
switch (power)
{
case EXTERN_POWER: // dec. PWM0 LOW field
if ((DCDC->pmpcon & PWM0_LOW_DATA_MASK) >
(MIN_DUTYCYCLE_VALUE << PWM0_LOW_DATA_POSITION)
) // dec. if current field value greater-than MIN allowed
{
DCDC->pmpcon -= PWM0_LOW_DATA_SELECT;
}
else
{ // if not, can't decrement.
ret = _ERROR;
}
break;
case BATTERY_POWER: // dec. PWM0 HIGH field
if ((DCDC->pmpcon & PWM0_HIGH_DATA_MASK) >
(MIN_DUTYCYCLE_VALUE << PWM0_HIGH_DATA_POSITION)
) // dec. if current field value greater-than MIN allowed
{
DCDC->pmpcon -= PWM0_HIGH_DATA_SELECT;
}
else
{ // if not, can't decrement.
ret = _ERROR;
}
break;
case ALL_POWER_TYPES: // dec. PWM0 LOW & HIGH fields
if ((DCDC->pmpcon & PWM0_LOW_DATA_MASK) >
(MIN_DUTYCYCLE_VALUE << PWM0_LOW_DATA_POSITION)
) // dec. if current field value greater-than MIN allowed
{
DCDC->pmpcon -= PWM0_LOW_DATA_SELECT;
}
else
{ // if not, can't decrement.
ret = _ERROR;
}
if ((DCDC->pmpcon & PWM0_HIGH_DATA_MASK) >
(MIN_DUTYCYCLE_VALUE << PWM0_HIGH_DATA_POSITION)
) // dec. if current field value greater-than MIN allowed
{
DCDC->pmpcon -= PWM0_HIGH_DATA_SELECT;
}
else
{ // if not, can't decrement.
ret = _ERROR;
}
break;
default:
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm1_increase_duty_cycle
*
* Purpose:
* increase PWM1 duty cycle by ONE for selected power-type
*
* Processing:
* - read current PWM1 Duty-Cycles
* - increase selected power-type field by 1
* - write back out
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access:
* EXTERN_POWER or BATTERY_POWER or ALL_POWER_TYPES
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER | ALL_POWER_TYPES
*
*
* Outputs: None
*
* Returns: None
* success: _NO_ERROR
* failure: _ERROR (checks if already at MAX)
*
* Notes:
* For power == ALL_POWER_TYPES, _ERROR return does not specify
* which one power-ype or both were already at MAX.
*
*
**********************************************************************/
INT_8 LH7A400_pwm1_increase_duty_cycle (UNS_8 power)
{
INT_8 ret;
ret = _NO_ERROR;
switch (power)
{
case EXTERN_POWER: // inc. PWM1 LOW field
if ((DCDC->pmpcon & PWM1_LOW_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM1_LOW_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM1_LOW_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
break;
case BATTERY_POWER: // inc. PWM1 HIGH field
if ((DCDC->pmpcon & PWM1_HIGH_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM1_HIGH_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM1_HIGH_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
break;
case ALL_POWER_TYPES: // inc. PWM1 LOW & HIGH fields
if ((DCDC->pmpcon & PWM1_LOW_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM1_LOW_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM1_LOW_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
if ((DCDC->pmpcon & PWM1_HIGH_DATA_MASK) <
(MAX_DUTYCYCLE_VALUE << PWM1_HIGH_DATA_POSITION)
) // inc. if current field value less-than MAX allowed
{
DCDC->pmpcon += PWM1_HIGH_DATA_SELECT;
}
else
{ // if not, can't increment.
ret = _ERROR;
}
break;
default:
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm1_decrease_duty_cycle
*
* Purpose:
* decrease PWM1 duty cycle by ONE for selected power-type
*
* Processing:
* - read current PWM1 Duty-Cycles
* - decrease selected power-type field by 1
* - write back out
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access:
* EXTERN_POWER or BATTERY_POWER or ALL_POWER_TYPES
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER | ALL_POWER_TYPES
*
*
* Outputs: None
*
* Returns: None
* success: _NO_ERROR
* failure: _ERROR (checks if already at MAX)
*
* Notes:
* For power == ALL_POWER_TYPES, _ERROR return does not specify
* which one power-ype or both were already at MAX.
*
*
**********************************************************************/
INT_8 LH7A400_pwm1_decrease_duty_cycle (UNS_8 power)
{
INT_8 ret;
ret = _NO_ERROR;
switch (power)
{
case EXTERN_POWER: // dec. PWM1 LOW field
if ((DCDC->pmpcon & PWM1_LOW_DATA_MASK) >
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -