diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-02-12 10:54:26 -0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-02-12 13:46:44 -0800 |
commit | 9fde14da9b2e8d8944e66c5b8f4798e0c40be72e (patch) | |
tree | 24ebaa6fb2b1ef3e16f5f73bc987b7736a681151 | |
parent | c19a4db9e4935400b24bd5bb43452019ff1843b8 (diff) | |
download | chrome-ec-9fde14da9b2e8d8944e66c5b8f4798e0c40be72e.tar.gz |
Rename and document battery constants
In preparation for cleaning up low-battery logic. Make clear what
comparison operator is used for each constant (<=, <, >=, >).
Also remove hard-coded and unused display of design warning/low
battery levels from ectool. Verified via code search that these are
not used anywhere. Even if we later care about these levels, they
should be battery-specific and not hard-coded as a
platform-independent percentage of full capacity when ectool is
compiled.
BUG=chrome-os-partner:17124
BRANCH=link
TEST=compile link; 'ectool battery' from root shell prints valid info
Change-Id: I3650e27a08f4cc77067beb0685ee1488cc56d02f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/43119
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | common/charge_state.c | 16 | ||||
-rw-r--r-- | include/battery.h | 36 | ||||
-rw-r--r-- | util/ectool.c | 8 |
3 files changed, 28 insertions, 32 deletions
diff --git a/common/charge_state.c b/common/charge_state.c index ef7df7d115..f413d58c3a 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * @@ -350,14 +350,14 @@ static enum power_state state_idle(struct power_state_context *ctx) ctx->curr.charging_current) return PWR_STATE_INIT; - if (batt->state_of_charge >= STOP_CHARGE_THRESHOLD) + if (batt->state_of_charge >= BATTERY_LEVEL_FULL) return PWR_STATE_UNCHANGE; /* Configure init charger state and switch to charge state */ if (batt->desired_voltage && batt->desired_current) { /* Set charger output constraints */ if (batt->desired_current < ctx->charger->current_min && - batt->state_of_charge < PRE_CHARGE_THRESHOLD) { + batt->state_of_charge < BATTERY_LEVEL_PRE_CHARGE) { /* Trickle charging */ if (charger_set_current(c_info->current_min) || charger_set_voltage(batt->voltage)) @@ -377,7 +377,7 @@ static enum power_state state_idle(struct power_state_context *ctx) } update_charger_time(ctx, get_time()); - if (ctx->curr.batt.state_of_charge < NEAR_FULL_THRESHOLD) + if (ctx->curr.batt.state_of_charge < BATTERY_LEVEL_NEAR_FULL) return PWR_STATE_CHARGE; else return PWR_STATE_CHARGE_NEAR_FULL; @@ -406,7 +406,7 @@ static enum power_state state_charge(struct power_state_context *ctx) if (batt->desired_current < c_info->current_min && batt->desired_current > 0 && - batt->state_of_charge < PRE_CHARGE_THRESHOLD) + batt->state_of_charge < BATTERY_LEVEL_PRE_CHARGE) return trickle_charge(ctx); /* Check charger reset */ @@ -417,7 +417,7 @@ static enum power_state state_charge(struct power_state_context *ctx) if (!curr->ac) return PWR_STATE_INIT; - if (batt->state_of_charge >= STOP_CHARGE_THRESHOLD) { + if (batt->state_of_charge >= BATTERY_LEVEL_FULL) { if (charger_set_voltage(0) || charger_set_current(0)) return PWR_STATE_ERROR; return PWR_STATE_IDLE; @@ -645,7 +645,7 @@ void charge_state_machine_task(void) new_state = state_charge(ctx); if (new_state == PWR_STATE_UNCHANGE && (ctx->curr.batt.state_of_charge >= - NEAR_FULL_THRESHOLD)) { + BATTERY_LEVEL_NEAR_FULL)) { /* Almost done charging */ new_state = PWR_STATE_CHARGE_NEAR_FULL; } @@ -655,7 +655,7 @@ void charge_state_machine_task(void) new_state = state_charge(ctx); if (new_state == PWR_STATE_UNCHANGE && (ctx->curr.batt.state_of_charge < - NEAR_FULL_THRESHOLD)) { + BATTERY_LEVEL_NEAR_FULL)) { /* Battery below almost-full threshold. */ new_state = PWR_STATE_CHARGE; } diff --git a/include/battery.h b/include/battery.h index 12b10422da..da4071e158 100644 --- a/include/battery.h +++ b/include/battery.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * @@ -8,21 +8,25 @@ #ifndef __CROS_EC_BATTERY_H #define __CROS_EC_BATTERY_H -/* Design capacities, percentage */ -#define BATTERY_LEVEL_WARNING 15 -#define BATTERY_LEVEL_LOW 10 -#define BATTERY_LEVEL_CRITICAL 5 -/* Shut down main processor when battery level reaches this level */ -#define BATTERY_LEVEL_SHUTDOWN 3 -/* Hibernate EC immediately when battery level reaches this level */ -#define BATTERY_LEVEL_HIBERNATE_EC 2 - -/* Stop charge when state of charge reaches this percentage */ -#define STOP_CHARGE_THRESHOLD 100 -/* Tell host we're charged at this percentage */ -#define NEAR_FULL_THRESHOLD 97 -/* Precharge only when state of charge is below this level */ -#define PRE_CHARGE_THRESHOLD 25 +/* Stop charge when charging and battery level >= this percentage */ +#define BATTERY_LEVEL_FULL 100 +/* Tell host we're charged when battery level >= this percentage */ +#define BATTERY_LEVEL_NEAR_FULL 97 +/* Precharge only when charging and battery level < this level */ +#define BATTERY_LEVEL_PRE_CHARGE 25 +/* + * Send battery-low host event when discharging and battery level <= this level + */ +#define BATTERY_LEVEL_LOW 10 +/* + * Send battery-critical host event when discharging and battery level <= this + * level. + */ +#define BATTERY_LEVEL_CRITICAL 5 +/* Shut down main processor when discharging and battery level < this level */ +#define BATTERY_LEVEL_SHUTDOWN 3 +/* Hibernate EC immediately when discharging and battery level < this level */ +#define BATTERY_LEVEL_HIBERNATE_EC 2 #endif /* __CROS_EC_BATTERY_H */ diff --git a/util/ectool.c b/util/ectool.c index 34eeb3df94..253dc2ef27 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -2184,14 +2184,6 @@ int cmd_battery(int argc, char *argv[]) goto cmd_error; printf(" Design output voltage %u mV\n", val); - val = read_mapped_mem32(EC_MEMMAP_BATT_DCAP); - if (!is_battery_range(val)) - goto cmd_error; - printf(" Design capacity warning %u mAh\n", - val * BATTERY_LEVEL_WARNING / 100); - printf(" Design capacity low %u mAh\n", - val * BATTERY_LEVEL_LOW / 100); - val = read_mapped_mem32(EC_MEMMAP_BATT_CCNT); if (!is_battery_range(val)) goto cmd_error; |