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

ddi_bc_Status_t ddi_bc_RampStep ( uint32_t  u32Time  ) 

Step the current ramp.

Function

This function steps the current ramp forward through the given amount of time.

Parameters:
[in] u32Time The time increment to add.
Return values:
DDI_BC_STATUS_SUCCESS If the operation succeeded.
DDI_BC_STATUS_NOT_INITIALIZED If the Battery Charger is not yet initialized.

Definition at line 487 of file ddi_bc_ramp.c.

References _ddi_bc_RampControl::batteryTempAlarm, ddi_bc_hwExpressibleCurrent(), ddi_bc_hwGetMaxCurrent(), ddi_bc_hwSetChargerPower(), ddi_bc_hwSetMaxCurrent(), DDI_BC_STATE_UNINITIALIZED, DDI_BC_STATUS_NOT_INITIALIZED, DDI_BC_STATUS_SUCCESS, _ddi_bc_RampControl::dieTempAlarm, g_ddi_bc_Configuration, g_ddi_bc_State, _ddi_bc_Cfg::u16BatteryTempSafeCurrent, _ddi_bc_Cfg::u16CurrentRampSlope, _ddi_bc_Cfg::u16DieTempSafeCurrent, _ddi_bc_RampControl::u16Limit, _ddi_bc_RampControl::u16Target, and _ddi_bc_RampControl::u32AccumulatedTime.

Referenced by ddi_bc_Charging(), ddi_bc_Conditioning(), ddi_bc_RampReset(), ddi_bc_RampSetLimit(), ddi_bc_RampSetTarget(), ddi_bc_RampUpdateAlarms(), and ddi_bc_ToppingOff().

