From 835de3afde0bf99a1d105667109a21e3a91c73d1 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Fri, 20 Nov 2015 10:17:09 -0800 Subject: motion: Fix the number of sample to collect in motion task AP could collect samples while motion task was still adding timestamp. A data stream not ending with a timestamp can lead to timestamp error in the kernel. This is espcially true if the motion task interrupt the AP back to back, when sensor ODR changes for instance. BRANCH=smaug BUG=b:24367625 TEST=Run android.hardware.cts.SingleSensorTests Change-Id: I5820216a2cfc0a869db7dc5ef75d4be126a53b4f Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/313640 Reviewed-by: Alec Berg (cherry picked from commit 708f81e3d1d222270c697b5643760b1ca361b9f9) Reviewed-on: https://chromium-review.googlesource.com/313738 --- common/motion_sense.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/motion_sense.c b/common/motion_sense.c index 0c6e461995..4854607482 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -78,6 +78,8 @@ static int wake_up_needed; /* Need to send flush events */ static int fifo_flush_needed; +/* Number of element the AP should collect */ +static int fifo_queue_count; struct queue motion_sense_fifo = QUEUE_NULL(CONFIG_ACCEL_FIFO, struct ec_response_motion_sensor_data); @@ -155,7 +157,7 @@ static void motion_sense_get_fifo_info( { fifo_info->size = motion_sense_fifo.buffer_units; mutex_lock(&g_sensor_mutex); - fifo_info->count = queue_count(&motion_sense_fifo); + fifo_info->count = fifo_queue_count; fifo_info->total_lost = motion_sense_fifo_lost; mutex_unlock(&g_sensor_mutex); fifo_info->timestamp = __hw_clock_source_read(); @@ -790,6 +792,13 @@ void motion_sense_task(void) motion_sense_insert_timestamp(); fifo_flush_needed = 0; ts_last_int = ts_end_task; + /* + * Count the number of event the AP is allowed to + * collect. + */ + mutex_lock(&g_sensor_mutex); + fifo_queue_count = queue_count(&motion_sense_fifo); + mutex_unlock(&g_sensor_mutex); #ifdef CONFIG_MKBP_EVENT /* * We don't currently support wake up sensor. -- cgit v1.2.1