From 29f034c53e1f187d99edfc07908fe94defe7d0ac Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Mon, 14 Jan 2019 07:59:36 -0700 Subject: [PATCH] mpu9250 fix hardfaults if attempting to start an already running driver (#11190) * removed bus options that were essentially duplicates, causing hardfaults if attempting to start an already running driver. Changed NULL to nullptr. Removed bus options that were unused * removed condition from if statement that was unnecessary * fixed style --- src/drivers/imu/mpu9250/main.cpp | 51 ++++++++------------------------ 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/src/drivers/imu/mpu9250/main.cpp b/src/drivers/imu/mpu9250/main.cpp index f508b2fb747b..7cd2845fd8a5 100644 --- a/src/drivers/imu/mpu9250/main.cpp +++ b/src/drivers/imu/mpu9250/main.cpp @@ -91,29 +91,9 @@ #define MPU_DEVICE_PATH_GYRO_EXT2 "/dev/mpu9250_gyro_ext2" #define MPU_DEVICE_PATH_MAG_EXT2 "/dev/mpu9250_mag_ext2" -#define MPU_DEVICE_PATH_MPU6500_ACCEL "/dev/mpu6500_accel" -#define MPU_DEVICE_PATH_MPU6500_GYRO "/dev/mpu6500_gyro" -#define MPU_DEVICE_PATH_MPU6500_MAG "/dev/mpu6500_mag" - -#define MPU_DEVICE_PATH_MPU6500_ACCEL_1 "/dev/mpu6500_accel1" -#define MPU_DEVICE_PATH_MPU6500_GYRO_1 "/dev/mpu6500_gyro1" -#define MPU_DEVICE_PATH_MPU6500_MAG_1 "/dev/mpu6500_mag1" - -#define MPU_DEVICE_PATH_MPU6500_ACCEL_EXT "/dev/mpu6500_accel_ext" -#define MPU_DEVICE_PATH_MPU6500_GYRO_EXT "/dev/mpu6500_gyro_ext" -#define MPU_DEVICE_PATH_MPU6500_MAG_EXT "/dev/mpu6500_mag_ext" - -#define MPU_DEVICE_PATH_ICM_ACCEL_EXT "/dev/mpu9250_icm_accel_ext" -#define MPU_DEVICE_PATH_ICM_GYRO_EXT "/dev/mpu9250_icm_gyro_ext" -#define MPU_DEVICE_PATH_ICM_MAG_EXT "/dev/mpu9250_icm_mag_ext" - -#define MPU_DEVICE_PATH_ICM_ACCEL_EXT1 "/dev/mpu9250_icm_accel_ext1" -#define MPU_DEVICE_PATH_ICM_GYRO_EXT1 "/dev/mpu9250_icm_gyro_ext1" -#define MPU_DEVICE_PATH_ICM_MAG_EXT1 "/dev/mpu9250_icm_mag_ext1" - -#define MPU_DEVICE_PATH_ICM_ACCEL_EXT2 "/dev/mpu9250_icm_accel_ext2" -#define MPU_DEVICE_PATH_ICM_GYRO_EXT2 "/dev/mpu9250_icm_gyro_ext2" -#define MPU_DEVICE_PATH_ICM_MAG_EXT2 "/dev/mpu9250_icm_mag_ext2" +#define ICM_DEVICE_PATH_ACCEL_EXT "/dev/icm20948_accel_ext" +#define ICM_DEVICE_PATH_GYRO_EXT "/dev/icm20948_gyro_ext" +#define ICM_DEVICE_PATH_MAG_EXT "/dev/icm20948_mag_ext" /** driver 'main' command */ extern "C" { __EXPORT int mpu9250_main(int argc, char *argv[]); } @@ -150,34 +130,29 @@ struct mpu9250_bus_option { } bus_options[] = { #if defined (USE_I2C) # if defined(PX4_I2C_BUS_ONBOARD) && defined(PX4_I2C_OBDEV_MPU9250) - { MPU9250_BUS_I2C_INTERNAL, MPU_DEVICE_PATH_ACCEL, MPU_DEVICE_PATH_GYRO, MPU_DEVICE_PATH_MAG, &MPU9250_I2C_interface, false, PX4_I2C_BUS_ONBOARD, PX4_I2C_OBDEV_MPU9250, NULL }, - { MPU9250_BUS_I2C_INTERNAL, MPU_DEVICE_PATH_ACCEL, MPU_DEVICE_PATH_GYRO, MPU_DEVICE_PATH_MAG, &MPU9250_I2C_interface, false, PX4_I2C_BUS_ONBOARD, PX4_I2C_OBDEV_MPU9250, NULL }, + { MPU9250_BUS_I2C_INTERNAL, MPU_DEVICE_PATH_ACCEL, MPU_DEVICE_PATH_GYRO, MPU_DEVICE_PATH_MAG, &MPU9250_I2C_interface, false, PX4_I2C_BUS_ONBOARD, PX4_I2C_OBDEV_MPU9250, nullptr }, # endif # if defined(PX4_I2C_BUS_EXPANSION) # if defined(PX4_I2C_OBDEV_MPU9250) - { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT, MPU_DEVICE_PATH_GYRO_EXT, MPU_DEVICE_PATH_MAG_EXT, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION, PX4_I2C_OBDEV_MPU9250, NULL }, - { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT, MPU_DEVICE_PATH_GYRO_EXT, MPU_DEVICE_PATH_MAG_EXT, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION, PX4_I2C_OBDEV_MPU9250, NULL }, + { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT, MPU_DEVICE_PATH_GYRO_EXT, MPU_DEVICE_PATH_MAG_EXT, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION, PX4_I2C_OBDEV_MPU9250, nullptr }, # endif - { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ICM_ACCEL_EXT, MPU_DEVICE_PATH_ICM_GYRO_EXT, MPU_DEVICE_PATH_ICM_MAG_EXT, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION, PX4_I2C_EXT_ICM20948_1, NULL }, + { MPU9250_BUS_I2C_EXTERNAL, ICM_DEVICE_PATH_ACCEL_EXT, ICM_DEVICE_PATH_GYRO_EXT, ICM_DEVICE_PATH_MAG_EXT, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION, PX4_I2C_EXT_ICM20948_1, nullptr }, #endif # if defined(PX4_I2C_BUS_EXPANSION1) && defined(PX4_I2C_OBDEV_MPU9250) - { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT1, MPU_DEVICE_PATH_GYRO_EXT1, MPU_DEVICE_PATH_MAG_EXT1, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION1, PX4_I2C_OBDEV_MPU9250, NULL }, + { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT1, MPU_DEVICE_PATH_GYRO_EXT1, MPU_DEVICE_PATH_MAG_EXT1, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION1, PX4_I2C_OBDEV_MPU9250, nullptr }, # endif # if defined(PX4_I2C_BUS_EXPANSION2) && defined(PX4_I2C_OBDEV_MPU9250) - { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT2, MPU_DEVICE_PATH_GYRO_EXT2, MPU_DEVICE_PATH_MAG_EXT2, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION2, PX4_I2C_OBDEV_MPU9250, NULL }, + { MPU9250_BUS_I2C_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT2, MPU_DEVICE_PATH_GYRO_EXT2, MPU_DEVICE_PATH_MAG_EXT2, &MPU9250_I2C_interface, false, PX4_I2C_BUS_EXPANSION2, PX4_I2C_OBDEV_MPU9250, nullptr }, # endif #endif #ifdef PX4_SPIDEV_MPU - { MPU9250_BUS_SPI_INTERNAL, MPU_DEVICE_PATH_ACCEL, MPU_DEVICE_PATH_GYRO, MPU_DEVICE_PATH_MAG, &MPU9250_SPI_interface, true, PX4_SPI_BUS_SENSORS, PX4_SPIDEV_MPU, NULL }, - { MPU9250_BUS_SPI_INTERNAL, MPU_DEVICE_PATH_MPU6500_ACCEL, MPU_DEVICE_PATH_MPU6500_GYRO, MPU_DEVICE_PATH_MPU6500_MAG, &MPU9250_SPI_interface, true, PX4_SPI_BUS_SENSORS, PX4_SPIDEV_MPU, NULL }, + { MPU9250_BUS_SPI_INTERNAL, MPU_DEVICE_PATH_ACCEL, MPU_DEVICE_PATH_GYRO, MPU_DEVICE_PATH_MAG, &MPU9250_SPI_interface, true, PX4_SPI_BUS_SENSORS, PX4_SPIDEV_MPU, nullptr }, #endif #ifdef PX4_SPIDEV_MPU2 - { MPU9250_BUS_SPI_INTERNAL2, MPU_DEVICE_PATH_ACCEL_1, MPU_DEVICE_PATH_GYRO_1, MPU_DEVICE_PATH_MAG_1, &MPU9250_SPI_interface, true, PX4_SPI_BUS_SENSORS, PX4_SPIDEV_MPU2, NULL }, - { MPU9250_BUS_SPI_INTERNAL2, MPU_DEVICE_PATH_MPU6500_ACCEL_1, MPU_DEVICE_PATH_MPU6500_GYRO_1, MPU_DEVICE_PATH_MPU6500_MAG_1, &MPU9250_SPI_interface, true, PX4_SPI_BUS_SENSORS, PX4_SPIDEV_MPU2, NULL }, + { MPU9250_BUS_SPI_INTERNAL2, MPU_DEVICE_PATH_ACCEL_1, MPU_DEVICE_PATH_GYRO_1, MPU_DEVICE_PATH_MAG_1, &MPU9250_SPI_interface, true, PX4_SPI_BUS_SENSORS, PX4_SPIDEV_MPU2, nullptr }, #endif #if defined(PX4_SPI_BUS_EXT) && defined(PX4_SPIDEV_EXT_MPU) - { MPU9250_BUS_SPI_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT, MPU_DEVICE_PATH_GYRO_EXT, MPU_DEVICE_PATH_MAG_EXT, &MPU9250_SPI_interface, true, PX4_SPI_BUS_EXT, PX4_SPIDEV_EXT_MPU, NULL }, - { MPU9250_BUS_SPI_EXTERNAL, MPU_DEVICE_PATH_MPU6500_ACCEL_EXT, MPU_DEVICE_PATH_MPU6500_GYRO_EXT, MPU_DEVICE_PATH_MPU6500_MAG_EXT, &MPU9250_SPI_interface, true, PX4_SPI_BUS_EXT, PX4_SPIDEV_EXT_MPU, NULL }, + { MPU9250_BUS_SPI_EXTERNAL, MPU_DEVICE_PATH_ACCEL_EXT, MPU_DEVICE_PATH_GYRO_EXT, MPU_DEVICE_PATH_MAG_EXT, &MPU9250_SPI_interface, true, PX4_SPI_BUS_EXT, PX4_SPIDEV_EXT_MPU, nullptr }, #endif }; @@ -199,7 +174,7 @@ struct mpu9250_bus_option &find_bus(enum MPU9250_BUS busid) { for (uint8_t i = 0; i < NUM_BUS_OPTIONS; i++) { if ((busid == MPU9250_BUS_ALL || - busid == bus_options[i].busid) && bus_options[i].dev != NULL) { + busid == bus_options[i].busid) && bus_options[i].dev != nullptr) { return bus_options[i]; } } @@ -317,7 +292,7 @@ start(enum MPU9250_BUS busid, enum Rotation rotation, bool external, bool magnet bool started = false; for (unsigned i = 0; i < NUM_BUS_OPTIONS; i++) { - if (busid == MPU9250_BUS_ALL && bus_options[i].dev != NULL) { + if (bus_options[i].dev != nullptr) { // this device is already started continue; }