{

      uint16_t u16MaxNow;
      uint16_t u16Target;
      uint16_t u16Cart;
      int32_t i32Delta;

      //--------------------------------------------------------------------------
      // Make sure the Battery Charger is initialized.
      //--------------------------------------------------------------------------

      if (g_ddi_bc_State == DDI_BC_STATE_UNINITIALIZED) {
            return (DDI_BC_STATUS_NOT_INITIALIZED);
      }
      //--------------------------------------------------------------------------
      // Figure out how much current the hardware is set to draw right now.
      //--------------------------------------------------------------------------

      u16MaxNow = ddi_bc_hwGetMaxCurrent();

      //--------------------------------------------------------------------------
      // Start with the target.
      //--------------------------------------------------------------------------

      u16Target = g_RampControl.u16Target;

      //--------------------------------------------------------------------------
      // Check the target against the hard limit.
      //--------------------------------------------------------------------------

      if (u16Target > g_RampControl.u16Limit)
            u16Target = g_RampControl.u16Limit;

      //--------------------------------------------------------------------------
      // Check if the die temperature alarm is active.
      //--------------------------------------------------------------------------

      if (g_RampControl.dieTempAlarm) {

            //----------------------------------------------------------------------
            // If control arrives here, we are under a die temperature alarm. Clamp
            // the target current.
            //----------------------------------------------------------------------

            if (u16Target > g_ddi_bc_Configuration.u16DieTempSafeCurrent) {
                  u16Target =
                      g_ddi_bc_Configuration.u16DieTempSafeCurrent;
            }

      }
      //--------------------------------------------------------------------------
      // Check if the battery temperature alarm is active.
      //--------------------------------------------------------------------------

      if (g_RampControl.batteryTempAlarm) {

            //----------------------------------------------------------------------
            // If control arrives here, we are under a battery temperature alarm.
            // Clamp the target current.
            //----------------------------------------------------------------------

            if (u16Target >
                g_ddi_bc_Configuration.u16BatteryTempSafeCurrent) {
                  u16Target =
                      g_ddi_bc_Configuration.u16BatteryTempSafeCurrent;
            }

      }
      //--------------------------------------------------------------------------
      // Now we know the target current. Figure out what is actually expressible
      // in the hardware.
      //--------------------------------------------------------------------------

      u16Target = ddi_bc_hwExpressibleCurrent(u16Target);

      //--------------------------------------------------------------------------
      // Compute the difference between the expressible target and what's actually
      // set in the hardware right now.
      //--------------------------------------------------------------------------

      i32Delta = ((int32_t) u16Target) - ((int32_t) u16MaxNow);

      //--------------------------------------------------------------------------
      // Check if the delta is zero.
      //--------------------------------------------------------------------------

      if (i32Delta == 0) {

            //----------------------------------------------------------------------
            // If control arrives here, there is no difference between what we want
            // and what's set in the hardware.
            //
            // Before we leave, though, we don't want to leave any accumulated time
            // laying around for the next ramp up. Zero it out.
            //----------------------------------------------------------------------

            g_RampControl.u32AccumulatedTime = 0;

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

            return (DDI_BC_STATUS_SUCCESS);

      }
      //--------------------------------------------------------------------------
      // Check if the delta is negative.
      //--------------------------------------------------------------------------

      if (i32Delta < 0) {

            //----------------------------------------------------------------------
            // If control arrives here, the new target is lower than what's
            // currently set in the hardware. Since that means we're *reducing* the
            // current draw, we can do it right now. Just gimme a sec here...
            //----------------------------------------------------------------------

            ddi_bc_hwSetMaxCurrent(u16Target);

#ifdef CONFIG_POWER_SUPPLY_DEBUG
            printk("Battery charger: setting max charge "
                   "current to: %hdmA\r\n", u16Target);
#endif

            //----------------------------------------------------------------------
            // Flip the power switch on the charging hardware according to the new
            // current setting.
            //----------------------------------------------------------------------

            ddi_bc_hwSetChargerPower(u16Target != 0);

            //----------------------------------------------------------------------
            // We don't want to leave any accumulated time laying around for the
            // next ramp up. Zero it out.
            //----------------------------------------------------------------------

            g_RampControl.u32AccumulatedTime = 0;

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

            return (DDI_BC_STATUS_SUCCESS);

      }
      //--------------------------------------------------------------------------
      // If control arrives here, the target current is higher than what's set in
      // the hardware right now. That means we're going to ramp it up. To do that,
      // we're going to "buy" more milliamps by "spending" milliseconds of time.
      // Add the time we've "banked" to the time we've been credited in this call.
      //--------------------------------------------------------------------------

      u32Time += g_RampControl.u32AccumulatedTime;

      //--------------------------------------------------------------------------
      // Now we know how much we can spend. How much current will it buy?
      //--------------------------------------------------------------------------

      u16Cart = (g_ddi_bc_Configuration.u16CurrentRampSlope * u32Time) / 1000;

      //--------------------------------------------------------------------------
      // Check how the current we can afford stacks up against the target we want.
      //--------------------------------------------------------------------------

      if ((u16MaxNow + u16Cart) < u16Target) {

            //----------------------------------------------------------------------
            // If control arrives here, we can't afford to buy all the current we
            // want. Compute the maximum we can afford, and then figure out what we
            // can actually express in the hardware.
            //----------------------------------------------------------------------

            u16Target = ddi_bc_hwExpressibleCurrent(u16MaxNow + u16Cart);

            //----------------------------------------------------------------------
            // Check if the result isn't actually different from what's set in the
            // the hardware right now.
            //----------------------------------------------------------------------

            if (u16Target == u16MaxNow) {

                  //------------------------------------------------------------------
                  // If control arrives here, we are so poor that we can't yet afford
                  // to buy enough current to make a change in the expressible
                  // hardware setting. Since we didn't spend any of our time, put the
                  // new balance back in the bank.
                  //------------------------------------------------------------------

                  g_RampControl.u32AccumulatedTime = u32Time;

                  //------------------------------------------------------------------
                  // Leave dispiritedly.
                  //------------------------------------------------------------------

                  return (DDI_BC_STATUS_SUCCESS);

            }

      }
      //--------------------------------------------------------------------------
      // If control arrives here, we can afford to buy enough current to get us
      // all the way to the target. Set it.
      //--------------------------------------------------------------------------

      ddi_bc_hwSetMaxCurrent(u16Target);

#ifdef CONFIG_POWER_SUPPLY_DEBUG
      printk("Battery charger: setting max charge"
             "current to: %hdmA\r\n", u16Target);
#endif

      //--------------------------------------------------------------------------
      // Flip the power switch on the charging hardware according to the new
      // current setting.
      //--------------------------------------------------------------------------

      ddi_bc_hwSetChargerPower(u16Target != 0);

      //--------------------------------------------------------------------------
      // We're at the target, so we're finished buying current. Zero out the
      // account.
      //--------------------------------------------------------------------------

      g_RampControl.u32AccumulatedTime = 0;

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

      return (DDI_BC_STATUS_SUCCESS);

}


Generated by  Doxygen 1.6.0   Back to index