diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2016-12-28 14:53:03 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-12-28 21:49:35 -0800 |
commit | 1dce89f8b40349ec4c76e62a7a0d3164d6ec113a (patch) | |
tree | d7b61c12af803ab774a90e98910af5b27b01e69a | |
parent | 03bfb6f78fd978f33faff060ce4e796d0e0880b3 (diff) | |
download | chrome-ec-1dce89f8b40349ec4c76e62a7a0d3164d6ec113a.tar.gz |
motion: Fix last timestamp calculation
last_collection is used for sensor in forced mode to be sure we are not
calling the read routine too often. We should update last_collection even
when the reading fails, and not on the interrupt path.
For sensors that support interrupt, the new timing diagram is:
/-------- data rate period ---------\
--------------+------------------------------------+-----------------> t
| /\
read (sample request) |
| Interrupt (sample available)
\/ |
sensor
BUG=chrome-os-partner:59423
BRANCH=reef
TEST=Check the ALS read is not called too often even when the sensor
reports an error because the read value is not changed.
Change-Id: I2def7bbd5227cf373c1f613c9b70bc6215861008
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/424222
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/motion_sense.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index 6e6c2da1f4..d64cb1055f 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -604,8 +604,6 @@ static int motion_sense_process(struct motion_sensor_t *sensor, if ((*event & TASK_EVENT_MOTION_INTERRUPT_MASK) && (sensor->drv->irq_handler != NULL)) { ret = sensor->drv->irq_handler(sensor, event); - if (ret == EC_SUCCESS) - sensor->last_collection = ts->le.lo; } #endif #ifdef CONFIG_ACCEL_FIFO @@ -622,8 +620,8 @@ static int motion_sense_process(struct motion_sensor_t *sensor, vector.data[Y] = sensor->raw_xyz[Y]; vector.data[Z] = sensor->raw_xyz[Z]; motion_sense_fifo_add_unit(&vector, sensor, 3); - sensor->last_collection = ts->le.lo; } + sensor->last_collection = ts->le.lo; } else { ret = EC_ERROR_BUSY; } @@ -639,11 +637,11 @@ static int motion_sense_process(struct motion_sensor_t *sensor, if (motion_sensor_time_to_read(ts, sensor)) { /* Get latest data for local calculation */ ret = motion_sense_read(sensor); + sensor->last_collection = ts->le.lo; } else { ret = EC_ERROR_BUSY; } if (ret == EC_SUCCESS) { - sensor->last_collection = ts->le.lo; mutex_lock(&g_sensor_mutex); memcpy(sensor->xyz, sensor->raw_xyz, sizeof(sensor->xyz)); mutex_unlock(&g_sensor_mutex); |