summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRong Chang <rongchang@chromium.org>2012-09-10 15:33:43 +0800
committerRong Chang <rongchang@chromium.org>2012-09-10 17:25:45 -0700
commit3d05292d34f9840488f868d48def142efe03cc82 (patch)
tree31458164e3aaff5fac5ac005381ddd6d2c74c275
parent32722ff042349f49604a5497a6e20fbc30ea23ad (diff)
downloadchrome-ec-3d05292d34f9840488f868d48def142efe03cc82.tar.gz
snow: Check state of charge using moving average
Signed-off-by: Rong Chang <rongchang@chromium.org> BRANCH=snow BUG=chrome-os-partner:13846 TEST=manual Connect EC UART console and discharge snow device. The system should be turned off when average state of charge is lower than 2.5%. Original-Change-Id: Iab9797d0aa6b159bedd8ce0d2fa72c6458cd14ac Reviewed-on: https://gerrit.chromium.org/gerrit/32693 Commit-Ready: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org> Reviewed-by: Sameer Nanda <snanda@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org> (cherry picked from commit e21db5e488259d5bcab1a8429367b5c8b35cfc27) Change-Id: Ic8d47f3ec43f6bda4a97637f451b8ba2ff675bd0 Reviewed-on: https://gerrit.chromium.org/gerrit/32852 Reviewed-by: Rong Chang <rongchang@chromium.org> Tested-by: Rong Chang <rongchang@chromium.org>
-rw-r--r--common/pmu_tps65090_charger.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c
index 8ef77fb340..b1284759de 100644
--- a/common/pmu_tps65090_charger.c
+++ b/common/pmu_tps65090_charger.c
@@ -129,6 +129,39 @@ static int notify_battery_low(void)
return ST_DISCHARGING;
}
+/*
+ * Calculate relative state of charge moving average
+ *
+ * The returned value will be rounded to the nearest integer, by set moving
+ * average init value to (0.5 * window_size).
+ *
+ */
+static int rsoc_moving_average(int state_of_charge)
+{
+ static uint8_t rsoc[4];
+ static int8_t index = -1;
+ int moving_average = sizeof(rsoc) / 2;
+ int i;
+
+ if (index < 0) {
+ for (i = 0; i < sizeof(rsoc); i++)
+ rsoc[i] = (uint8_t)state_of_charge;
+ index = 0;
+ return state_of_charge;
+ }
+
+ rsoc[index] = (uint8_t)state_of_charge;
+ index++;
+ index %= sizeof(rsoc);
+
+ for (i = 0; i < sizeof(rsoc); i++)
+ moving_average += (int)rsoc[i];
+ moving_average /= sizeof(rsoc);
+
+ return moving_average;
+}
+
+
static int config_low_current_charging(int charge)
{
/* Disable low current termination */
@@ -269,7 +302,11 @@ static int calc_next_state(int state)
}
/* Check remaining charge % */
if (battery_state_of_charge(&capacity) == 0) {
- if (capacity < 3) {
+ /*
+ * Shutdown AP when state of charge < 2.5%.
+ * Moving average is rounded to integer.
+ */
+ if (rsoc_moving_average(capacity) < 3) {
system_off();
return ST_IDLE;
} else if (capacity < 10) {