summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-10-18 16:22:17 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-19 21:26:29 +0000
commitfb7facda70d06efb0b9337ba8a8ed0834019a12a (patch)
treebf613809b09b9b6c21b415dcd0e16139ee2801b5
parent81e812f8a091217a7fedcf5cf88f33b462889af1 (diff)
downloadchrome-ec-fb7facda70d06efb0b9337ba8a8ed0834019a12a.tar.gz
zephyr: Test BMI260 interrupt handler
Quick test of the interrupt handler in accelgyro_bmi260.c that verifies the event flags get set properly. Also moved the definition of CONFIG_ACCELGYRO_BMI260_INT_EVENT in to the corresponding header file so we can access that value in the test. BRANCH=None BUG=b:184856157 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ibf88aee12f661a7883d1fffb6b3a6d53b79289db Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3229647 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--driver/accelgyro_bmi260.c20
-rw-r--r--include/driver/accelgyro_bmi160.h20
-rw-r--r--zephyr/test/drivers/src/bmi260.c27
3 files changed, 46 insertions, 21 deletions
diff --git a/driver/accelgyro_bmi260.c b/driver/accelgyro_bmi260.c
index fe0bf0e0cc..70672b3517 100644
--- a/driver/accelgyro_bmi260.c
+++ b/driver/accelgyro_bmi260.c
@@ -37,26 +37,6 @@
#define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args)
#define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args)
-#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS)
-/*
- * Get the mostion sensor ID of the BMI260 sensor that
- * generates the interrupt.
- * The interrupt is converted to the event and transferred to motion
- * sense task that actually handles the interrupt.
- *
- * Here, we use alias to get the motion sensor ID
- *
- * e.g) base_accel is the label of a child node in /motionsense-sensors
- * aliases {
- * bmi260-int = &base_accel;
- * };
- */
-#if DT_NODE_EXISTS(DT_ALIAS(bmi260_int))
-#define CONFIG_ACCELGYRO_BMI260_INT_EVENT \
- TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi260_int)))
-#endif
-#endif
-
STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp;
/*
diff --git a/include/driver/accelgyro_bmi160.h b/include/driver/accelgyro_bmi160.h
index c916576130..d1b5253023 100644
--- a/include/driver/accelgyro_bmi160.h
+++ b/include/driver/accelgyro_bmi160.h
@@ -391,4 +391,24 @@ int bmi160_sec_raw_write8(const int port, const uint16_t addr_flags,
const uint8_t reg, int data);
#endif
+#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS)
+/*
+ * Get the mostion sensor ID of the BMI260 sensor that
+ * generates the interrupt.
+ * The interrupt is converted to the event and transferred to motion
+ * sense task that actually handles the interrupt.
+ *
+ * Here, we use alias to get the motion sensor ID
+ *
+ * e.g) base_accel is the label of a child node in /motionsense-sensors
+ * aliases {
+ * bmi260-int = &base_accel;
+ * };
+ */
+#if DT_NODE_EXISTS(DT_ALIAS(bmi260_int))
+#define CONFIG_ACCELGYRO_BMI260_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi260_int)))
+#endif
+#endif
+
#endif /* __CROS_EC_ACCELGYRO_BMI160_H */
diff --git a/zephyr/test/drivers/src/bmi260.c b/zephyr/test/drivers/src/bmi260.c
index 964a83d678..9c703746e2 100644
--- a/zephyr/test/drivers/src/bmi260.c
+++ b/zephyr/test/drivers/src/bmi260.c
@@ -1891,6 +1891,30 @@ static void test_unsupported_configs(void)
EC_RES_INVALID_PARAM, ret);
}
+void test_interrupt_handler(void)
+{
+ /* The accelerometer interrupt handler simply sets an event flag for the
+ * motion sensing task. Make sure that flag starts cleared, fire the
+ * interrupt, and ensure the flag is set.
+ */
+
+ uint32_t *mask;
+
+ mask = task_get_event_bitmap(TASK_ID_MOTIONSENSE);
+ zassert_true(mask != NULL,
+ "Got a null pointer when getting event bitmap.");
+ zassert_true((*mask & CONFIG_ACCELGYRO_BMI260_INT_EVENT) == 0,
+ "Event flag is set before firing interrupt");
+
+ bmi260_interrupt(0);
+
+ mask = task_get_event_bitmap(TASK_ID_MOTIONSENSE);
+ zassert_true(mask != NULL,
+ "Got a null pointer when getting event bitmap.");
+ zassert_true(*mask & CONFIG_ACCELGYRO_BMI260_INT_EVENT,
+ "Event flag is not set after firing interrupt");
+}
+
void test_suite_bmi260(void)
{
ztest_test_suite(bmi260,
@@ -1912,6 +1936,7 @@ void test_suite_bmi260(void)
ztest_user_unit_test(test_bmi_init),
ztest_user_unit_test(test_bmi_acc_fifo),
ztest_user_unit_test(test_bmi_gyr_fifo),
- ztest_user_unit_test(test_unsupported_configs));
+ ztest_user_unit_test(test_unsupported_configs),
+ ztest_user_unit_test(test_interrupt_handler));
ztest_run_test_suite(bmi260);
}