⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lh7a400_dcdc_driver.c

📁 sharp flash blob 的烧写代码
💻 C
📖 第 1 页 / 共 4 页
字号:
                (MIN_DUTYCYCLE_VALUE << PWM1_LOW_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpcon -=  PWM1_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        case BATTERY_POWER:    // dec. PWM1 HIGH field
            if ((DCDC->pmpcon & PWM1_HIGH_DATA_MASK) >
                (MIN_DUTYCYCLE_VALUE << PWM1_HIGH_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpcon -=  PWM1_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        case ALL_POWER_TYPES:  // dec. PWM1 LOW & HIGH fields
            if ((DCDC->pmpcon & PWM1_LOW_DATA_MASK) >
                (MIN_DUTYCYCLE_VALUE << PWM1_LOW_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpcon -=  PWM1_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            if ((DCDC->pmpcon & PWM1_HIGH_DATA_MASK) >
                (MIN_DUTYCYCLE_VALUE << PWM1_HIGH_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpcon -=  PWM1_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        default:
            break;
    }

    return ret;
}


/***********************************************************************
 *
 * Function:  LH7A400_pwm0_increase_clock_prescaler
 *
 * Purpose:
 *     increase PWM0 clock prescaler by ONE for selected power-type
 *
 * Processing:
 *   - read current PWM0 Clock-Prescalers
 *   - 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_clock_prescaler (UNS_8 power)
{
    INT_8   ret;

    ret = _NO_ERROR;

    switch (power)
    {
        case EXTERN_POWER:     // inc. PWM0 LOW field
            if ((DCDC->pmpfreq & PWM0_LOW_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM0_LOW_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM0_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            break;

        case BATTERY_POWER:    // inc. PWM0 HIGH field
            if ((DCDC->pmpfreq & PWM0_HIGH_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM0_HIGH_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM0_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            break;

        case ALL_POWER_TYPES:  // inc. PWM0 LOW & HIGH fields
            if ((DCDC->pmpfreq & PWM0_LOW_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM0_LOW_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM0_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            if ((DCDC->pmpfreq & PWM0_HIGH_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM0_HIGH_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM0_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            break;

        default:
            break;
    }

    return ret;
}


/***********************************************************************
 *
 * Function:  LH7A400_pwm0_decrease_clock_prescaler
 *
 * Purpose:
 *     decrease PWM0 clock prescaler by ONE for selected power-type
 *
 * Processing:
 *   - read current PWM0 Clock-Prescalers
 *   - 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_clock_prescaler (UNS_8 power)
{
    INT_8   ret;

    ret = _NO_ERROR;

    switch (power)
    {
        case EXTERN_POWER:     // dec. PWM0 LOW field
            if ((DCDC->pmpfreq & PWM0_LOW_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM0_LOW_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM0_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        case BATTERY_POWER:    // dec. PWM0 HIGH field
            if ((DCDC->pmpfreq & PWM0_HIGH_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM0_HIGH_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM0_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        case ALL_POWER_TYPES:  // dec. PWM0 LOW & HIGH fields
            if ((DCDC->pmpfreq & PWM0_LOW_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM0_LOW_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM0_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            if ((DCDC->pmpfreq & PWM0_HIGH_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM0_HIGH_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM0_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        default:
            break;
    }

    return ret;
}


/***********************************************************************
 *
 * Function:  LH7A400_pwm1_increase_clock_prescaler
 *
 * Purpose:
 *     increase PWM1 clock prescaler by ONE for selected power-type
 *
 * Processing:
 *   - read current PWM1 Clock-Prescalers
 *   - 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_clock_prescaler (UNS_8 power)
{
    INT_8   ret;

    ret = _NO_ERROR;

    switch (power)
    {
        case EXTERN_POWER:     // inc. PWM1 LOW field
            if ((DCDC->pmpfreq & PWM1_LOW_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM1_LOW_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM1_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            break;

        case BATTERY_POWER:    // inc. PWM1 HIGH field
            if ((DCDC->pmpfreq & PWM1_HIGH_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM1_HIGH_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM1_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            break;

        case ALL_POWER_TYPES:  // inc. PWM1 LOW & HIGH fields
            if ((DCDC->pmpfreq & PWM1_LOW_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM1_LOW_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM1_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            if ((DCDC->pmpfreq & PWM1_HIGH_DATA_MASK) <
                (MAX_PRESCALE_VALUE << PWM1_HIGH_DATA_POSITION)
               ) // inc. if current field value less-than MAX allowed
            {
                DCDC->pmpfreq +=  PWM1_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't increment.
                ret = _ERROR;
            }
            break;

        default:
            break;
    }

    return ret;
}


/***********************************************************************
 *
 * Function:  LH7A400_pwm1_decrease_clock_prescaler
 *
 * Purpose:
 *     decrease PWM1 clock prescaler by ONE for selected power-type
 *
 * Processing:
 *   - read current PWM1 Clock-Prescalers
 *   - 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_clock_prescaler (UNS_8 power)
{
    INT_8   ret;

    ret = _NO_ERROR;

    switch (power)
    {
        case EXTERN_POWER:     // dec. PWM1 LOW field
            if ((DCDC->pmpfreq & PWM1_LOW_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM1_LOW_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM1_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        case BATTERY_POWER:    // dec. PWM1 HIGH field
            if ((DCDC->pmpfreq & PWM1_HIGH_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM1_HIGH_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM1_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        case ALL_POWER_TYPES:  // dec. PWM1 LOW & HIGH fields
            if ((DCDC->pmpfreq & PWM1_LOW_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM1_LOW_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM1_LOW_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            if ((DCDC->pmpfreq & PWM1_HIGH_DATA_MASK) >
                (MIN_PRESCALE_VALUE << PWM1_HIGH_DATA_POSITION)
               ) // dec. if current field value greater-than MIN allowed
            {
                DCDC->pmpfreq -=  PWM1_HIGH_DATA_SELECT;
            }
            else
            {    // if not, can't decrement.
                ret = _ERROR;
            }
            break;

        default:
            break;
    }

    return ret;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -