diff options
author | Vic Yang <victoryang@chromium.org> | 2013-03-20 10:58:12 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-20 23:47:46 -0700 |
commit | cdb08e12217367f0ac8c6ce0dc1df2e27f80563e (patch) | |
tree | 0450b0b7f851106752698d2b3a269d04b4f6de3b | |
parent | 89ad54d2b2c4abdb7ffdba8b9912f7be34fbc686 (diff) | |
download | chrome-ec-cdb08e12217367f0ac8c6ce0dc1df2e27f80563e.tar.gz |
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>
-rw-r--r-- | common/pmu_tps65090_charger.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index c07d643e97..4da619ea39 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -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()) { |