From 5faadc6748d556375c1effd56dac226f2a773ad1 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Fri, 7 Aug 2015 22:44:57 -0700 Subject: [PATCH] motion_sense: Force flush when sensor disabled. When sensor is disabled, HAL will not send flush request to EC. However, when sensor is reenabled, only new events are expected. When we have a change in frequency, we have to request the host to query all the current events. Flush the FIFO when events are not needed because all sensors are disabled. BRANCH=smaug TEST=Pass more tests: tests like ..._fastest_batching after _50hz_flush have more change to pass. BUG=chrome-os-partner:39900 Change-Id: I1a8fc3784e3e6be260b23103b28e336e242f14cd Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/291991 Reviewed-by: Sheng-liang Song --- common/motion_sense.c | 8 +------- driver/accelgyro_bmi160.c | 10 +++++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/common/motion_sense.c b/common/motion_sense.c index 4855a68d93..4e7f63ea83 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -505,13 +505,6 @@ void motion_sense_task(void) ts_end_task = get_time(); #ifdef CONFIG_ACCEL_FIFO - /* - * If ODR of any sensor changed, insert a timestamp to be ease - * calculation of each events. - */ - if (event & TASK_EVENT_MOTION_ODR_CHANGE) - motion_sense_insert_timestamp(); - /* * Ask the host to flush the queue if * - a flush event has been queued. @@ -519,6 +512,7 @@ void motion_sense_task(void) * - we haven't done it for a while. */ if (fifo_flush_needed || + event & TASK_EVENT_MOTION_ODR_CHANGE || queue_space(&motion_sense_fifo) < CONFIG_ACCEL_FIFO_THRES || (ts_end_task.val - ts_last_int.val) > accel_interval) { if (!fifo_flush_needed) diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index 3afa3e6bd7..e2b6daddeb 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -797,8 +797,16 @@ static int load_fifo(struct motion_sensor_t *s) if (s->type != MOTIONSENSE_TYPE_ACCEL) return EC_SUCCESS; - if (!(data->flags & (BMI160_FIFO_ALL_MASK << BMI160_FIFO_FLAG_OFFSET))) + if (!(data->flags & + (BMI160_FIFO_ALL_MASK << BMI160_FIFO_FLAG_OFFSET))) { + /* + * Flush potiential left over: + * + * When sensor is resumed, we don't want to read old data. + */ + raw_write8(s->addr, BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH); return EC_SUCCESS; + } do { enum fifo_state state = FIFO_HEADER;