From 1b82905cfe66ae472cdb42f0e17c2ec94aa466c3 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Thu, 21 Aug 2014 15:37:23 -0700 Subject: Add hysteresis to host events for battery capacity changed Adds a small threshold for sending a host event to battery whenever the full capacity changes. This helps avoid constant host events when the battery decides the capacity is going back and forth 1mAh BUG=none BRANCH=none TEST=load on samus. set LFCC_EVENT_THRESHOLD to 1 and see host events very often. set LFCC_EVENT_THRESHOLD to 5 and see no host events. Change-Id: I2dc38f04e1a634539837dfed19b10ccfcfd0a8a3 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/213668 Reviewed-by: Bill Richardson --- common/charge_state_v2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index f51a03f185..ea196b8f28 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -29,6 +29,7 @@ #define LOW_BATTERY_SHUTDOWN_TIMEOUT_US (LOW_BATTERY_SHUTDOWN_TIMEOUT * SECOND) #define PRECHARGE_TIMEOUT_US (PRECHARGE_TIMEOUT * SECOND) +#define LFCC_EVENT_THRESH 5 /* Full-capacity change reqd for host event */ /* * State for charger_task(). Here so we can reset it on a HOOK_INIT, and @@ -187,7 +188,8 @@ static void update_dynamic_battery_info(void) cap_changed = 0; if (!(curr.batt.flags & BATT_FLAG_BAD_FULL_CAPACITY) && - curr.batt.full_capacity != *memmap_lfcc) { + (curr.batt.full_capacity <= (*memmap_lfcc - LFCC_EVENT_THRESH) || + curr.batt.full_capacity >= (*memmap_lfcc + LFCC_EVENT_THRESH))) { *memmap_lfcc = curr.batt.full_capacity; cap_changed = 1; } -- cgit v1.2.1