diff options
-rw-r--r-- | driver/accelgyro_bmi160.c | 17 | ||||
-rw-r--r-- | include/driver/accelgyro_bmi160.h | 21 | ||||
-rw-r--r-- | include/driver/accelgyro_bmi260.h | 20 | ||||
-rw-r--r-- | zephyr/test/drivers/src/bmi160.c | 27 |
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); } |