diff options
author | Vic Yang <victoryang@chromium.org> | 2013-03-20 10:58:12 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-21 09:53:36 -0700 |
commit | 5c59bd4975aa8b1022b799f1f624f2bb7f03e90e (patch) | |
tree | e243674b8964975a5f6e03ea8439f59337c7f379 | |
parent | bac6621b5edd351884d06725a6b36a293297365d (diff) | |
download | chrome-ec-5c59bd4975aa8b1022b799f1f624f2bb7f03e90e.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
Original-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>
(cherry picked from commit cdb08e12217367f0ac8c6ce0dc1df2e27f80563e)
Change-Id: I087877a65893814beac59c7cd8a004c44bf13ede
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/46111
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 ee9c8091c9..aebe067d8d 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 @@ -377,7 +377,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(); /* @@ -419,14 +419,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]); @@ -435,6 +437,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; @@ -470,10 +474,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 (board_get_ac()) { |