📄 lh7a400_dcdc_driver.c
字号:
PMPCON_DRV1_DTYLO(dutycycle) |
PMPCON_DRV1_DTYHI(dutycycle) ;
break;
default:
break;
}
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm0_set_clock_prescaler
*
* Purpose:
* Sets the PWM0 clock prescaler to the value specified
*
* Processing:
* - save appropriate old PWM clock-prescaler data
* - set "power" field to "prescaler" for PWM0 DCDCFREQ Register
* - write new Clock-Prescaler Register data
*
* Parameters:
* prescaler - PWM0 clock-prescaler value. (0-7)
*
* 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 prescale - 0-7: clock / (16 * (2^n)) {clock-prescaler}
* UNS_8 power - EXTERN_POWER | BATTERY_POWER | ALL_POWER_TYPES
*
*
* Outputs: None
*
* Returns:
* success: _NO_ERROR
* failure: _ERROR (currently just a parameter-check failure)
*
* Notes:
*
* ALL PWM data is preserved, except for parameter data field(s)
* overwritten by parameter value.
*
**********************************************************************/
INT_8 LH7A400_pwm0_set_clock_prescaler (UNS_8 prescaler, UNS_8 power)
{
INT_8 ret;
UNS_32 old_pmpfreq1_data;
ret = _NO_ERROR;
/* bounds check parameters */
if (prescaler > 7)
ret = _ERROR;
if (power > NUMBER_OF_POWER_TYPES)
ret = _ERROR;
/*
* if parameters are VALID,
* set appropriate register fields based on Power-Type
*/
if (ret == _NO_ERROR)
{
/*
* save appropriate previous register contents,
* then set desired field accordingly
*/
switch (power)
{
case EXTERN_POWER: // set PWM0 LOW field
old_pmpfreq1_data = DCDC->pmpfreq &
~PWM0_LOW_DATA_MASK;
DCDC->pmpfreq = old_pmpfreq1_data |
PMPFREQ_DRV0_PRELO(prescaler);
break;
case BATTERY_POWER: // set PWM0 HIGH field
old_pmpfreq1_data = DCDC->pmpfreq &
~PWM0_HIGH_DATA_MASK;
DCDC->pmpfreq = old_pmpfreq1_data |
PMPFREQ_DRV0_PREHI(prescaler);
break;
case ALL_POWER_TYPES: // set PWM0 LOW & HIGH fields
old_pmpfreq1_data = DCDC->pmpfreq &
~PWM0_ALL_DATA_MASK;
DCDC->pmpfreq = old_pmpfreq1_data |
PMPFREQ_DRV0_PRELO(prescaler) |
PMPFREQ_DRV0_PREHI(prescaler) ;
break;
default:
break;
}
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm1_set_clock_prescaler
*
* Purpose:
* Sets the PWM1 clock prescaler to the value specified
*
* Processing:
* - save appropriate old PWM clock-prescaler data
* - set "power" field to "prescaler" for PWM1 DCDCFREQ Register
* - write new Clock-Prescaler Register data
*
* Parameters:
* prescaler - PWM1 clock-prescaler value. (0-7)
*
* 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 prescale - 0-7: clock / (16 * (2^n)) {clock-prescaler}
* UNS_8 power - EXTERN_POWER | BATTERY_POWER | ALL_POWER_TYPES
*
*
* Outputs: None
*
* Returns:
* success: _NO_ERROR
* failure: _ERROR (currently just a parameter-check failure)
*
* Notes:
*
* ALL PWM data is preserved, except for parameter data field(s)
* overwritten by parameter value.
*
**********************************************************************/
INT_8 LH7A400_pwm1_set_clock_prescaler (UNS_8 prescaler, UNS_8 power)
{
INT_8 ret;
UNS_32 old_pmpfreq0_data;
ret = _NO_ERROR;
/* bounds check parameters */
if (prescaler > 7)
ret = _ERROR;
if (power > NUMBER_OF_POWER_TYPES)
ret = _ERROR;
/*
* if parameters are VALID,
* set appropriate register fields based on Power-Type
*/
if (ret == _NO_ERROR)
{
/*
* save appropriate previous register contents,
* then set desired field accordingly
*/
switch (power)
{
case EXTERN_POWER: // set PWM1 LOW field
old_pmpfreq0_data = DCDC->pmpfreq &
~PWM1_LOW_DATA_MASK;
DCDC->pmpfreq = old_pmpfreq0_data |
PMPFREQ_DRV1_PRELO(prescaler);
break;
case BATTERY_POWER: // set PWM1 HIGH field
old_pmpfreq0_data = DCDC->pmpfreq &
~PWM1_HIGH_DATA_MASK;
DCDC->pmpfreq = old_pmpfreq0_data |
PMPFREQ_DRV1_PREHI(prescaler);
break;
case ALL_POWER_TYPES: // set PWM1 LOW & HIGH fields
old_pmpfreq0_data = DCDC->pmpfreq &
~PWM1_ALL_DATA_MASK;
DCDC->pmpfreq = old_pmpfreq0_data |
PMPFREQ_DRV1_PRELO(prescaler) |
PMPFREQ_DRV1_PREHI(prescaler) ;
break;
default:
break;
}
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm0_get_duty_cycle_value
*
* Purpose:
* Gets the current PWM0 duty cycle setting for the specified
* power-type field.
*
* Processing:
* - read the appropriate PWM0 duty-cycle data
* - mask it and shift it over to the LSB (4-bits)
* - return it
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access: EXTERN_POWER or BATTERY_POWER
* "ALL_POWER_TYPES" is NOT an accepted value here.
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER
*
*
* Outputs: None
*
* Returns:
* - the PWM0 duty-cycle value for
* the specified power-type field
*
* Notes:
*
* parameter: any bad 'power' passed in
* 1) == ALL_POWER_TYPES
* 2) > NUMBER_OF_POWER_TYPES
* will be treated as BATTERY_POWER.
*
*
**********************************************************************/
INT_8 LH7A400_pwm0_get_duty_cycle_value (UNS_8 power)
{
UNS_8 ret;
/* bounds check parameters */
if ((power > NUMBER_OF_POWER_TYPES) || (power == ALL_POWER_TYPES))
power = BATTERY_POWER;
/*
* get PMPCON register contents, mask-out desired field,
* then shift into LSB position as needed.
*/
switch (power)
{
case EXTERN_POWER: // get PWM0 LOW field
ret = (DCDC->pmpcon & PWM0_LOW_DATA_MASK)
>> PWM0_LOW_DATA_POSITION; // into LSB
break;
default:
case BATTERY_POWER: // get PWM0 HIGH field
ret = (DCDC->pmpcon & PWM0_HIGH_DATA_MASK)
>> PWM0_HIGH_DATA_POSITION; // into LSB
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm1_get_duty_cycle_value
*
* Purpose:
* Gets the current PWM1 duty cycle setting for the specified
* power-type field.
*
* Processing:
* - read the appropriate PWM1 duty-cycle data
* - mask it and shift it over to the LSB (4-bits)
* - return it
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access: EXTERN_POWER or BATTERY_POWER
* "ALL_POWER_TYPES" is NOT an accepted value here.
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER
*
*
* Outputs: None
*
* Returns:
* - the PWM1 duty-cycle value for
* the specified power-type field
*
* Notes:
*
* parameter: any bad 'power' passed in
* 1) == ALL_POWER_TYPES
* 2) > NUMBER_OF_POWER_TYPES
* will be treated as BATTERY_POWER.
*
*
**********************************************************************/
INT_8 LH7A400_pwm1_get_duty_cycle_value (UNS_8 power)
{
UNS_8 ret;
/* bounds check parameters */
if ((power > NUMBER_OF_POWER_TYPES) || (power == ALL_POWER_TYPES))
power = BATTERY_POWER;
/*
* get PMPCON register contents, mask-out desired field,
* then shift into LSB position as needed.
*/
switch (power)
{
case EXTERN_POWER: // get PWM1 LOW field
ret = (DCDC->pmpcon & PWM1_LOW_DATA_MASK)
>> PWM1_LOW_DATA_POSITION; // into LSB
break;
default:
case BATTERY_POWER: // get PWM1 HIGH field
ret = (DCDC->pmpcon & PWM1_HIGH_DATA_MASK)
>> PWM1_HIGH_DATA_POSITION; // into LSB
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm0_get_clock_prescaler_value
*
* Purpose:
* Gets the current PWM0 clock prescaler setting for the specified
* power-type field.
*
* Processing:
* - read the appropriate PWM0 clock-prescaler data
* - mask it and shift it over to the LSB (4-bits)
* - return it
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access: EXTERN_POWER or BATTERY_POWER
* "ALL_POWER_TYPES" is NOT an accepted value here.
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER
*
*
* Outputs: None
*
* Returns:
* - the PWM0 clock-prescaler value for
* the specified power-type field
*
* Notes:
*
* parameter: any bad 'power' passed in
* 1) == ALL_POWER_TYPES
* 2) > NUMBER_OF_POWER_TYPES
* will be treated as BATTERY_POWER.
*
*
**********************************************************************/
INT_8 LH7A400_pwm0_get_clock_prescaler_value (UNS_8 power)
{
UNS_8 ret;
/* bounds check parameters */
if ((power > NUMBER_OF_POWER_TYPES) || (power == ALL_POWER_TYPES))
power = BATTERY_POWER;
/*
* get PMPFREQ register contents, mask-out desired field,
* then shift into LSB position as needed.
*/
switch (power)
{
case EXTERN_POWER: // get PWM0 LOW field
ret = (DCDC->pmpfreq & PWM0_LOW_DATA_MASK)
>> PWM0_LOW_DATA_POSITION; // into LSB
break;
default:
case BATTERY_POWER: // get PWM0 HIGH field
ret = (DCDC->pmpfreq & PWM0_HIGH_DATA_MASK)
>> PWM0_HIGH_DATA_POSITION; // into LSB
break;
}
return ret;
}
/***********************************************************************
*
* Function: LH7A400_pwm1_get_clock_prescaler_value
*
* Purpose:
* Gets the current PWM1 clock prescaler setting for the specified
* power-type field.
*
* Processing:
* - read the appropriate PWM1 clock-prescaler data
* - mask it and shift it over to the LSB (4-bits)
* - return it
*
* Parameters:
* power - Type of power connected to the LH7A400.
* This actually designates which register fields
* to access: EXTERN_POWER or BATTERY_POWER
* "ALL_POWER_TYPES" is NOT an accepted value here.
* {LH7A400_dcdc_driver.h}
*
* Values:
* UNS_8 power - EXTERN_POWER | BATTERY_POWER
*
*
* Outputs: None
*
* Returns:
* - the PWM1 clock-prescaler value for
* the specified power-type field
*
* Notes:
*
* parameter: any bad 'power' passed in
* 1) == ALL_POWER_TYPES
* 2) > NUMBER_OF_POWER_TYPES
* will be treated as BATTERY_POWER.
*
*
**********************************************************************/
INT_8 LH7A400_pwm1_get_clock_prescaler_value (UNS_8 power)
{
UNS_8 ret;
/* bounds check parameters */
if ((power > NUMBER_OF_POWER_TYPES) || (power == ALL_POWER_TYPES))
power = BATTERY_POWER;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -