summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2019-01-15 15:53:19 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-01-17 20:20:49 -0800
commit9f78744fd33837a86bd4c1046fd77bd9847ffd8f (patch)
treedc981419637a2c42afbbe410dbb8297ff2ec8480
parenta1bb29e2dfc756e3a9d01956dabf9bfa9030299d (diff)
downloadchrome-ec-9f78744fd33837a86bd4c1046fd77bd9847ffd8f.tar.gz
LSM6: Correct timestamp reporting and FIFO length
When an accelerometer sends a sample to the motion_sense task with a timestamp, the timestamp should represent the time of the IRQ which caused the FIFO read. This change caches a timestamp after the accelerometer data is read to use when pushing all data from that read. This also corrects the number of bits in the FIFO length field. BRANCH=octopus BUG=b:120679547 TEST=builds, phaser360 CTS pass rate unaffected Change-Id: I220aa2e8fa23af3f7833999cdfac966e8695c831 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1413670 Reviewed-by: Alexandru M Stan <amstan@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--driver/accelgyro_lsm6dsm.c18
-rw-r--r--driver/accelgyro_lsm6dsm.h2
2 files changed, 12 insertions, 8 deletions
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index 7a445dc0c7..7f9ac5b983 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -21,7 +21,7 @@
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
#ifdef CONFIG_ACCEL_FIFO
-static uint32_t last_interrupt_timestamp;
+static volatile uint32_t last_interrupt_timestamp;
#endif
/**
@@ -198,7 +198,7 @@ static int fifo_next(struct lsm6dsm_data *private)
* push_fifo_data - Scan data pattern and push upside
*/
static void push_fifo_data(struct motion_sensor_t *accel, uint8_t *fifo,
- uint16_t flen)
+ uint16_t flen, uint32_t int_ts)
{
struct lsm6dsm_data *private = accel->drv_data;
/* In FIFO sensors are mapped in a different way. */
@@ -232,8 +232,7 @@ static void push_fifo_data(struct motion_sensor_t *accel, uint8_t *fifo,
vect.flags = 0;
vect.sensor_num = accel - motion_sensors + id;
- motion_sense_fifo_add_data(&vect, accel + id, 3,
- last_interrupt_timestamp);
+ motion_sense_fifo_add_data(&vect, accel + id, 3, int_ts);
fifo += OUT_XYZ_SIZE;
flen -= OUT_XYZ_SIZE;
@@ -246,7 +245,7 @@ static int load_fifo(struct motion_sensor_t *s, const struct fstatus *fsts)
uint8_t fifo[FIFO_READ_LEN];
/*
- * DIFF[9:0] are number of unread uint16 in FIFO
+ * DIFF[11:0] are number of unread uint16 in FIFO
* mask DIFF and compute total byte len to read from FIFO.
*/
left = fsts->len & LSM6DSM_FIFO_DIFF_MASK;
@@ -268,8 +267,13 @@ static int load_fifo(struct motion_sensor_t *s, const struct fstatus *fsts)
if (err != EC_SUCCESS)
return err;
- /* Manage patterns and push data. */
- push_fifo_data(s, fifo, length);
+ /*
+ * Manage patterns and push data. Data should be pushed with the
+ * timestamp of the last IRQ before the FIFO was read, so make a
+ * copy of the current time in case another interrupt comes in
+ * during processing.
+ */
+ push_fifo_data(s, fifo, length, last_interrupt_timestamp);
left -= length;
} while (left > 0);
diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h
index 763260894b..72c21fa5f3 100644
--- a/driver/accelgyro_lsm6dsm.h
+++ b/driver/accelgyro_lsm6dsm.h
@@ -93,7 +93,7 @@
#define LSM6DSM_FIFO_STS1_ADDR 0x3a
#define LSM6DSM_FIFO_STS2_ADDR 0x3b
-#define LSM6DSM_FIFO_DIFF_MASK 0x07ff
+#define LSM6DSM_FIFO_DIFF_MASK 0x0fff
#define LSM6DSM_FIFO_EMPTY 0x1000
#define LSM6DSM_FIFO_FULL 0x2000
#define LSM6DSM_FIFO_DATA_OVR 0x4000