summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-10-12 14:27:44 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-05-01 21:16:36 +0000
commit7891e6b60e5b4a7f987e71c51c1160968fac007f (patch)
treef6234c43307b5e068389a3a78e3600cfcb39a4bd
parent16a9abc02c5abe092bb8899166c0a79482d40825 (diff)
downloadchrome-ec-7891e6b60e5b4a7f987e71c51c1160968fac007f.tar.gz
UPSTREAM: 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=smau, cyan, ultima BUG=chrome-os-partner:4381, b:27849483, b:36973851 TEST=Check SingleSensorTests pass. Reviewed-on: https://chromium-review.googlesource.com/305571 Reviewed-by: Alec Berg <alecaberg@chromium.org> (cherry picked from commit 0174b9a21d0764bf32243cf23a3f138bf44e5938) Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/359387 Reviewed-on: https://chromium-review.googlesource.com/409474 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit 9a9a2387cb35e517f59515183c98ab1b324278d9) Change-Id: Ie40ebd9d856abdeeeccf4b636351560bb8a6305c Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/489747
-rw-r--r--common/motion_sense.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 29a0ef8346..6aeb04bc10 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -89,10 +89,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];
@@ -147,7 +143,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)
@@ -236,8 +234,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;
return sensor->drv->set_data_rate(sensor, odr, roundup);
}
@@ -933,6 +932,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);
@@ -941,13 +948,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