@@ -269,7 +269,7 @@ static void fix_single_param(int flag, int *cached, int *curr)
269
269
* cached = * curr ;
270
270
}
271
271
272
- #define CACHE_INVALIDATION_TIME_US (5 * SECOND)
272
+ #define CACHE_INVALIDATION_TIME_US (3 * SECOND)
273
273
274
274
/*
275
275
* f any value in batt_params is bad, replace it with a cached
@@ -282,14 +282,42 @@ __override void board_battery_compensate_params(struct batt_params *batt)
282
282
static timestamp_t deadline ;
283
283
284
284
/*
285
- * If battery keeps failing for 5 seconds, stop hiding the error and
285
+ * If battery keeps failing for 3 seconds, stop hiding the error and
286
286
* report back to host.
287
287
*/
288
- if (batt -> flags & BATT_FLAG_BAD_ANY ) {
289
- if (timestamp_expired (deadline , NULL ))
288
+ if (batt -> flags & BATT_FLAG_RESPONSIVE ) {
289
+ if (batt -> flags & BATT_FLAG_BAD_ANY ) {
290
+ if (timestamp_expired (deadline , NULL ))
291
+ return ;
292
+ } else
293
+ deadline .val = get_time ().val + CACHE_INVALIDATION_TIME_US ;
294
+ } else if (!(batt -> flags & BATT_FLAG_RESPONSIVE )) {
295
+ /**
296
+ * There are 4 situations for battery is not repsonsed
297
+ * 1. Darin battery (first time)
298
+ * 2. Dead battery (first time)
299
+ * 3. No battery (is preset)
300
+ * 4. Others
301
+ */
302
+ /* we don't need to cache the value when battery is not present */
303
+ if (!batt -> is_present ) {
304
+ batt_cache .flags &= ~BATT_FLAG_RESPONSIVE ;
305
+ return ;
306
+ }
307
+
308
+ /* we don't need to cache the value when we read the battery first time*/
309
+ if (!(batt_cache .flags & BATT_FLAG_RESPONSIVE ))
290
310
return ;
291
- } else {
292
- deadline .val = get_time ().val + CACHE_INVALIDATION_TIME_US ;
311
+
312
+ /**
313
+ * If battery keeps no responsing for 3 seconds, stop hiding the error and
314
+ * back to host.
315
+ */
316
+ if (timestamp_expired (deadline , NULL )) {
317
+ batt_cache .flags &= ~BATT_FLAG_RESPONSIVE ;
318
+ return ;
319
+ }
320
+
293
321
}
294
322
295
323
/* return cached values for at most CACHE_INVALIDATION_TIME_US */
@@ -330,6 +358,8 @@ __override void board_battery_compensate_params(struct batt_params *batt)
330
358
331
359
/* remove bad flags after applying cached values */
332
360
batt -> flags &= ~BATT_FLAG_BAD_ANY ;
361
+ batt -> flags |= BATT_FLAG_RESPONSIVE ;
362
+ batt_cache .flags |= BATT_FLAG_RESPONSIVE ;
333
363
}
334
364
335
365
/*****************************************************************************/
0 commit comments