summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-02-12 10:54:26 -0800
committerRandall Spangler <rspangler@chromium.org>2013-03-05 15:14:45 -0800
commit0046e5fcd3bf7586aec78ec60818b356c79ed4ac (patch)
tree2a84b21e874a770782e1ebf378c7732c2d9c7282
parent492043cb75414f849972c0af67623c4acb6efb31 (diff)
downloadchrome-ec-0046e5fcd3bf7586aec78ec60818b356c79ed4ac.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 Original-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> (cherry picked from commit 9fde14da9b2e8d8944e66c5b8f4798e0c40be72e) Change-Id: Id74d55fed9bb306e9cf5a0aed86caf81ec2fe7d0 Reviewed-on: https://gerrit.chromium.org/gerrit/44686 Commit-Queue: Randall Spangler <rspangler@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Tested-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/charge_state.c16
-rw-r--r--include/battery.h36
-rw-r--r--util/ectool.c10
3 files changed, 29 insertions, 33 deletions
diff --git a/common/charge_state.c b/common/charge_state.c
index 60f4c4de79..ddf11f6c7e 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.
*
@@ -357,14 +357,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))
@@ -384,7 +384,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;
@@ -411,7 +411,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 */
@@ -422,7 +422,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 f83ae0f3d5..d2f2979795 100644
--- a/util/ectool.c
+++ b/util/ectool.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.
*/
@@ -2136,14 +2136,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;