Use timeout instead of retry count for pre-charging

Now that PMU task is waken not only by timer, we shouldn't depend on
retry count anymore. This moves pre-charging timeout to actually use
timestamp.

BUG=none
TEST=Remove battery and boot. See charge state goes to error after 15
seconds.
BRANCH=spring

Change-Id: Iff587bc824ffee93650184c14f1fc403d26ebc06
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/45957
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vic Yang
2013-03-20 10:58:12 +08:00
committed by ChromeBot
parent 89ad54d2b2
commit cdb08e1221

View File

@@ -29,8 +29,8 @@
ALARM_OVER_CHARGED | \
ALARM_OVER_TEMP)
/* Maximum retry count to revive a extremely low charge battery */
#define PRE_CHARGING_RETRY 3
/* Maximum time allowed to revive a extremely low charge battery */
#define PRE_CHARGING_TIMEOUT (15 * SECOND)
/*
* Time delay in usec for idle, charging and discharging. Defined in battery
@@ -394,7 +394,7 @@ void pmu_charger_task(void)
{
int next_state;
int wait_time = T1_USEC;
unsigned int pre_charging_count = 0;
timestamp_t pre_chg_start = get_time();
pmu_init();
/*
@@ -436,14 +436,16 @@ void pmu_charger_task(void)
* charger should be disabled if the communication to battery
* failed.
*/
next_state = pre_charging_count > PRE_CHARGING_RETRY ?
ST_CHARGING_ERROR : calc_next_state(current_state);
if (current_state == ST_PRE_CHARGING &&
get_time().val - pre_chg_start.val >= PRE_CHARGING_TIMEOUT)
next_state = ST_CHARGING_ERROR;
else
next_state = calc_next_state(current_state);
if (next_state != current_state) {
/* Reset state of charge moving average window */
rsoc_moving_average(-1);
pre_charging_count = 0;
CPRINTF("[batt] state %s -> %s\n",
state_list[current_state],
state_list[next_state]);
@@ -452,6 +454,8 @@ void pmu_charger_task(void)
switch (current_state) {
case ST_PRE_CHARGING:
pre_chg_start = get_time();
/* Fall through */
case ST_CHARGING:
if (pmu_blink_led(0))
next_state = ST_CHARGING_ERROR;
@@ -487,10 +491,9 @@ void pmu_charger_task(void)
break;
case ST_PRE_CHARGING:
wait_time = T1_USEC;
if (pre_charging_count > PRE_CHARGING_RETRY)
if (get_time().val - pre_chg_start.val >=
PRE_CHARGING_TIMEOUT)
enable_charging(0);
else
pre_charging_count++;
break;
default:
if (extpower_is_present()) {