From 81ebdb38b6dda49fa75326e5a21e9e674a23383d Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Sat, 16 Dec 2017 10:04:23 +0000 Subject: [PATCH] Improved accgyro device structure alignment --- src/main/common/utils.h | 4 +-- src/main/drivers/accgyro/accgyro.h | 42 ++++++++++++++++------------ src/main/drivers/light_ws2811strip.h | 2 +- src/main/sensors/acceleration.c | 1 - 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/common/utils.h b/src/main/common/utils.h index 2cc6f3a44..1cf72c520 100644 --- a/src/main/common/utils.h +++ b/src/main/common/utils.h @@ -97,10 +97,10 @@ static inline int32_t cmp32(uint32_t a, uint32_t b) { return (int32_t)(a-b); } // using memcpy_fn will force memcpy function call, instead of inlining it. In most cases function call takes fewer instructions // than inlined version (inlining is cheaper for very small moves < 8 bytes / 2 store instructions) -#ifdef UNIT_TEST +#if defined(UNIT_TEST) || defined(SIMULATOR_BUILD) // Call memcpy when building unittest - this is easier that asm symbol name mangling (symbols start with _underscore on win32) #include -static inline void memcpy_fn ( void * destination, const void * source, size_t num ) { memcpy(destination, source, num); }; +static inline void memcpy_fn ( void * destination, const void * source, size_t num ) { memcpy(destination, source, num); } #else void * memcpy_fn ( void * destination, const void * source, size_t num ) asm("memcpy"); #endif diff --git a/src/main/drivers/accgyro/accgyro.h b/src/main/drivers/accgyro/accgyro.h index 5908c69d0..c8f71c680 100644 --- a/src/main/drivers/accgyro/accgyro.h +++ b/src/main/drivers/accgyro/accgyro.h @@ -18,13 +18,17 @@ #pragma once #include "platform.h" + #include "common/axis.h" #include "drivers/exti.h" #include "drivers/bus.h" #include "drivers/sensor.h" #include "drivers/accgyro/accgyro_mpu.h" +#pragma GCC diagnostic push #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD) #include +#else +#pragma GCC diagnostic warning "-Wpadded" #endif #ifndef MPU_I2C_INSTANCE @@ -50,6 +54,9 @@ typedef enum { } gyroRateKHz_e; typedef struct gyroDev_s { +#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD) + pthread_mutex_t lock; +#endif sensorGyroInitFuncPtr initFn; // initialize function sensorGyroReadFuncPtr readFn; // read 3 axis data function sensorGyroReadDataFuncPtr temperatureFn; // read temperature if available @@ -58,38 +65,36 @@ typedef struct gyroDev_s { float scale; // scalefactor int32_t gyroZero[XYZ_AXIS_COUNT]; int32_t gyroADC[XYZ_AXIS_COUNT]; // gyro data after calibration and alignment - int16_t gyroADCRaw[XYZ_AXIS_COUNT]; int32_t gyroADCRawPrevious[XYZ_AXIS_COUNT]; + int16_t gyroADCRaw[XYZ_AXIS_COUNT]; int16_t temperature; - uint8_t lpf; - gyroRateKHz_e gyroRateKHz; - uint8_t mpuDividerDrops; - bool dataReady; - sensor_align_e gyroAlign; - mpuDetectionResult_t mpuDetectionResult; - ioTag_t mpuIntExtiTag; mpuConfiguration_t mpuConfiguration; + mpuDetectionResult_t mpuDetectionResult; + sensor_align_e gyroAlign; + gyroRateKHz_e gyroRateKHz; + bool dataReady; bool gyro_high_fsr; -#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD) - pthread_mutex_t lock; -#endif + uint8_t lpf; + uint8_t mpuDividerDrops; + ioTag_t mpuIntExtiTag; + uint8_t filler[3]; } gyroDev_t; typedef struct accDev_s { +#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD) + pthread_mutex_t lock; +#endif sensorAccInitFuncPtr initFn; // initialize function sensorAccReadFuncPtr readFn; // read 3 axis data function busDevice_t bus; uint16_t acc_1G; int16_t ADCRaw[XYZ_AXIS_COUNT]; - char revisionCode; // a revision code for the sensor, if known - bool dataReady; - sensor_align_e accAlign; mpuDetectionResult_t mpuDetectionResult; - mpuConfiguration_t mpuConfiguration; + sensor_align_e accAlign; + bool dataReady; bool acc_high_fsr; -#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD) - pthread_mutex_t lock; -#endif + char revisionCode; // a revision code for the sensor, if known + uint8_t filler[2]; } accDev_t; static inline void accDevLock(accDev_t *acc) @@ -127,3 +132,4 @@ static inline void gyroDevUnLock(gyroDev_t *gyro) (void)gyro; #endif } +#pragma GCC diagnostic pop diff --git a/src/main/drivers/light_ws2811strip.h b/src/main/drivers/light_ws2811strip.h index 64967bc3b..930b917e9 100644 --- a/src/main/drivers/light_ws2811strip.h +++ b/src/main/drivers/light_ws2811strip.h @@ -57,4 +57,4 @@ extern uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; extern volatile uint8_t ws2811LedDataTransferInProgress; extern uint16_t BIT_COMPARE_1; -extern uint16_t BIT_COMPARE_0; \ No newline at end of file +extern uint16_t BIT_COMPARE_0; diff --git a/src/main/sensors/acceleration.c b/src/main/sensors/acceleration.c index 0ec36037b..70a317815 100644 --- a/src/main/sensors/acceleration.c +++ b/src/main/sensors/acceleration.c @@ -319,7 +319,6 @@ bool accInit(uint32_t gyroSamplingInverval) memset(&acc, 0, sizeof(acc)); // copy over the common gyro mpu settings acc.dev.bus = *gyroSensorBus(); - acc.dev.mpuConfiguration = *gyroMpuConfiguration(); acc.dev.mpuDetectionResult = *gyroMpuDetectionResult(); acc.dev.acc_high_fsr = accelerometerConfig()->acc_high_fsr; if (!accDetect(&acc.dev, accelerometerConfig()->acc_hardware)) {