summaryrefslogtreecommitdiff
path: root/test/motion_sense_fifo.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2022-09-16 21:13:50 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-28 00:27:11 +0000
commitff96cd3447b12ed965bd28602407b18a9986de25 (patch)
tree3712c69feccea8c86d6f088e21d5264ac5155723 /test/motion_sense_fifo.c
parenta87d4151f52be9edda706cc587826ca6d126f688 (diff)
downloadchrome-ec-ff96cd3447b12ed965bd28602407b18a9986de25.tar.gz
motion_sense: Trigger AP interrupt based on sensor timestamp
Currently, interrupt trigering is based on the time when the motion sensor task is scheduled. If the task is delayed for processing a first sample but not a second one, the second sample will be delayed until the third sample arrive: / sensor interrupt / sensor interrupt / sensor int | / task scheduling| / task scheduling | / task +-delay-+----------------+-+--------------------+-+ <--------- 10 ms --------X------------ 10 ms -----> <------- < 10 ms ----> event delayed until the next sample. To address the issue: 1 - add more leeway to schedule the interrupt. Instead of 3us, allow to trigger an interrupt if the delta between samples is more than the expect delta minus 1ms. 2 - Use the sensor timestamp provided to the FIFO, keep sensor timestamp for every sensor. When the timestamp difference is larger than the requested rate, we schedule an interrupt. Fixes: 0c71c474869 ("motion sense: Calculate loop time based on sensor needs") BUG=b:242263033 BRANCH=none TEST=Ran "tast run localhost:22552 hardware.SensorIioserviceHard" Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: I9ccf08c1180820e699cf84069df3e4541768988d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3966709 Reviewed-by: Yuval Peress <peress@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Diffstat (limited to 'test/motion_sense_fifo.c')
-rw-r--r--test/motion_sense_fifo.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/motion_sense_fifo.c b/test/motion_sense_fifo.c
index c93e67951b..5a977e94d0 100644
--- a/test/motion_sense_fifo.c
+++ b/test/motion_sense_fifo.c
@@ -417,6 +417,79 @@ static int test_get_info_size(void)
return EC_SUCCESS;
}
+static int test_check_ap_interval_set_one_sample(void)
+{
+ uint32_t now;
+ int read_count;
+
+ /* The AP needs data every sample (200 Hz). */
+ motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 5000; /* us */
+ motion_sensors[0].oversampling_ratio = 1;
+ motion_sense_set_data_period(0, 5000 /* us */);
+ msleep(5);
+ now = __hw_clock_source_read();
+
+ motion_sense_fifo_stage_data(data, motion_sensors, 3, now);
+ motion_sense_fifo_commit_data();
+ read_count = motion_sense_fifo_read(
+ sizeof(data), CONFIG_ACCEL_FIFO_SIZE, data, &data_bytes_read);
+ TEST_EQ(read_count, 2, "%d");
+ TEST_BITS_SET(data[0].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP);
+ TEST_EQ(data[0].timestamp, now, "%u");
+ TEST_EQ(motion_sense_fifo_interrupt_needed(), 1, "%d");
+
+ /* Simulate interrupt processing. */
+ motion_sense_fifo_reset_needed_flags();
+
+ msleep(5);
+ now = __hw_clock_source_read();
+ motion_sense_fifo_stage_data(data, motion_sensors, 3, now);
+ motion_sense_fifo_commit_data();
+ read_count = motion_sense_fifo_read(
+ sizeof(data), CONFIG_ACCEL_FIFO_SIZE, data, &data_bytes_read);
+ TEST_EQ(read_count, 2, "%d");
+ TEST_BITS_SET(data[0].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP);
+ TEST_EQ(data[0].timestamp, now, "%u");
+ TEST_EQ(motion_sense_fifo_interrupt_needed(), 1, "%d");
+
+ return EC_SUCCESS;
+}
+
+static int test_check_ap_interval_set_multiple_sample(void)
+{
+ uint32_t now;
+ int read_count;
+
+ /* The AP needs data every 2 samples. */
+ motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 10000; /* us */
+ motion_sensors[0].oversampling_ratio = 1;
+ motion_sense_set_data_period(0, 5000 /* us */);
+ msleep(5);
+ now = __hw_clock_source_read();
+
+ motion_sense_fifo_stage_data(data, motion_sensors, 3, now);
+ motion_sense_fifo_commit_data();
+ read_count = motion_sense_fifo_read(
+ sizeof(data), CONFIG_ACCEL_FIFO_SIZE, data, &data_bytes_read);
+ TEST_EQ(read_count, 2, "%d");
+ TEST_BITS_SET(data[0].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP);
+ TEST_EQ(data[0].timestamp, now, "%u");
+ TEST_EQ(motion_sense_fifo_interrupt_needed(), 0, "%d");
+
+ msleep(5);
+ now = __hw_clock_source_read();
+ motion_sense_fifo_stage_data(data, motion_sensors, 3, now);
+ motion_sense_fifo_commit_data();
+ read_count = motion_sense_fifo_read(
+ sizeof(data), CONFIG_ACCEL_FIFO_SIZE, data, &data_bytes_read);
+ TEST_EQ(read_count, 2, "%d");
+ TEST_BITS_SET(data[0].flags, MOTIONSENSE_SENSOR_FLAG_TIMESTAMP);
+ TEST_EQ(data[0].timestamp, now, "%u");
+ TEST_EQ(motion_sense_fifo_interrupt_needed(), 1, "%d");
+
+ return EC_SUCCESS;
+}
+
void before_test(void)
{
motion_sense_fifo_commit_data();
@@ -447,6 +520,8 @@ void run_test(int argc, const char **argv)
RUN_TEST(test_spread_data_by_collection_rate);
RUN_TEST(test_commit_non_data_or_timestamp_entries);
RUN_TEST(test_get_info_size);
+ RUN_TEST(test_check_ap_interval_set_one_sample);
+ RUN_TEST(test_check_ap_interval_set_multiple_sample);
test_print_result();
}