summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-05-14 12:13:08 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-05-15 05:28:08 +0000
commit65df2fd6e444f6655838d55af63de59e699238a2 (patch)
tree8049186891b2509a1bced4d30cf4ba15b238d54c
parent10aecec841361727e7ed8f16a13e0d7a575e77ff (diff)
downloadchrome-ec-65df2fd6e444f6655838d55af63de59e699238a2.tar.gz
Add "debug" option to charge_state_v2.c
This is useful for testing battery charge profiles. When enabled, a dump of all battery, charger, and charge state information will be printed whenever the battery charge percentage changes. BUG=none BRANCH=ToT TEST=make buildall -j On the EC console: chg debug on then watch the console while either charging or discharging the battery. Disable with chg debug off Change-Id: I6725c461461f90fcd812873f97490e980ab47bc6 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/199816 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--common/battery.c13
-rw-r--r--common/charge_state_v2.c18
-rw-r--r--common/charger.c11
-rw-r--r--include/battery.h5
-rw-r--r--include/charger.h3
5 files changed, 40 insertions, 10 deletions
diff --git a/common/battery.c b/common/battery.c
index 20baa1e431..323f3d2790 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -209,6 +209,14 @@ static void print_battery_info(void)
}
}
+void print_battery_debug(void)
+{
+ print_battery_status();
+ print_battery_params();
+ print_battery_strings();
+ print_battery_info();
+}
+
static int command_battery(int argc, char **argv)
{
int repeat = 1;
@@ -233,10 +241,7 @@ static int command_battery(int argc, char **argv)
}
for (loop = 0; loop < repeat; loop++) {
- print_battery_status();
- print_battery_params();
- print_battery_strings();
- print_battery_info();
+ print_battery_debug();
/*
* Running with a high repeat count will take so long the
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index a5a621da8b..3109f23363 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -43,6 +43,7 @@ test_export_static timestamp_t shutdown_warning_time;
static timestamp_t precharge_start_time;
static int battery_seems_to_be_dead;
static int problems_exist;
+static int debugging;
/* Track problems in communicating with the battery or charger */
enum problem_type {
@@ -245,6 +246,7 @@ static void dump_charge_state(void)
ccprintf(" manual_mode = %d\n", manual_mode);
ccprintf(" user_current_limit = %dmA\n", user_current_limit);
ccprintf(" battery_seems_to_be_dead = %d\n", battery_seems_to_be_dead);
+ ccprintf(" debug output = %s\n", debugging ? "on" : "off");
#undef DUMP
}
@@ -270,6 +272,15 @@ static void show_charging_progress(void)
curr.batt.state_of_charge,
minutes / 60, minutes % 60,
to_full ? "to full" : "to empty");
+
+ if (debugging) {
+ ccprintf("battery:\n");
+ print_battery_debug();
+ ccprintf("charger:\n");
+ print_charger_debug();
+ ccprintf("chg:\n");
+ dump_charge_state();
+ }
}
/*
@@ -917,6 +928,11 @@ static int command_chgstate(int argc, char **argv)
rv = charge_force_idle(val);
if (rv)
return rv;
+ } else if (!strcasecmp(argv[1], "debug")) {
+ if (argc <= 2)
+ return EC_ERROR_PARAM_COUNT;
+ if (!parse_bool(argv[2], &debugging))
+ return EC_ERROR_PARAM2;
} else {
/* maybe handle board_discharge_on_ac() too? */
return EC_ERROR_PARAM1;
@@ -927,6 +943,6 @@ static int command_chgstate(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(chgstate, command_chgstate,
- "[idle on|off]",
+ "[idle|debug on|off]",
"Get/set charge state machine status",
NULL);
diff --git a/common/charger.c b/common/charger.c
index 8a07a62818..36d81fd3d0 100644
--- a/common/charger.c
+++ b/common/charger.c
@@ -5,6 +5,7 @@
* Common functions for battery charging.
*/
+#include "battery_smart.h"
#include "charger.h"
#include "common.h"
#include "console.h"
@@ -114,7 +115,7 @@ static int check_print_error(int rv)
return 0;
}
-static int print_info(void)
+void print_charger_debug(void)
{
int d;
const struct charger_info *info = charger_get_info();
@@ -165,8 +166,6 @@ static int print_info(void)
ccprintf("%5d\n", dptf_limit_ma);
else
ccputs("disabled\n");
-
- return EC_SUCCESS;
}
static int command_charger(int argc, char **argv)
@@ -174,8 +173,10 @@ static int command_charger(int argc, char **argv)
int d;
char *e;
- if (argc != 3)
- return print_info();
+ if (argc != 3) {
+ print_charger_debug();
+ return EC_SUCCESS;
+ }
if (strcasecmp(argv[1], "input") == 0) {
d = strtoi(argv[2], &e, 0);
diff --git a/include/battery.h b/include/battery.h
index e395839546..b61da1833c 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -309,4 +309,9 @@ int battery_set_vendor_param(uint32_t param, uint32_t value);
*/
int battery_wait_for_stable(void);
+/**
+ * Print all battery info for debugging purposes
+ */
+void print_battery_debug(void);
+
#endif /* __CROS_EC_BATTERY_H */
diff --git a/include/charger.h b/include/charger.h
index bb84990856..8b65c388f3 100644
--- a/include/charger.h
+++ b/include/charger.h
@@ -107,5 +107,8 @@ int charger_device_id(int *id);
int charger_get_option(int *option);
int charger_set_option(int option);
+/* Print all charger info for debugging purposes */
+void print_charger_debug(void);
+
#endif /* __CROS_EC_CHARGER_H */