summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-11-04 16:57:54 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-09 21:29:49 +0000
commitc5b31809cb024e89f51555943d34197ceb1640f1 (patch)
tree240eaed46671786edeef49780d9b1a67ef6c69a7
parent998bd68a7d018e4b610805e1b365eedecc425bbf (diff)
downloadchrome-ec-c5b31809cb024e89f51555943d34197ceb1640f1.tar.gz
zephyr: bmi160: Test interrupt handler and bug fix
Test the interrupt handler in the BMI160 driver. Also, correct an error from an earlier CL (3229647) where I moved the BMI260 event flag in to BMI160 driver's header. BRANCH=None BUG=b:184856157 TEST=zmake -D configure --test test-drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Icb08d9e1142066ba0ef22b9633895e60e6b40e90 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262878 Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--driver/accelgyro_bmi160.c17
-rw-r--r--include/driver/accelgyro_bmi160.h21
-rw-r--r--include/driver/accelgyro_bmi260.h20
-rw-r--r--zephyr/test/drivers/src/bmi160.c27
4 files changed, 55 insertions, 30 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index ebcb6f71dc..08bd7a0445 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -28,23 +28,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 motion sensor ID of the BMI160 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 an alias (bmi160_int) to get the motion sensor ID. This alias
- * MUST be defined for this driver to work.
- * aliases {
- * bmi160-int = &base_accel;
- * };
- */
-#if DT_NODE_EXISTS(DT_ALIAS(bmi160_int))
-#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
- TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi160_int)))
-#endif
-#endif
-
STATIC_IF(CONFIG_BMI_ORIENTATION_SENSOR) void irq_set_orientation(
struct motion_sensor_t *s,
int interrupt);
diff --git a/include/driver/accelgyro_bmi160.h b/include/driver/accelgyro_bmi160.h
index 8b050227bc..76d24936c6 100644
--- a/include/driver/accelgyro_bmi160.h
+++ b/include/driver/accelgyro_bmi160.h
@@ -390,22 +390,19 @@ int bmi160_sec_raw_write8(const int port, const uint16_t addr_flags,
const uint8_t reg, int data);
#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
+/* Get the motion sensor ID of the BMI160 sensor that generates the interrupt.
+ * The interrupt is converted to the event and transferred to motion sense task
+ * that actually handles the interrupt.
*
- * e.g) base_accel is the label of a child node in /motionsense-sensors
+ * Here we use an alias (bmi160_int) to get the motion sensor ID. This alias
+ * MUST be defined for this driver to work.
* aliases {
- * bmi260-int = &base_accel;
+ * bmi160-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)))
+#if DT_NODE_EXISTS(DT_ALIAS(bmi160_int))
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi160_int)))
#endif
#endif
diff --git a/include/driver/accelgyro_bmi260.h b/include/driver/accelgyro_bmi260.h
index e59870a93e..ae1c0f5777 100644
--- a/include/driver/accelgyro_bmi260.h
+++ b/include/driver/accelgyro_bmi260.h
@@ -328,4 +328,24 @@
/* Root mean square noise of 100Hz accelerometer, units: ug */
#define BMI260_ACCEL_RMS_NOISE_100HZ 1060
+#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS)
+/*
+ * Get the motion 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_BMI260_H */
diff --git a/zephyr/test/drivers/src/bmi160.c b/zephyr/test/drivers/src/bmi160.c
index 8678e34093..dca9d5bf30 100644
--- a/zephyr/test/drivers/src/bmi160.c
+++ b/zephyr/test/drivers/src/bmi160.c
@@ -1989,6 +1989,30 @@ static void test_bmi_temp_sensor(void)
EC_ERROR_NOT_POWERED, ret);
}
+static void test_bmi_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_BMI160_INT_EVENT) == 0,
+ "Event flag is set before firing interrupt");
+
+ bmi160_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_BMI160_INT_EVENT,
+ "Event flag is not set after firing interrupt");
+}
+
void test_suite_bmi160(void)
{
ztest_test_suite(bmi160,
@@ -2015,6 +2039,7 @@ void test_suite_bmi160(void)
ztest_user_unit_test(test_bmi_set_offset_invalid_type),
ztest_user_unit_test(
test_bmi_perform_calib_invalid_type),
- ztest_user_unit_test(test_bmi_temp_sensor));
+ ztest_user_unit_test(test_bmi_temp_sensor),
+ ztest_user_unit_test(test_bmi_interrupt_handler));
ztest_run_test_suite(bmi160);
}