summaryrefslogtreecommitdiff
path: root/driver/accelgyro_bmi160.c
diff options
context:
space:
mode:
authorAlexandru M Stan <amstan@chromium.org>2017-12-04 19:44:42 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-03-14 04:06:52 -0700
commitb63595258df33b0c31effe979feb4bfe884cc9fb (patch)
tree3de3e0bf2293c177bf4103cebffde756b1f78b02 /driver/accelgyro_bmi160.c
parente74d21f5bdf7f05f13a3b6d496fe37235cb4fdef (diff)
downloadchrome-ec-b63595258df33b0c31effe979feb4bfe884cc9fb.tar.gz
motion: Lower jitter of Sensor->EC timestamp
Instead getting the time for each sample in the task code, we should be getting it as soon as the sensor reported it added it to its fifo (so sensor just finished integration). Because of that each sensor should provide the time when it provides a sample, ideally from an accurate spot like an interrupt. Deprecate motion_sense_fifo_add_unit (without a timestamp) in favour of motion_sense_fifo_add_data (which adds the timestamps). Update all relevant sensors to use the new api. Note: for now I focused on the BMI160, where I actually made it get the time in the interrupt. The other sensors were made to use the new api, but still don't record the time in the right place (though it's not any worse than before). BUG=b:67743747 TEST=In the kernel, fifo_info->info.timestamp still has sane values. TEST=CTS should still pass BRANCH=master Change-Id: I9829343f8702e00cc19f9c88134fa1f258c9e1e9 Signed-off-by: Alexandru M Stan <amstan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/807331 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'driver/accelgyro_bmi160.c')
-rw-r--r--driver/accelgyro_bmi160.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index 384357bf29..72b8b2a902 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -14,6 +14,7 @@
#include "driver/accelgyro_bmi160.h"
#include "driver/mag_bmm150.h"
#include "hooks.h"
+#include "hwtimer.h"
#include "i2c.h"
#include "math_util.h"
#include "spi.h"
@@ -25,6 +26,10 @@
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
+#ifdef CONFIG_ACCEL_FIFO
+static uint32_t last_interrupt_timestamp;
+#endif
+
/*
* Struct for pairing an engineering value with the register value for a
* parameter.
@@ -820,7 +825,8 @@ static int bmi160_decode_header(struct motion_sensor_t *s,
vector.data[Y] = v[Y];
vector.data[Z] = v[Z];
vector.sensor_num = i + (s - motion_sensors);
- motion_sense_fifo_add_unit(&vector, s + i, 3);
+ motion_sense_fifo_add_data(&vector, s + i, 3,
+ last_interrupt_timestamp);
*bp += (i == MOTIONSENSE_TYPE_MAG ? 8 : 6);
}
}
@@ -955,6 +961,9 @@ static int load_fifo(struct motion_sensor_t *s)
*/
void bmi160_interrupt(enum gpio_signal signal)
{
+#ifdef CONFIG_ACCEL_FIFO
+ last_interrupt_timestamp = __hw_clock_source_read();
+#endif
task_set_event(TASK_ID_MOTIONSENSE,
CONFIG_ACCELGYRO_BMI160_INT_EVENT, 0);
}