diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2018-09-04 10:33:21 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-10-04 22:25:54 +0000 |
commit | 4f97fff8a0604a7ee5cdb23ff9365f0ac37bcbd9 (patch) | |
tree | 8c179d5bfc522ca18474fecb1a9bc4b4a191ffc1 /common/motion_sense.c | |
parent | e4eea88b3c24058a380a3acbfaf33fc0a1a96ee9 (diff) | |
download | chrome-ec-4f97fff8a0604a7ee5cdb23ff9365f0ac37bcbd9.tar.gz |
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 <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1204692
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit f62f2ebbecb131956a5edc4bf60c094bc67972a1)
Reviewed-on: https://chromium-review.googlesource.com/c/1259383
Reviewed-by: Philip Chen <philipchen@chromium.org>
Commit-Queue: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Trybot-Ready: Philip Chen <philipchen@chromium.org>
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r-- | common/motion_sense.c | 36 |
1 files changed, 11 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)); |