From 4f97fff8a0604a7ee5cdb23ff9365f0ac37bcbd9 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 4 Sep 2018 10:33:21 -0700 Subject: motion: Change ODR only within the motion sensor task When changing ODR for one sensor, we insert a timestamp in the FIFO. That timestamp can be misinterpreted by other sensor while in batch mode, condensing all events in a small timezone. Also, it can lead the motionsense stack to insert timestamp from the past. BUG=b:111422556,chromium:562245 TEST=Check cheets_CTS_P.9.0_r2.x86.CtsSensorTestCases pass on eve. BRANCH=eve Change-Id: If76aa3abcedbe463321ccbb1c183dc16edda8693 Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/1204692 Reviewed-by: Aseda Aboagye (cherry picked from commit f62f2ebbecb131956a5edc4bf60c094bc67972a1) Reviewed-on: https://chromium-review.googlesource.com/c/1259383 Reviewed-by: Philip Chen Commit-Queue: Philip Chen Tested-by: Philip Chen Trybot-Ready: Philip Chen --- common/motion_sense.c | 36 +++++++++++------------------------- include/motion_sense.h | 3 +++ 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/common/motion_sense.c b/common/motion_sense.c index 7fd71b875e..37f9eaa7a8 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -750,6 +750,13 @@ static int motion_sense_process(struct motion_sensor_t *sensor, } #endif + + /* ODR change was requested. */ + if ((*event & TASK_EVENT_MOTION_ODR_CHANGE) && + atomic_read_clear(&sensor->new_odr)) { + motion_sense_set_data_rate(sensor); + motion_sense_set_motion_intervals(); + } return ret; } @@ -1174,36 +1181,18 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) /* Set new data rate if the data arg has a value. */ if (in->sensor_odr.data != EC_MOTION_SENSE_NO_VALUE) { -#ifdef CONFIG_ACCEL_FIFO - /* - * To be sure timestamps are calculated properly, - * Send an event to have a timestamp inserted in the - * FIFO. - */ - motion_sense_insert_timestamp(); -#endif sensor->config[SENSOR_CONFIG_AP].odr = in->sensor_odr.data | (in->sensor_odr.roundup ? ROUND_UP_FLAG : 0); - ret = motion_sense_set_data_rate(sensor); - if (ret != EC_SUCCESS) - return EC_RES_INVALID_PARAM; + atomic_add(&sensor->new_odr, 1); -#ifdef CONFIG_ACCEL_FIFO /* * The new ODR may suspend sensor, leaving samples * in the FIFO. Flush it explicitly. */ task_set_event(TASK_ID_MOTIONSENSE, TASK_EVENT_MOTION_ODR_CHANGE, 0); -#endif - /* - * If the sensor was suspended before, or now - * suspended, we have to recalculate the EC sampling - * rate - */ - motion_sense_set_motion_intervals(); } out->sensor_odr.ret = sensor->drv->get_data_rate(sensor); @@ -1553,7 +1542,7 @@ DECLARE_CONSOLE_COMMAND(accelres, command_accelresolution, static int command_accel_data_rate(int argc, char **argv) { char *e; - int id, data, round = 1, ret; + int id, data, round = 1; struct motion_sensor_t *sensor; enum sensor_config config_id; @@ -1589,11 +1578,8 @@ static int command_accel_data_rate(int argc, char **argv) sensor->config[SENSOR_CONFIG_AP].odr = 0; sensor->config[config_id].odr = data | (round ? ROUND_UP_FLAG : 0); - ret = motion_sense_set_data_rate(sensor); - if (ret) - return EC_ERROR_PARAM2; - /* Sensor might be out of suspend, check the ec_rate */ - motion_sense_set_motion_intervals(); + task_set_event(TASK_ID_MOTIONSENSE, + TASK_EVENT_MOTION_ODR_CHANGE, 0); } else { ccprintf("Data rate for sensor %d: %d\n", id, sensor->drv->get_data_rate(sensor)); diff --git a/include/motion_sense.h b/include/motion_sense.h index 9d727a62de..7b574e37f7 100644 --- a/include/motion_sense.h +++ b/include/motion_sense.h @@ -125,6 +125,9 @@ struct motion_sensor_t { /* How many flush events are pending */ uint32_t flush_pending; + /* new ODR pending */ + uint32_t new_odr; + /* * Allow EC to request an higher frequency for the sensors than the AP. * We will downsample according to oversampling_ratio, or ignore the -- cgit v1.2.1