From 0274bd503f204253816440b23a3efaddce056b90 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Wed, 28 Jan 2026 19:59:39 -0700 Subject: [PATCH 01/17] Added wrappers for interrupt enable/disable --- common/common.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- common/common.h | 12 +++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/common/common.c b/common/common.c index 0a6e41c..c1687ef 100644 --- a/common/common.c +++ b/common/common.c @@ -28,6 +28,7 @@ /*------------------------------------------------------------------------------ Project Includes ------------------------------------------------------------------------------*/ +#include "cmsis_gcc.h" #include "main.h" #include "common.h" #include "stm32h7xx_hal.h" @@ -47,6 +48,81 @@ API Functions ------------------------------------------------------------------------------*/ +/******************************************************************************* +* * +* PROCEDURE: * +* disable_irq() * +* * +* DESCRIPTION: * +* Disables IRQ interrupts * +* Wrapper for __disable_irq(); see cmsis_gcc.h * +* * +*******************************************************************************/ +void disable_irq() +{ + __disable_irq(); +} /* disable_irq */ + +/******************************************************************************* +* * +* PROCEDURE: * +* enable_irq() * +* * +* DESCRIPTION: * +* Enables IRQ interrupts * +* Wrapper for __enable_irq(); see cmsis_gcc.h * +* * +*******************************************************************************/ +void enable_irq() +{ + __enable_irq(); +} /* enable_irq */ + +/******************************************************************************* +* * +* PROCEDURE: * +* crc32 * +* * +* DESCRIPTION: * +* Returns a 32bit checksum from the given data. * +* * +*******************************************************************************/ +uint32_t crc32 + ( + const uint8_t *data, + size_t len + ) +{ +uint32_t crc = 0xFFFFFFFF; +while (len--) + { + crc ^= *data++; + for (int i = 0; i < 8; ++i) + crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1)); + } +return ~crc; + +} /* crc32 */ + + +/******************************************************************************* +* * +* PROCEDURE: * +* error_fail_fast * +* * +* DESCRIPTION: * +* In case of error occurrence, this function passes the error * +* code to the error handler * +* * +*******************************************************************************/ +void error_fail_fast + ( + volatile ERROR_CODE error_code + ) +{ +Error_Handler(error_code); + +} /* error_fail_fast */ /******************************************************************************* * * @@ -68,4 +144,4 @@ HAL_Delay(delay); /******************************************************************************* * END OF FILE * -*******************************************************************************/ \ No newline at end of file +*******************************************************************************/ diff --git a/common/common.h b/common/common.h index c2819d2..96cfc7a 100644 --- a/common/common.h +++ b/common/common.h @@ -107,6 +107,16 @@ memcpy( uid_buffer, uid, sizeof( ST_UID_TYPE ) ); Function Prototypes ------------------------------------------------------------------------------*/ +void disable_irq(); + +void enable_irq(); + +uint32_t crc32 + ( + const uint8_t *data, + size_t len + ); + /* common */ void delay_ms @@ -121,4 +131,4 @@ void delay_ms /******************************************************************************* * END OF FILE * -*******************************************************************************/ \ No newline at end of file +*******************************************************************************/ From eb6519599468ad2fe884b48c203c745416fe39cb Mon Sep 17 00:00:00 2001 From: butchhartman Date: Thu, 29 Jan 2026 16:19:39 -0700 Subject: [PATCH 02/17] Typdefs --- common/common.h | 2 +- sensor/sensor.c | 64 ++++++++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/common/common.h b/common/common.h index 96cfc7a..4f4e0c9 100644 --- a/common/common.h +++ b/common/common.h @@ -36,7 +36,7 @@ extern "C" { /*------------------------------------------------------------------------------ - Typdefs + Typedefs ------------------------------------------------------------------------------*/ /* UID serial number (packed struct inhibits padding) */ diff --git a/sensor/sensor.c b/sensor/sensor.c index 13ac322..5a97aa3 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -64,6 +64,7 @@ #if defined( VALVE_CONTROLLER ) #include "valve.h" #endif +#include "common.h" /*------------------------------------------------------------------------------ @@ -156,7 +157,7 @@ static void pt6_adc_channel_select #endif /* #ifdef L0002_REV5 */ #ifdef A0002_REV2 -static SENSOR_STATUS sensor_it_imu_baro +static SENSOR_STATUS sensor_get_it_ready ( uint32_t timeout, SENSOR_DATA* sensor_data_ptr, @@ -750,35 +751,50 @@ SENSOR_STATUS sensor_dump #if defined( FLIGHT_COMPUTER ) /*Call sensor API functions*/ - memset( &(imu_raw), 0, sizeof( IMU_RAW ) ); + /* check that IMU & BARO are ready to be read */ + parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT, sensor_data_ptr, &imu_raw ); - /* GPS sensor */ - sensor_data_ptr->gps_altitude_ft = gps_data.altitude_ft; - sensor_data_ptr->gps_speed_kmh = gps_data.speed_km; - sensor_data_ptr->gps_utc_time = gps_data.utc_time; - sensor_data_ptr->gps_dec_longitude = gps_data.dec_longitude; - sensor_data_ptr->gps_dec_latitude = gps_data.dec_latitude; - sensor_data_ptr->gps_ns = gps_data.ns; - sensor_data_ptr->gps_ew = gps_data.ew; - sensor_data_ptr->gps_gll_status = gps_data.gll_status; - sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; + /* If sensors are ready, then collect data, otherwise skip to status return */ + if( parallel_status != SENSOR_IT_TIMEOUT ) + { + /* Disabling interrupts to avoid race conditions */ + disable_irq(); - parallel_status = sensor_it_imu_baro( HAL_DEFAULT_TIMEOUT, sensor_data_ptr, &imu_raw ); + /* CRITICAL SECTION BEGIN */ - /*Compute State Estimations*/ + memset( &(imu_raw), 0, sizeof( IMU_RAW ) ); - /* Calculated and retrieve converted IMU data */ - sensor_conv_imu( &(sensor_data_ptr->imu_data), &imu_raw ); + /* GPS sensor */ + sensor_data_ptr->gps_altitude_ft = gps_data.altitude_ft; + sensor_data_ptr->gps_speed_kmh = gps_data.speed_km; + sensor_data_ptr->gps_utc_time = gps_data.utc_time; + sensor_data_ptr->gps_dec_longitude = gps_data.dec_longitude; + sensor_data_ptr->gps_dec_latitude = gps_data.dec_latitude; + sensor_data_ptr->gps_ns = gps_data.ns; + sensor_data_ptr->gps_ew = gps_data.ew; + sensor_data_ptr->gps_gll_status = gps_data.gll_status; + sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; - /* Calculated to get body state */ - sensor_body_state( &(sensor_data_ptr->imu_data) ); - /* Calculated velocity and position */ - sensor_imu_velo( &(sensor_data_ptr->imu_data) ); + /*Compute State Estimations*/ - /* Calculated velocity from barometer */ - sensor_baro_velo( sensor_data_ptr ); + /* Calculated and retrieve converted IMU data */ + sensor_conv_imu( &(sensor_data_ptr->imu_data), &imu_raw ); + /* Calculated to get body state */ + sensor_body_state( &(sensor_data_ptr->imu_data) ); + + /* Calculated velocity and position */ + sensor_imu_velo( &(sensor_data_ptr->imu_data) ); + + /* Calculated velocity from barometer */ + sensor_baro_velo( sensor_data_ptr ); + + /* CRITICAL SECTION END */ + + /* Reenabling interrupts after potentially dangerous reads/writes occur */ + enable_irq(); + } #elif defined( ENGINE_CONTROLLER ) #ifndef L0002_REV5 @@ -2155,13 +2171,13 @@ HAL_ADC_ConfigChannel( &hadc3, &sConfig ); /******************************************************************************* * * * PROCEDURE: * -* sensor_it_imu_baro * +* sensor_get_it_ready * * * * DESCRIPTION: * * Collect data from the double buffers and put it in sensor_data. * * * *******************************************************************************/ -static SENSOR_STATUS sensor_it_imu_baro +static SENSOR_STATUS sensor_get_it_ready ( uint32_t timeout, SENSOR_DATA* sensor_data_ptr, From 2b7bf3a355e4342b4c05384d878012aa86410c6e Mon Sep 17 00:00:00 2001 From: butchhartman Date: Thu, 29 Jan 2026 16:25:47 -0700 Subject: [PATCH 03/17] Include common.h when building for flight computer --- sensor/sensor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensor/sensor.c b/sensor/sensor.c index 5a97aa3..9ccf4f4 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -48,6 +48,7 @@ ------------------------------------------------------------------------------*/ #include "main.h" #if defined( FLIGHT_COMPUTER ) + #include "common.h" #include "imu.h" #include "baro.h" #elif defined( FLIGHT_COMPUTER_LITE ) @@ -64,7 +65,6 @@ #if defined( VALVE_CONTROLLER ) #include "valve.h" #endif -#include "common.h" /*------------------------------------------------------------------------------ From 2add1153d735017ff21cfcff55d6c587935188eb Mon Sep 17 00:00:00 2001 From: butchhartman Date: Fri, 30 Jan 2026 08:45:19 -0700 Subject: [PATCH 04/17] Conform irq toggling functions to file style --- common/common.c | 10 ++++++++-- common/common.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/common.c b/common/common.c index c1687ef..1d8e04c 100644 --- a/common/common.c +++ b/common/common.c @@ -58,7 +58,10 @@ * Wrapper for __disable_irq(); see cmsis_gcc.h * * * *******************************************************************************/ -void disable_irq() +void disable_irq + ( + void + ) { __disable_irq(); } /* disable_irq */ @@ -73,7 +76,10 @@ void disable_irq() * Wrapper for __enable_irq(); see cmsis_gcc.h * * * *******************************************************************************/ -void enable_irq() +void enable_irq + ( + void + ) { __enable_irq(); } /* enable_irq */ diff --git a/common/common.h b/common/common.h index 4f4e0c9..f456b86 100644 --- a/common/common.h +++ b/common/common.h @@ -107,9 +107,15 @@ memcpy( uid_buffer, uid, sizeof( ST_UID_TYPE ) ); Function Prototypes ------------------------------------------------------------------------------*/ -void disable_irq(); +void disable_irq + ( + void + ); -void enable_irq(); +void enable_irq + ( + void + ); uint32_t crc32 ( From f40ef719a2e60389f5535e285f8a7082fad11961 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Fri, 30 Jan 2026 12:38:59 -0700 Subject: [PATCH 05/17] Check sensor status before read --- sensor/sensor.c | 69 ++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/sensor/sensor.c b/sensor/sensor.c index 9ccf4f4..c99e300 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -78,6 +78,9 @@ extern volatile uint32_t tdelta, previous_time; #ifdef FLIGHT_COMPUTER extern GPS_DATA gps_data; extern IMU_OFFSET imu_offset; +extern bool imu_data_ready; +extern bool baro_data_ready; +extern bool mag_data_ready; #endif @@ -159,9 +162,7 @@ static void pt6_adc_channel_select #ifdef A0002_REV2 static SENSOR_STATUS sensor_get_it_ready ( - uint32_t timeout, - SENSOR_DATA* sensor_data_ptr, - IMU_RAW* imu_raw + uint32_t timeout ); #endif @@ -712,10 +713,8 @@ SENSOR_STATUS sensor_dump ------------------------------------------------------------------------------*/ #if defined( FLIGHT_COMPUTER ) SENSOR_STATUS parallel_status; - IMU_STATUS accel_status; - IMU_STATUS gyro_status; - BARO_STATUS press_status; - BARO_STATUS temp_status; + IMU_STATUS imu_status; + BARO_STATUS baro_status; IMU_RAW imu_raw; #elif defined( ENGINE_CONTROLLER ) #if defined(L0002_REV4 ) @@ -733,10 +732,8 @@ SENSOR_STATUS sensor_dump ------------------------------------------------------------------------------*/ #if defined( FLIGHT_COMPUTER ) parallel_status = SENSOR_OK; - accel_status = IMU_OK; - gyro_status = IMU_OK; - press_status = BARO_OK; - temp_status = BARO_OK; + imu_status = IMU_OK; + baro_status = BARO_OK; #elif defined( ENGINE_CONTROLLER ) #ifdef L0002_REV4 pt_status = PRESSURE_OK; @@ -752,10 +749,9 @@ SENSOR_STATUS sensor_dump /*Call sensor API functions*/ /* check that IMU & BARO are ready to be read */ - parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT, sensor_data_ptr, &imu_raw ); + parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT); - /* If sensors are ready, then collect data, otherwise skip to status return */ - if( parallel_status != SENSOR_IT_TIMEOUT ) + if( parallel_status == SENSOR_OK) { /* Disabling interrupts to avoid race conditions */ disable_irq(); @@ -775,6 +771,11 @@ SENSOR_STATUS sensor_dump sensor_data_ptr->gps_gll_status = gps_data.gll_status; sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; + /* IMU Read */ + imu_status = get_imu_it( &imu_raw ); + + /* Baro Read */ + baro_status = get_baro_it( &(sensor_data_ptr->baro_pressure), &(sensor_data_ptr->baro_temp) ); /*Compute State Estimations*/ @@ -792,7 +793,7 @@ SENSOR_STATUS sensor_dump /* CRITICAL SECTION END */ - /* Reenabling interrupts after potentially dangerous reads/writes occur */ + /* Re-enabling interrupts after potentially dangerous reads/writes occur */ enable_irq(); } @@ -825,16 +826,11 @@ SENSOR_STATUS sensor_dump /* Start next measurement and return status */ parallel_status |= sensor_start_IT( sensor_data_ptr ); - if( accel_status != IMU_OK ) - { - return SENSOR_ACCEL_ERROR; - } - else if ( gyro_status != IMU_OK ) + if( imu_status != IMU_OK ) { - return SENSOR_GYRO_ERROR; + return SENSOR_IMU_FAIL; } - else if ( press_status != BARO_OK || - temp_status != BARO_OK ) + else if ( baro_status != BARO_OK) { return SENSOR_BARO_ERROR; } @@ -2174,39 +2170,24 @@ HAL_ADC_ConfigChannel( &hadc3, &sConfig ); * sensor_get_it_ready * * * * DESCRIPTION: * -* Collect data from the double buffers and put it in sensor_data. * +* Ensures baro & imu are ready to be read from. * * * *******************************************************************************/ static SENSOR_STATUS sensor_get_it_ready ( - uint32_t timeout, - SENSOR_DATA* sensor_data_ptr, - IMU_RAW* imu_raw + uint32_t timeout ) { /* set up timeout */ uint32_t starting_time = HAL_GetTick(); uint32_t curr_time = HAL_GetTick(); -IMU_STATUS imu_ready = IMU_BUSY; -BARO_STATUS baro_ready = BARO_BUSY; while( curr_time <= starting_time + timeout ) { - /* determine if ready */ - if( imu_ready == IMU_BUSY ) - { - imu_ready = get_imu_it( imu_raw ); - } - if( baro_ready == BARO_BUSY ) - { - /* doing IMU first. return ready. */ - baro_ready = get_baro_it( &(sensor_data_ptr->baro_pressure), &(sensor_data_ptr->baro_temp) ); - } - /* compute return if ready */ - if( baro_ready != BARO_BUSY && imu_ready != IMU_BUSY ) - { - return baro_ready | imu_ready; - } + /* Ensure both the IMU and barometer are ready to be read */ + if ( imu_data_ready && baro_data_ready && mag_data_ready) { + return SENSOR_OK; + } /* update timeout poll */ curr_time = HAL_GetTick(); From c66cc9fd06927cd1245c2af87a04f24d1b156303 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Fri, 30 Jan 2026 12:52:24 -0700 Subject: [PATCH 06/17] Minor common.c styling fix --- common/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/common.c b/common/common.c index 1d8e04c..edd1da2 100644 --- a/common/common.c +++ b/common/common.c @@ -51,7 +51,7 @@ /******************************************************************************* * * * PROCEDURE: * -* disable_irq() * +* disable_irq * * * * DESCRIPTION: * * Disables IRQ interrupts * @@ -69,7 +69,7 @@ void disable_irq /******************************************************************************* * * * PROCEDURE: * -* enable_irq() * +* enable_irq * * * * DESCRIPTION: * * Enables IRQ interrupts * From 9b630ad3dbf797d7bc9010c387e2dc6cf51ec12d Mon Sep 17 00:00:00 2001 From: butchhartman Date: Fri, 30 Jan 2026 12:59:11 -0700 Subject: [PATCH 07/17] More formatting in common.c --- common/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/common.c b/common/common.c index edd1da2..3cad1a6 100644 --- a/common/common.c +++ b/common/common.c @@ -63,7 +63,7 @@ void disable_irq void ) { - __disable_irq(); +__disable_irq(); } /* disable_irq */ /******************************************************************************* @@ -81,7 +81,7 @@ void enable_irq void ) { - __enable_irq(); +__enable_irq(); } /* enable_irq */ /******************************************************************************* From cac9759b949f6b2154743f41a53ac799b45c4037 Mon Sep 17 00:00:00 2001 From: ETSsound <147210601+ETSsound@users.noreply.github.com> Date: Mon, 2 Feb 2026 14:22:51 -0700 Subject: [PATCH 08/17] Fix common.c --- common/common.c | 47 ++--------------------------------------------- common/common.h | 8 -------- 2 files changed, 2 insertions(+), 53 deletions(-) diff --git a/common/common.c b/common/common.c index 3cad1a6..155f89e 100644 --- a/common/common.c +++ b/common/common.c @@ -66,6 +66,7 @@ void disable_irq __disable_irq(); } /* disable_irq */ + /******************************************************************************* * * * PROCEDURE: * @@ -84,51 +85,6 @@ void enable_irq __enable_irq(); } /* enable_irq */ -/******************************************************************************* -* * -* PROCEDURE: * -* crc32 * -* * -* DESCRIPTION: * -* Returns a 32bit checksum from the given data. * -* * -*******************************************************************************/ -uint32_t crc32 - ( - const uint8_t *data, - size_t len - ) -{ -uint32_t crc = 0xFFFFFFFF; -while (len--) - { - crc ^= *data++; - for (int i = 0; i < 8; ++i) - crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1)); - } -return ~crc; - -} /* crc32 */ - - -/******************************************************************************* -* * -* PROCEDURE: * -* error_fail_fast * -* * -* DESCRIPTION: * -* In case of error occurrence, this function passes the error * -* code to the error handler * -* * -*******************************************************************************/ -void error_fail_fast - ( - volatile ERROR_CODE error_code - ) -{ -Error_Handler(error_code); - -} /* error_fail_fast */ /******************************************************************************* * * @@ -148,6 +104,7 @@ HAL_Delay(delay); } /* delay_ms */ + /******************************************************************************* * END OF FILE * *******************************************************************************/ diff --git a/common/common.h b/common/common.h index f456b86..af73bf2 100644 --- a/common/common.h +++ b/common/common.h @@ -117,14 +117,6 @@ void enable_irq void ); -uint32_t crc32 - ( - const uint8_t *data, - size_t len - ); - -/* common */ - void delay_ms ( uint32_t delay From b5950aa62f7a2b5d20e56de1f9c115963aad9e65 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Mon, 2 Feb 2026 14:49:01 -0700 Subject: [PATCH 09/17] Remove include cmsis_gcc.h (oops) --- common/common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/common.c b/common/common.c index 155f89e..a4ab8e5 100644 --- a/common/common.c +++ b/common/common.c @@ -28,7 +28,6 @@ /*------------------------------------------------------------------------------ Project Includes ------------------------------------------------------------------------------*/ -#include "cmsis_gcc.h" #include "main.h" #include "common.h" #include "stm32h7xx_hal.h" @@ -55,7 +54,7 @@ * * * DESCRIPTION: * * Disables IRQ interrupts * -* Wrapper for __disable_irq(); see cmsis_gcc.h * +* Wrapper for __disable_irq(); * * * *******************************************************************************/ void disable_irq @@ -74,7 +73,7 @@ __disable_irq(); * * * DESCRIPTION: * * Enables IRQ interrupts * -* Wrapper for __enable_irq(); see cmsis_gcc.h * +* Wrapper for __enable_irq() * * * *******************************************************************************/ void enable_irq From ba7e409e969eed1fac24cc150be05af86b6d7730 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Mon, 2 Feb 2026 18:35:27 -0700 Subject: [PATCH 10/17] Added getters for imu, mag, and baro data ready flags --- baro/baro.c | 15 +++++++++++++++ baro/baro.h | 6 ++++++ imu/imu.c | 38 ++++++++++++++++++++++++++++++++++++-- imu/imu.h | 12 ++++++++++++ sensor/sensor.c | 7 ++----- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/baro/baro.c b/baro/baro.c index a009dd3..7180043 100644 --- a/baro/baro.c +++ b/baro/baro.c @@ -862,6 +862,21 @@ static BARO_STATUS baro_flush_fifo return write_reg( BARO_REG_CMD, BARO_CMD_FIFO_FLUSH ); } /* baro_flush_fifo */ +/******************************************************************************* +* * +* PROCEDURE: * +* baro_get_baro_data_ready * +* * +* DESCRIPTION: * +* Returns the baro_data_ready flag * +* * +*******************************************************************************/ +bool baro_get_baro_data_ready + ( + void + ) { +return baro_data_ready; +}/* baro_get_baro_data_ready */ /******************************************************************************* * * diff --git a/baro/baro.h b/baro/baro.h index 996d0cf..6d10293 100644 --- a/baro/baro.h +++ b/baro/baro.h @@ -282,6 +282,12 @@ BARO_STATUS baro_get_altitude void ); +/* returns the baro_data_ready flag */ +bool baro_get_baro_data_ready + ( + void + ); + BARO_STATUS start_baro_read_IT(); BARO_STATUS baro_IT_handler(); BARO_STATUS get_baro_it(float* pres_ptr, float* temp_ptr); diff --git a/imu/imu.c b/imu/imu.c index c80c6b0..eb74304 100644 --- a/imu/imu.c +++ b/imu/imu.c @@ -52,10 +52,10 @@ #if defined( A0002_REV2 ) uint8_t imu_raw_buffer[12]; IMU_RAW imu_raw_processed; -bool imu_data_ready; +static bool imu_data_ready; uint8_t mag_raw_buffer[8]; -bool mag_data_ready; +static bool mag_data_ready; #endif MAG_TRIM mag_trim; @@ -871,6 +871,40 @@ else } /* read_imu_regs */ +/******************************************************************************* +* * +* PROCEDURE: * +* imu_get_imu_data_ready * +* * +* DESCRIPTION: * +* * +* Returns the imu_data_ready flag * +* * +*******************************************************************************/ +bool imu_get_imu_data_ready + ( + void + ) { +return imu_data_ready; +} /* imu_get_imu_data_ready */ + +/******************************************************************************* +* * +* PROCEDURE: * +* imu_get_mag_data_ready * +* * +* DESCRIPTION: * +* * +* Returns the mag_data_ready flag * +* * +*******************************************************************************/ +bool imu_get_mag_data_ready + ( + void + ) { +return mag_data_ready; +} /* imu_get_mag_data_ready */ + #if defined( A0002_REV2 ) /******************************************************************************* * * diff --git a/imu/imu.h b/imu/imu.h index 0bc6bcb..f962ee1 100644 --- a/imu/imu.h +++ b/imu/imu.h @@ -487,6 +487,18 @@ void IMU_config uint16_t mag_setting ); +/* Get the static variable imu_data_ready */ +bool imu_get_imu_data_ready + ( + void + ); + +/* Get the static variable mag_data_ready */ +bool imu_get_mag_data_ready + ( + void + ); + #ifdef A0002_REV2 IMU_STATUS start_imu_read_IT(void); IMU_STATUS imu_it_handler(); diff --git a/sensor/sensor.c b/sensor/sensor.c index c99e300..22e33da 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -78,9 +78,6 @@ extern volatile uint32_t tdelta, previous_time; #ifdef FLIGHT_COMPUTER extern GPS_DATA gps_data; extern IMU_OFFSET imu_offset; -extern bool imu_data_ready; -extern bool baro_data_ready; -extern bool mag_data_ready; #endif @@ -2170,7 +2167,7 @@ HAL_ADC_ConfigChannel( &hadc3, &sConfig ); * sensor_get_it_ready * * * * DESCRIPTION: * -* Ensures baro & imu are ready to be read from. * +* Ensures baro & mag & imu are ready to be read from. * * * *******************************************************************************/ static SENSOR_STATUS sensor_get_it_ready @@ -2185,7 +2182,7 @@ while( curr_time <= starting_time + timeout ) { /* Ensure both the IMU and barometer are ready to be read */ - if ( imu_data_ready && baro_data_ready && mag_data_ready) { + if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready()) { return SENSOR_OK; } From e6c57b4aa8922dde9ceee115c08fc1131a3638f4 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Mon, 2 Feb 2026 18:37:50 -0700 Subject: [PATCH 11/17] Made baro_data_ready flag static --- baro/baro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baro/baro.c b/baro/baro.c index 7180043..5a9f7f6 100644 --- a/baro/baro.c +++ b/baro/baro.c @@ -49,7 +49,7 @@ static BARO_CAL_DATA baro_cal_data; uint8_t baro_raw_buffer[6]; float baro_pres_proc = NAN; float baro_temp_proc = NAN; -bool baro_data_ready = false; +static bool baro_data_ready = false; /*------------------------------------------------------------------------------ From ee24355d3d81dbcd63dfb79ed68288b87a9d61f6 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Wed, 4 Feb 2026 05:48:34 -0700 Subject: [PATCH 12/17] Updated changes to adhere to SDR standards --- baro/baro.c | 5 ++-- baro/baro.h | 2 +- common/common.c | 8 +++--- imu/imu.c | 14 +++++---- sensor/sensor.c | 75 +++++++++++++++++++++++++------------------------ 5 files changed, 55 insertions(+), 49 deletions(-) diff --git a/baro/baro.c b/baro/baro.c index 5a9f7f6..5e24da3 100644 --- a/baro/baro.c +++ b/baro/baro.c @@ -873,8 +873,9 @@ return write_reg( BARO_REG_CMD, BARO_CMD_FIFO_FLUSH ); *******************************************************************************/ bool baro_get_baro_data_ready ( - void - ) { + void + ) +{ return baro_data_ready; }/* baro_get_baro_data_ready */ diff --git a/baro/baro.h b/baro/baro.h index 6d10293..e133ed2 100644 --- a/baro/baro.h +++ b/baro/baro.h @@ -285,7 +285,7 @@ BARO_STATUS baro_get_altitude /* returns the baro_data_ready flag */ bool baro_get_baro_data_ready ( - void + void ); BARO_STATUS start_baro_read_IT(); diff --git a/common/common.c b/common/common.c index a4ab8e5..8a7f515 100644 --- a/common/common.c +++ b/common/common.c @@ -53,8 +53,8 @@ * disable_irq * * * * DESCRIPTION: * -* Disables IRQ interrupts * -* Wrapper for __disable_irq(); * +* Disables IRQ interrupts; wrapper for __disable_irq() * +* * * * *******************************************************************************/ void disable_irq @@ -72,8 +72,8 @@ __disable_irq(); * enable_irq * * * * DESCRIPTION: * -* Enables IRQ interrupts * -* Wrapper for __enable_irq() * +* Enables IRQ interrupts; wrapper for __enable_irq() * +* * * * *******************************************************************************/ void enable_irq diff --git a/imu/imu.c b/imu/imu.c index eb74304..e2c1776 100644 --- a/imu/imu.c +++ b/imu/imu.c @@ -877,14 +877,15 @@ else * imu_get_imu_data_ready * * * * DESCRIPTION: * -* * -* Returns the imu_data_ready flag * +* Returns the imu_data_ready flag * +* * * * *******************************************************************************/ bool imu_get_imu_data_ready ( void - ) { + ) +{ return imu_data_ready; } /* imu_get_imu_data_ready */ @@ -894,14 +895,15 @@ return imu_data_ready; * imu_get_mag_data_ready * * * * DESCRIPTION: * -* * -* Returns the mag_data_ready flag * +* Returns the mag_data_ready flag * +* * * * *******************************************************************************/ bool imu_get_mag_data_ready ( void - ) { + ) +{ return mag_data_ready; } /* imu_get_mag_data_ready */ diff --git a/sensor/sensor.c b/sensor/sensor.c index 22e33da..3058896 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -746,53 +746,55 @@ SENSOR_STATUS sensor_dump /*Call sensor API functions*/ /* check that IMU & BARO are ready to be read */ - parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT); + parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT ); - if( parallel_status == SENSOR_OK) - { - /* Disabling interrupts to avoid race conditions */ - disable_irq(); + if( parallel_status != SENSOR_OK ) + { + return parallel_status; + } - /* CRITICAL SECTION BEGIN */ + /* Disabling interrupts to avoid race conditions */ + disable_irq(); - memset( &(imu_raw), 0, sizeof( IMU_RAW ) ); + /* CRITICAL SECTION BEGIN */ - /* GPS sensor */ - sensor_data_ptr->gps_altitude_ft = gps_data.altitude_ft; - sensor_data_ptr->gps_speed_kmh = gps_data.speed_km; - sensor_data_ptr->gps_utc_time = gps_data.utc_time; - sensor_data_ptr->gps_dec_longitude = gps_data.dec_longitude; - sensor_data_ptr->gps_dec_latitude = gps_data.dec_latitude; - sensor_data_ptr->gps_ns = gps_data.ns; - sensor_data_ptr->gps_ew = gps_data.ew; - sensor_data_ptr->gps_gll_status = gps_data.gll_status; - sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; + memset( &(imu_raw), 0, sizeof( IMU_RAW ) ); - /* IMU Read */ - imu_status = get_imu_it( &imu_raw ); + /* GPS sensor */ + sensor_data_ptr->gps_altitude_ft = gps_data.altitude_ft; + sensor_data_ptr->gps_speed_kmh = gps_data.speed_km; + sensor_data_ptr->gps_utc_time = gps_data.utc_time; + sensor_data_ptr->gps_dec_longitude = gps_data.dec_longitude; + sensor_data_ptr->gps_dec_latitude = gps_data.dec_latitude; + sensor_data_ptr->gps_ns = gps_data.ns; + sensor_data_ptr->gps_ew = gps_data.ew; + sensor_data_ptr->gps_gll_status = gps_data.gll_status; + sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; - /* Baro Read */ - baro_status = get_baro_it( &(sensor_data_ptr->baro_pressure), &(sensor_data_ptr->baro_temp) ); + /* IMU Read */ + imu_status = get_imu_it( &imu_raw ); - /*Compute State Estimations*/ + /* Baro Read */ + baro_status = get_baro_it( &(sensor_data_ptr->baro_pressure), &(sensor_data_ptr->baro_temp) ); - /* Calculated and retrieve converted IMU data */ - sensor_conv_imu( &(sensor_data_ptr->imu_data), &imu_raw ); + /*Compute State Estimations*/ - /* Calculated to get body state */ - sensor_body_state( &(sensor_data_ptr->imu_data) ); + /* Calculated and retrieve converted IMU data */ + sensor_conv_imu( &(sensor_data_ptr->imu_data), &imu_raw ); - /* Calculated velocity and position */ - sensor_imu_velo( &(sensor_data_ptr->imu_data) ); + /* Calculated to get body state */ + sensor_body_state( &(sensor_data_ptr->imu_data) ); - /* Calculated velocity from barometer */ - sensor_baro_velo( sensor_data_ptr ); + /* Calculated velocity and position */ + sensor_imu_velo( &(sensor_data_ptr->imu_data) ); - /* CRITICAL SECTION END */ + /* Calculated velocity from barometer */ + sensor_baro_velo( sensor_data_ptr ); - /* Re-enabling interrupts after potentially dangerous reads/writes occur */ - enable_irq(); - } + /* CRITICAL SECTION END */ + + /* Re-enabling interrupts after potentially dangerous reads/writes occur */ + enable_irq(); #elif defined( ENGINE_CONTROLLER ) #ifndef L0002_REV5 @@ -2182,9 +2184,10 @@ while( curr_time <= starting_time + timeout ) { /* Ensure both the IMU and barometer are ready to be read */ - if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready()) { + if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready()) + { return SENSOR_OK; - } + } /* update timeout poll */ curr_time = HAL_GetTick(); From ce2760aca61d0c59666b44b311681325fb4da493 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Wed, 4 Feb 2026 06:01:49 -0700 Subject: [PATCH 13/17] Moved common include trying to fix weird indentation --- sensor/sensor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensor/sensor.c b/sensor/sensor.c index 3058896..f4b202f 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -48,9 +48,9 @@ ------------------------------------------------------------------------------*/ #include "main.h" #if defined( FLIGHT_COMPUTER ) - #include "common.h" #include "imu.h" #include "baro.h" + #include "common.h" #elif defined( FLIGHT_COMPUTER_LITE ) #include "baro.h" #endif From 9a8cc80c0c177be6cf9f3943307022bdaf01849b Mon Sep 17 00:00:00 2001 From: butchhartman Date: Wed, 4 Feb 2026 06:05:03 -0700 Subject: [PATCH 14/17] Fixed common include indentation --- sensor/sensor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensor/sensor.c b/sensor/sensor.c index f4b202f..076f213 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -48,9 +48,9 @@ ------------------------------------------------------------------------------*/ #include "main.h" #if defined( FLIGHT_COMPUTER ) + #include "common.h" #include "imu.h" #include "baro.h" - #include "common.h" #elif defined( FLIGHT_COMPUTER_LITE ) #include "baro.h" #endif From 4a4eb3e55ddc9ac8e9c9cad14968bda23d6d81a1 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Wed, 4 Feb 2026 06:30:09 -0700 Subject: [PATCH 15/17] Fixed formatting on imu.c function desc headers --- imu/imu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imu/imu.c b/imu/imu.c index e2c1776..7008c38 100644 --- a/imu/imu.c +++ b/imu/imu.c @@ -874,10 +874,10 @@ else /******************************************************************************* * * * PROCEDURE: * -* imu_get_imu_data_ready * +* imu_get_imu_data_ready * * * * DESCRIPTION: * -* Returns the imu_data_ready flag * +* Returns the imu_data_ready flag * * * * * *******************************************************************************/ @@ -892,10 +892,10 @@ return imu_data_ready; /******************************************************************************* * * * PROCEDURE: * -* imu_get_mag_data_ready * +* imu_get_mag_data_ready * * * * DESCRIPTION: * -* Returns the mag_data_ready flag * +* Returns the mag_data_ready flag * * * * * *******************************************************************************/ From 6f144f922d177c3a511270e4674162007970c5e7 Mon Sep 17 00:00:00 2001 From: butchhartman Date: Wed, 4 Feb 2026 06:36:11 -0700 Subject: [PATCH 16/17] sensor_get_it_ready() if indentation fix --- sensor/sensor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sensor/sensor.c b/sensor/sensor.c index 076f213..816ea6d 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -2184,7 +2184,7 @@ while( curr_time <= starting_time + timeout ) { /* Ensure both the IMU and barometer are ready to be read */ - if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready()) + if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready() ) { return SENSOR_OK; } From 062e934def0520bb0d91518c28f1cc3875efd4d2 Mon Sep 17 00:00:00 2001 From: etsells Date: Wed, 4 Feb 2026 09:10:55 -0700 Subject: [PATCH 17/17] Resolving nitpicks myself so I'm not torturing robert --- NOTICE | 4 +- baro/baro.c | 11 +++-- baro/baro.h | 6 +-- common/common.c | 10 ++--- imu/imu.c | 6 ++- sensor/sensor.c | 114 ++++++++++++++++++++++++------------------------ 6 files changed, 78 insertions(+), 73 deletions(-) diff --git a/NOTICE b/NOTICE index 7a24331..5c966b2 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1,3 @@ -This larger work, the Sun Devil Rocketry mod Submodule, uses the BSD-3-Clause. This software project does not use any dependencies, and all files in this project are covered under this license. \ No newline at end of file +This larger work, the Sun Devil Rocketry mod Submodule, uses the BSD-3-Clause. This software project does not have any official dependencies, however some derivative code is used. This is attributed below. + +sensor.c:sensor_conv_mag - Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. BSD-3-Clause license. https://opensource.org/license/bsd-3-clause \ No newline at end of file diff --git a/baro/baro.c b/baro/baro.c index 5e24da3..5581ca5 100644 --- a/baro/baro.c +++ b/baro/baro.c @@ -862,6 +862,7 @@ static BARO_STATUS baro_flush_fifo return write_reg( BARO_REG_CMD, BARO_CMD_FIFO_FLUSH ); } /* baro_flush_fifo */ + /******************************************************************************* * * * PROCEDURE: * @@ -872,12 +873,14 @@ return write_reg( BARO_REG_CMD, BARO_CMD_FIFO_FLUSH ); * * *******************************************************************************/ bool baro_get_baro_data_ready - ( - void - ) + ( + void + ) { return baro_data_ready; -}/* baro_get_baro_data_ready */ + +} /* baro_get_baro_data_ready */ + /******************************************************************************* * * diff --git a/baro/baro.h b/baro/baro.h index e133ed2..2a4847b 100644 --- a/baro/baro.h +++ b/baro/baro.h @@ -284,9 +284,9 @@ BARO_STATUS baro_get_altitude /* returns the baro_data_ready flag */ bool baro_get_baro_data_ready - ( - void - ); + ( + void + ); BARO_STATUS start_baro_read_IT(); BARO_STATUS baro_IT_handler(); diff --git a/common/common.c b/common/common.c index 8a7f515..4cc9844 100644 --- a/common/common.c +++ b/common/common.c @@ -50,11 +50,10 @@ /******************************************************************************* * * * PROCEDURE: * -* disable_irq * +* disable_irq * * * * DESCRIPTION: * -* Disables IRQ interrupts; wrapper for __disable_irq() * -* * +* Disables IRQ interrupts; wrapper for __disable_irq() * * * *******************************************************************************/ void disable_irq @@ -69,11 +68,10 @@ __disable_irq(); /******************************************************************************* * * * PROCEDURE: * -* enable_irq * +* enable_irq * * * * DESCRIPTION: * -* Enables IRQ interrupts; wrapper for __enable_irq() * -* * +* Enables IRQ interrupts; wrapper for __enable_irq() * * * *******************************************************************************/ void enable_irq diff --git a/imu/imu.c b/imu/imu.c index 7008c38..e659ca6 100644 --- a/imu/imu.c +++ b/imu/imu.c @@ -879,7 +879,6 @@ else * DESCRIPTION: * * Returns the imu_data_ready flag * * * -* * *******************************************************************************/ bool imu_get_imu_data_ready ( @@ -887,8 +886,10 @@ bool imu_get_imu_data_ready ) { return imu_data_ready; + } /* imu_get_imu_data_ready */ + /******************************************************************************* * * * PROCEDURE: * @@ -897,7 +898,6 @@ return imu_data_ready; * DESCRIPTION: * * Returns the mag_data_ready flag * * * -* * *******************************************************************************/ bool imu_get_mag_data_ready ( @@ -905,8 +905,10 @@ bool imu_get_mag_data_ready ) { return mag_data_ready; + } /* imu_get_mag_data_ready */ + #if defined( A0002_REV2 ) /******************************************************************************* * * diff --git a/sensor/sensor.c b/sensor/sensor.c index 816ea6d..8bc4226 100644 --- a/sensor/sensor.c +++ b/sensor/sensor.c @@ -743,58 +743,58 @@ SENSOR_STATUS sensor_dump /* Poll Sensors */ #if defined( FLIGHT_COMPUTER ) - /*Call sensor API functions*/ + /*Call sensor API functions*/ - /* check that IMU & BARO are ready to be read */ - parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT ); + /* check that IMU & BARO are ready to be read */ + parallel_status = sensor_get_it_ready( HAL_DEFAULT_TIMEOUT ); - if( parallel_status != SENSOR_OK ) - { - return parallel_status; - } + if( parallel_status != SENSOR_OK ) + { + return parallel_status; + } - /* Disabling interrupts to avoid race conditions */ - disable_irq(); + /* Disabling interrupts to avoid race conditions */ + disable_irq(); - /* CRITICAL SECTION BEGIN */ + /* CRITICAL SECTION BEGIN */ - memset( &(imu_raw), 0, sizeof( IMU_RAW ) ); + memset( &(imu_raw), 0, sizeof( IMU_RAW ) ); - /* GPS sensor */ - sensor_data_ptr->gps_altitude_ft = gps_data.altitude_ft; - sensor_data_ptr->gps_speed_kmh = gps_data.speed_km; - sensor_data_ptr->gps_utc_time = gps_data.utc_time; - sensor_data_ptr->gps_dec_longitude = gps_data.dec_longitude; - sensor_data_ptr->gps_dec_latitude = gps_data.dec_latitude; - sensor_data_ptr->gps_ns = gps_data.ns; - sensor_data_ptr->gps_ew = gps_data.ew; - sensor_data_ptr->gps_gll_status = gps_data.gll_status; - sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; + /* GPS sensor */ + sensor_data_ptr->gps_altitude_ft = gps_data.altitude_ft; + sensor_data_ptr->gps_speed_kmh = gps_data.speed_km; + sensor_data_ptr->gps_utc_time = gps_data.utc_time; + sensor_data_ptr->gps_dec_longitude = gps_data.dec_longitude; + sensor_data_ptr->gps_dec_latitude = gps_data.dec_latitude; + sensor_data_ptr->gps_ns = gps_data.ns; + sensor_data_ptr->gps_ew = gps_data.ew; + sensor_data_ptr->gps_gll_status = gps_data.gll_status; + sensor_data_ptr->gps_rmc_status = gps_data.rmc_status; - /* IMU Read */ - imu_status = get_imu_it( &imu_raw ); + /* IMU Read */ + imu_status = get_imu_it( &imu_raw ); - /* Baro Read */ - baro_status = get_baro_it( &(sensor_data_ptr->baro_pressure), &(sensor_data_ptr->baro_temp) ); + /* Baro Read */ + baro_status = get_baro_it( &(sensor_data_ptr->baro_pressure), &(sensor_data_ptr->baro_temp) ); - /*Compute State Estimations*/ + /*Compute State Estimations*/ - /* Calculated and retrieve converted IMU data */ - sensor_conv_imu( &(sensor_data_ptr->imu_data), &imu_raw ); + /* Calculated and retrieve converted IMU data */ + sensor_conv_imu( &(sensor_data_ptr->imu_data), &imu_raw ); - /* Calculated to get body state */ - sensor_body_state( &(sensor_data_ptr->imu_data) ); + /* Calculated to get body state */ + sensor_body_state( &(sensor_data_ptr->imu_data) ); - /* Calculated velocity and position */ - sensor_imu_velo( &(sensor_data_ptr->imu_data) ); + /* Calculated velocity and position */ + sensor_imu_velo( &(sensor_data_ptr->imu_data) ); - /* Calculated velocity from barometer */ - sensor_baro_velo( sensor_data_ptr ); + /* Calculated velocity from barometer */ + sensor_baro_velo( sensor_data_ptr ); - /* CRITICAL SECTION END */ + /* CRITICAL SECTION END */ - /* Re-enabling interrupts after potentially dangerous reads/writes occur */ - enable_irq(); + /* Re-enabling interrupts after potentially dangerous reads/writes occur */ + enable_irq(); #elif defined( ENGINE_CONTROLLER ) #ifndef L0002_REV5 @@ -826,21 +826,21 @@ SENSOR_STATUS sensor_dump parallel_status |= sensor_start_IT( sensor_data_ptr ); if( imu_status != IMU_OK ) - { - return SENSOR_IMU_FAIL; - } + { + return SENSOR_IMU_FAIL; + } else if ( baro_status != BARO_OK) - { - return SENSOR_BARO_ERROR; - } + { + return SENSOR_BARO_ERROR; + } else if ( parallel_status != SENSOR_OK ) - { - return SENSOR_IT_TIMEOUT; - } + { + return SENSOR_IT_TIMEOUT; + } else - { - return SENSOR_OK; - } + { + return SENSOR_OK; + } #elif defined( ENGINE_CONTROLLER ) #ifdef L0002_REV4 if ( pt_status != PRESSURE_OK ) @@ -2182,23 +2182,23 @@ uint32_t starting_time = HAL_GetTick(); uint32_t curr_time = HAL_GetTick(); while( curr_time <= starting_time + timeout ) { - - /* Ensure both the IMU and barometer are ready to be read */ - if ( imu_get_imu_data_ready() && imu_get_mag_data_ready() && baro_get_baro_data_ready() ) - { - return SENSOR_OK; - } + /* Ensure both the IMU and barometer are ready to be read */ + if ( imu_get_imu_data_ready() + && imu_get_mag_data_ready() + && baro_get_baro_data_ready() ) + { + return SENSOR_OK; + } /* update timeout poll */ curr_time = HAL_GetTick(); } return SENSOR_IT_TIMEOUT; + } -#endif /* #ifdef A0002_REV2 */ -#ifdef A0002_REV2 /******************************************************************************* * * * PROCEDURE: *