diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-10-12 14:27:44 -0700 |
---|---|---|
committer | ChromeOS bot <3su6n15k.default@developer.gserviceaccount.com> | 2015-10-16 02:57:40 +0000 |
commit | 11efd0a567928b5e1bad280b3ba0122d5876ead6 (patch) | |
tree | 38f16a1f20cdc17440f74f4aaf662cc60d62ffa0 | |
parent | 45179e9aefced99c145b6c7d8384d8a32850bc81 (diff) | |
download | chrome-ec-11efd0a567928b5e1bad280b3ba0122d5876ead6.tar.gz |
motion: Add timestamp in ODR
Before setting a new frequency, put a timestamp in the FIFO.
In case there was a long silence, the sample timestamp will be anchored
on that timestamp instead of the last timestamp the AP collected.
BRANCH=smaug
BUG=chrome-os-partner:43811
TEST=Check SingleSensorTests pass.
Change-Id: Ie40ebd9d856abdeeeccf4b636351560bb8a6305c
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/305571
Reviewed-by: Alec Berg <alecaberg@chromium.org>
(cherry picked from commit 0174b9a21d0764bf32243cf23a3f138bf44e5938)
Reviewed-on: https://chromium-review.googlesource.com/306373
-rw-r--r-- | common/motion_sense.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index 2a8dd29d4d..46a9045762 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -83,10 +83,6 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data, queue_remove_unit(&motion_sense_fifo, &vector); motion_sense_fifo_lost++; motion_sensors[vector.sensor_num].lost++; - if (vector.flags) - CPRINTS("Lost important event (0x%02x) for sensor %d", - vector.flags, - vector.sensor_num); } for (i = 0; i < valid_data; i++) sensor->xyz[i] = data->data[i]; @@ -141,7 +137,9 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data, motion_sense_insert_timestamp(); wake_up_needed = 1; } + mutex_lock(&g_sensor_mutex); queue_add_unit(&motion_sense_fifo, data); + mutex_unlock(&g_sensor_mutex); } static void motion_sense_insert_flush(struct motion_sensor_t *sensor) @@ -231,8 +229,9 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor) else config_id = SENSOR_CONFIG_AP; roundup = !!(sensor->config[config_id].odr & ROUND_UP_FLAG); - CPRINTS("%s ODR: %d - roundup %d from config %d", - sensor->name, odr, roundup, config_id); + CPRINTS("%s ODR: %d - roundup %d from config %d [AP %d]", + sensor->name, odr, roundup, config_id, + BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr)); sensor->oversampling = 0; /* * Reset last collection: the last collection may be so much in the past @@ -932,6 +931,14 @@ 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); @@ -940,13 +947,14 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args) if (ret != EC_SUCCESS) return EC_RES_INVALID_PARAM; +#ifdef CONFIG_ACCEL_FIFO /* - * To be sure timestamps are calculated properly, - * Send an event to have a timestamp inserted in the - * 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 |