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 <dianders@chromium.org>
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 <tyanh@google.com>
Reviewed-by: Rong Chang <rongchang@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Doug Anderson
2013-08-27 09:54:47 -07:00
committed by chrome-internal-fetch
parent 266807f289
commit a7106021ed

View File

@@ -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,
"<repeat_count>",
"<repeat_count> <sleep_ms>",
"Print battery info",
NULL);