summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorRuben Rodriguez Buchillon <coconutruben@chromium.org>2017-11-28 11:01:47 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-16 04:08:26 -0800
commit51e9e69f386366256807e6f4ccdd258821cdcfe0 (patch)
treec6fc8260505edadf8da3e6e0237a7bc6b3906da3 /common/charge_state_v2.c
parentbe1f97a2551549d81f77f0439a23683343234c40 (diff)
downloadchrome-ec-51e9e69f386366256807e6f4ccdd258821cdcfe0.tar.gz
power: introducing pwr_avg console command
pwr_avg provides an average voltage, current, and power over the last 1 minute. It's up to the battery drivers to implement this functionality. This change allows us to have better power tracking while minimizing the power impact on the EC, because - the pwr_avg command only needs to be called once every minute, and is short, thus less expensive to parse on ECs without a UART buffer - the work done to keep the avg is partially done by the batteries already and it's just a question of retrieving it. undefined on wheatley since no power debugging planned on that board. usage: > pwr_avg mv = 7153 ma = -605 mw = -4327 BUG=chromium:752320 BRANCH=None TEST=make buildall -j Change-Id: Id1a3479d277aedf90dfa965afb4ee9136654b1cf Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/823884 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index cc145d6971..75c25d072d 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1556,6 +1556,34 @@ DECLARE_HOST_COMMAND(EC_CMD_CHARGE_STATE, charge_command_charge_state,
/*****************************************************************************/
/* Console commands */
+#ifdef CONFIG_CMD_PWR_AVG
+
+static int command_pwr_avg(int argc, char **argv)
+{
+ int avg_mv;
+ int avg_ma;
+ int avg_mw;
+
+ if (argc != 1)
+ return EC_ERROR_PARAM_COUNT;
+
+ avg_mv = battery_get_avg_voltage();
+ if (avg_mv < 0)
+ return EC_ERROR_UNKNOWN;
+ avg_ma = battery_get_avg_current();
+ avg_mw = avg_mv * avg_ma / 1000;
+
+ ccprintf("mv = %d\nma = %d\nmw = %d\n",
+ avg_mv, avg_ma, avg_mw);
+ return EC_SUCCESS;
+}
+
+DECLARE_CONSOLE_COMMAND(pwr_avg, command_pwr_avg,
+ NULL,
+ "Get 1 min power average");
+
+#endif /* CONFIG_CMD_PWR_AVG */
+
static int command_chgstate(int argc, char **argv)
{
int rv;