From a7106021ed89992bc5ebd69ac000c7b90cde7276 Mon Sep 17 00:00:00 2001 From: Doug Anderson Date: Tue, 27 Aug 2013 09:54:47 -0700 Subject: [PATCH] battery: Add sleep param; make errors fatal in the loop If you're running the battery command in a loop: * You may need a sleep so you don't trigger watchdog resets, at least if you're running at a low clock frequency. * You probably want to break on an error. Make the sleep delay come from a parameter since you might want to avoid it if you just want to pound on the bus as fast as possible. BRANCH=pit BUG=chrome-os-partner:22093 TEST=With all patches together: - on AP: suspend_stress_test - on EC: battery 10000 50 Change-Id: I6ae6d818c06f59064e90bd6d23d6d4c782544849 Signed-off-by: Doug Anderson Previous-Reviewed-on: https://chromium-review.googlesource.com/167103 (cherry picked from commit 703ce2abf2e38b0f1434224534c1be505e1244f7) Reviewed-on: https://chromium-review.googlesource.com/167160 Reviewed-by: Hung-ying Tyan Reviewed-by: Rong Chang Reviewed-by: Randall Spangler --- common/smart_battery.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/smart_battery.c b/common/smart_battery.c index 536959bd82..3991a2e270 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -229,6 +229,7 @@ static int command_battery(int argc, char **argv) int repeat = 1; int rv = 0; int loop; + int sleep_ms = 0; char *e; if (argc > 1) { @@ -239,16 +240,31 @@ static int command_battery(int argc, char **argv) } } - for (loop = 0; loop < repeat; loop++) + if (argc > 2) { + sleep_ms = strtoi(argv[2], &e, 0); + if (*e) { + ccputs("Invalid sleep ms\n"); + return EC_ERROR_INVAL; + } + } + + for (loop = 0; loop < repeat; loop++) { rv = print_battery_info(); + if (sleep_ms) + msleep(sleep_ms); + + if (rv) + break; + } + if (rv) ccprintf("Failed - error %d\n", rv); return rv ? EC_ERROR_UNKNOWN : EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(battery, command_battery, - "", + " ", "Print battery info", NULL);