Logo Search packages:      
Sourcecode: linux-fsl-imx51 version File versions  Download package

static ddi_bc_Status_t ddi_bc_Conditioning ( void   )  [static]

Conditioning state function.

Function

This function implements the Conditioning state.

Definition at line 502 of file ddi_bc_sm.c.

References DDI_BC_BROKEN_CHARGING_TIMEOUT, DDI_BC_BROKEN_NO_BATTERY_DETECTED, ddi_bc_hwGetBatteryVoltage(), ddi_bc_hwPowerSupplyIsPresent(), ddi_bc_RampGetBatteryTempAlarm(), ddi_bc_RampGetDieTempAlarm(), ddi_bc_RampStep(), ddi_bc_RampUpdateAlarms(), DDI_BC_STATUS_BROKEN, DDI_BC_STATUS_SUCCESS, ddi_power_GetMaxBatteryChargeCurrent(), g_ddi_bc_Configuration, TransitionToBroken(), TransitionToCharging(), TransitionToWaitingToCharge(), _ddi_bc_Cfg::u16ConditioningCurrent, _ddi_bc_Cfg::u16ConditioningMaxVoltage, _ddi_bc_Cfg::u32ConditioningTimeout, and _ddi_bc_Cfg::u32StateMachinePeriod.

{

      //--------------------------------------------------------------------------
      // The first order of business is to update alarms.
      //--------------------------------------------------------------------------

      ddi_bc_RampUpdateAlarms();

      //--------------------------------------------------------------------------
      // If we're not under an alarm, increment the state timer.
      //--------------------------------------------------------------------------

      if (!ddi_bc_RampGetDieTempAlarm() && !ddi_bc_RampGetBatteryTempAlarm()) {
            g_ddi_bc_u32StateTimer +=
                g_ddi_bc_Configuration.u32StateMachinePeriod;
      }
      //--------------------------------------------------------------------------
      // Check if the power supply is still around.
      //--------------------------------------------------------------------------

      if (!ddi_bc_hwPowerSupplyIsPresent()) {

            //----------------------------------------------------------------------
            // If control arrives here, the power supply has been removed. Go back
            // and wait.
            //----------------------------------------------------------------------

            TransitionToWaitingToCharge();

            //----------------------------------------------------------------------
            // Return success.
            //----------------------------------------------------------------------

            return (DDI_BC_STATUS_SUCCESS);

      }

      //--------------------------------------------------------------------------
      // If control arrives here, we're still connected to a power supply.
      // Check if a battery is connected.  If the voltage rises to high with only
      // conditioning charge current, we determine that a battery is not connected.
      // If that is not the case and a battery is connected, check
      // if the battery voltage indicates it still needs conditioning.
      //--------------------------------------------------------------------------

//    if (ddi_bc_hwGetBatteryVoltage() >= 3900) {
      if ((ddi_bc_hwGetBatteryVoltage() >
           g_ddi_bc_Configuration.u16ConditioningMaxVoltage) &&
          (ddi_power_GetMaxBatteryChargeCurrent() <
           g_ddi_bc_Configuration.u16ConditioningCurrent)) {
            //----------------------------------------------------------------------
            // If control arrives here, voltage has risen too quickly for so
            // little charge being applied so their must be no battery connected.
            //----------------------------------------------------------------------

            ddi_bc_gBrokenReason = DDI_BC_BROKEN_NO_BATTERY_DETECTED;

            TransitionToBroken();

            //----------------------------------------------------------------------
            // Tell our caller the battery appears to be broken.
            //----------------------------------------------------------------------

            return (DDI_BC_STATUS_BROKEN);

      }

      if (ddi_bc_hwGetBatteryVoltage() >=
          g_ddi_bc_Configuration.u16ConditioningMaxVoltage) {

            //----------------------------------------------------------------------
            // If control arrives here, this battery no longer needs conditioning.
            //----------------------------------------------------------------------

            TransitionToCharging();

            //----------------------------------------------------------------------
            // Return success.
            //----------------------------------------------------------------------

            return (DDI_BC_STATUS_SUCCESS);

      }
      //--------------------------------------------------------------------------
      // Have we been in this state too long?
      //--------------------------------------------------------------------------

      if (g_ddi_bc_u32StateTimer >=
          g_ddi_bc_Configuration.u32ConditioningTimeout) {

            //----------------------------------------------------------------------
            // If control arrives here, we've been here too long.
            //----------------------------------------------------------------------

            ddi_bc_gBrokenReason = DDI_BC_BROKEN_CHARGING_TIMEOUT;

            TransitionToBroken();

            //----------------------------------------------------------------------
            // Tell our caller the battery appears to be broken.
            //----------------------------------------------------------------------

            return (DDI_BC_STATUS_BROKEN);

      }
      //--------------------------------------------------------------------------
      // If control arrives here, we're staying in this state. Step the current
      // ramp.
      //--------------------------------------------------------------------------

      ddi_bc_RampStep(g_ddi_bc_Configuration.u32StateMachinePeriod);

      //--------------------------------------------------------------------------
      // Return success.
      //--------------------------------------------------------------------------

      return (DDI_BC_STATUS_SUCCESS);

}


Generated by  Doxygen 1.6.0   Back to index