mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Improved accgyro device structure alignment
This commit is contained in:
parent
7a7f1ceda5
commit
81ebdb38b6
4 changed files with 27 additions and 22 deletions
|
@ -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
|
// 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)
|
// 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)
|
// Call memcpy when building unittest - this is easier that asm symbol name mangling (symbols start with _underscore on win32)
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
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
|
#else
|
||||||
void * memcpy_fn ( void * destination, const void * source, size_t num ) asm("memcpy");
|
void * memcpy_fn ( void * destination, const void * source, size_t num ) asm("memcpy");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,13 +18,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
#include "common/axis.h"
|
#include "common/axis.h"
|
||||||
#include "drivers/exti.h"
|
#include "drivers/exti.h"
|
||||||
#include "drivers/bus.h"
|
#include "drivers/bus.h"
|
||||||
#include "drivers/sensor.h"
|
#include "drivers/sensor.h"
|
||||||
#include "drivers/accgyro/accgyro_mpu.h"
|
#include "drivers/accgyro/accgyro_mpu.h"
|
||||||
|
#pragma GCC diagnostic push
|
||||||
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
|
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#else
|
||||||
|
#pragma GCC diagnostic warning "-Wpadded"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MPU_I2C_INSTANCE
|
#ifndef MPU_I2C_INSTANCE
|
||||||
|
@ -50,6 +54,9 @@ typedef enum {
|
||||||
} gyroRateKHz_e;
|
} gyroRateKHz_e;
|
||||||
|
|
||||||
typedef struct gyroDev_s {
|
typedef struct gyroDev_s {
|
||||||
|
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
#endif
|
||||||
sensorGyroInitFuncPtr initFn; // initialize function
|
sensorGyroInitFuncPtr initFn; // initialize function
|
||||||
sensorGyroReadFuncPtr readFn; // read 3 axis data function
|
sensorGyroReadFuncPtr readFn; // read 3 axis data function
|
||||||
sensorGyroReadDataFuncPtr temperatureFn; // read temperature if available
|
sensorGyroReadDataFuncPtr temperatureFn; // read temperature if available
|
||||||
|
@ -58,38 +65,36 @@ typedef struct gyroDev_s {
|
||||||
float scale; // scalefactor
|
float scale; // scalefactor
|
||||||
int32_t gyroZero[XYZ_AXIS_COUNT];
|
int32_t gyroZero[XYZ_AXIS_COUNT];
|
||||||
int32_t gyroADC[XYZ_AXIS_COUNT]; // gyro data after calibration and alignment
|
int32_t gyroADC[XYZ_AXIS_COUNT]; // gyro data after calibration and alignment
|
||||||
int16_t gyroADCRaw[XYZ_AXIS_COUNT];
|
|
||||||
int32_t gyroADCRawPrevious[XYZ_AXIS_COUNT];
|
int32_t gyroADCRawPrevious[XYZ_AXIS_COUNT];
|
||||||
|
int16_t gyroADCRaw[XYZ_AXIS_COUNT];
|
||||||
int16_t temperature;
|
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;
|
mpuConfiguration_t mpuConfiguration;
|
||||||
|
mpuDetectionResult_t mpuDetectionResult;
|
||||||
|
sensor_align_e gyroAlign;
|
||||||
|
gyroRateKHz_e gyroRateKHz;
|
||||||
|
bool dataReady;
|
||||||
bool gyro_high_fsr;
|
bool gyro_high_fsr;
|
||||||
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
|
uint8_t lpf;
|
||||||
pthread_mutex_t lock;
|
uint8_t mpuDividerDrops;
|
||||||
#endif
|
ioTag_t mpuIntExtiTag;
|
||||||
|
uint8_t filler[3];
|
||||||
} gyroDev_t;
|
} gyroDev_t;
|
||||||
|
|
||||||
typedef struct accDev_s {
|
typedef struct accDev_s {
|
||||||
|
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
#endif
|
||||||
sensorAccInitFuncPtr initFn; // initialize function
|
sensorAccInitFuncPtr initFn; // initialize function
|
||||||
sensorAccReadFuncPtr readFn; // read 3 axis data function
|
sensorAccReadFuncPtr readFn; // read 3 axis data function
|
||||||
busDevice_t bus;
|
busDevice_t bus;
|
||||||
uint16_t acc_1G;
|
uint16_t acc_1G;
|
||||||
int16_t ADCRaw[XYZ_AXIS_COUNT];
|
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;
|
mpuDetectionResult_t mpuDetectionResult;
|
||||||
mpuConfiguration_t mpuConfiguration;
|
sensor_align_e accAlign;
|
||||||
|
bool dataReady;
|
||||||
bool acc_high_fsr;
|
bool acc_high_fsr;
|
||||||
#if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
|
char revisionCode; // a revision code for the sensor, if known
|
||||||
pthread_mutex_t lock;
|
uint8_t filler[2];
|
||||||
#endif
|
|
||||||
} accDev_t;
|
} accDev_t;
|
||||||
|
|
||||||
static inline void accDevLock(accDev_t *acc)
|
static inline void accDevLock(accDev_t *acc)
|
||||||
|
@ -127,3 +132,4 @@ static inline void gyroDevUnLock(gyroDev_t *gyro)
|
||||||
(void)gyro;
|
(void)gyro;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
|
@ -57,4 +57,4 @@ extern uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE];
|
||||||
extern volatile uint8_t ws2811LedDataTransferInProgress;
|
extern volatile uint8_t ws2811LedDataTransferInProgress;
|
||||||
|
|
||||||
extern uint16_t BIT_COMPARE_1;
|
extern uint16_t BIT_COMPARE_1;
|
||||||
extern uint16_t BIT_COMPARE_0;
|
extern uint16_t BIT_COMPARE_0;
|
||||||
|
|
|
@ -319,7 +319,6 @@ bool accInit(uint32_t gyroSamplingInverval)
|
||||||
memset(&acc, 0, sizeof(acc));
|
memset(&acc, 0, sizeof(acc));
|
||||||
// copy over the common gyro mpu settings
|
// copy over the common gyro mpu settings
|
||||||
acc.dev.bus = *gyroSensorBus();
|
acc.dev.bus = *gyroSensorBus();
|
||||||
acc.dev.mpuConfiguration = *gyroMpuConfiguration();
|
|
||||||
acc.dev.mpuDetectionResult = *gyroMpuDetectionResult();
|
acc.dev.mpuDetectionResult = *gyroMpuDetectionResult();
|
||||||
acc.dev.acc_high_fsr = accelerometerConfig()->acc_high_fsr;
|
acc.dev.acc_high_fsr = accelerometerConfig()->acc_high_fsr;
|
||||||
if (!accDetect(&acc.dev, accelerometerConfig()->acc_hardware)) {
|
if (!accDetect(&acc.dev, accelerometerConfig()->acc_hardware)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue