Alignment with iNav

This commit is contained in:
Martin Budden 2017-01-25 21:06:01 +00:00
parent e4c860d4dd
commit f839e658e7
4 changed files with 54 additions and 41 deletions

View File

@ -47,6 +47,8 @@ PG_REGISTER(dummyConfig_t, dummyConfig, PG_DUMMY_CONFIG, 0);
extern uint8_t __config_start; // configured via linker script when building binaries. extern uint8_t __config_start; // configured via linker script when building binaries.
extern uint8_t __config_end; extern uint8_t __config_end;
static uint16_t eepromConfigSize;
typedef enum { typedef enum {
CR_CLASSICATION_SYSTEM = 0, CR_CLASSICATION_SYSTEM = 0,
CR_CLASSICATION_PROFILE1 = 1, CR_CLASSICATION_PROFILE1 = 1,
@ -111,7 +113,7 @@ static uint8_t updateChecksum(uint8_t chk, const void *data, uint32_t length)
} }
// Scan the EEPROM config. Returns true if the config is valid. // Scan the EEPROM config. Returns true if the config is valid.
static bool scanEEPROM(void) bool isEEPROMContentValid(void)
{ {
uint8_t chk = 0; uint8_t chk = 0;
const uint8_t *p = &__config_start; const uint8_t *p = &__config_start;
@ -148,7 +150,15 @@ static bool scanEEPROM(void)
chk = updateChecksum(chk, footer, sizeof(*footer)); chk = updateChecksum(chk, footer, sizeof(*footer));
p += sizeof(*footer); p += sizeof(*footer);
chk = ~chk; chk = ~chk;
return chk == *p; const uint8_t checkSum = *p;
p += sizeof(checkSum);
eepromConfigSize = p - &__config_start;
return chk == checkSum;
}
uint16_t getEEPROMConfigSize(void)
{
return eepromConfigSize;
} }
// find config record for reg + classification (profile info) in EEPROM // find config record for reg + classification (profile info) in EEPROM
@ -207,11 +217,6 @@ bool loadEEPROM(void)
return true; return true;
} }
bool isEEPROMContentValid(void)
{
return scanEEPROM();
}
static bool writeSettingsToEEPROM(void) static bool writeSettingsToEEPROM(void)
{ {
config_streamer_t streamer; config_streamer_t streamer;

View File

@ -17,8 +17,12 @@
#pragma once #pragma once
#include <stdint.h>
#include <stdbool.h>
#define EEPROM_CONF_VERSION 154 #define EEPROM_CONF_VERSION 154
bool isEEPROMContentValid(void); bool isEEPROMContentValid(void);
bool loadEEPROM(void); bool loadEEPROM(void);
void writeConfigToEEPROM(void); void writeConfigToEEPROM(void);
uint16_t getEEPROMConfigSize(void);

View File

@ -29,12 +29,18 @@
#include "cms/cms.h" #include "cms/cms.h"
#include "common/color.h"
#include "common/axis.h" #include "common/axis.h"
#include "common/maths.h" #include "common/color.h"
#include "common/filter.h" #include "common/filter.h"
#include "common/maths.h"
#include "config/config_eeprom.h"
#include "config/config_master.h"
#include "config/config_profile.h"
#include "config/feature.h"
#include "config/parameter_group.h"
#include "config/parameter_group_ids.h"
#include "drivers/sensor.h"
#include "drivers/accgyro.h" #include "drivers/accgyro.h"
#include "drivers/compass.h" #include "drivers/compass.h"
#include "drivers/io.h" #include "drivers/io.h"
@ -45,6 +51,7 @@
#include "drivers/rx_pwm.h" #include "drivers/rx_pwm.h"
#include "drivers/rx_spi.h" #include "drivers/rx_spi.h"
#include "drivers/sdcard.h" #include "drivers/sdcard.h"
#include "drivers/sensor.h"
#include "drivers/serial.h" #include "drivers/serial.h"
#include "drivers/sound_beeper.h" #include "drivers/sound_beeper.h"
#include "drivers/system.h" #include "drivers/system.h"
@ -56,43 +63,37 @@
#include "fc/rc_curves.h" #include "fc/rc_curves.h"
#include "fc/runtime_config.h" #include "fc/runtime_config.h"
#include "sensors/sensors.h" #include "flight/altitudehold.h"
#include "sensors/gyro.h" #include "flight/failsafe.h"
#include "sensors/compass.h" #include "flight/imu.h"
#include "sensors/acceleration.h" #include "flight/mixer.h"
#include "sensors/barometer.h" #include "flight/navigation.h"
#include "sensors/battery.h" #include "flight/pid.h"
#include "sensors/boardalignment.h" #include "flight/servos.h"
#include "io/beeper.h" #include "io/beeper.h"
#include "io/serial.h"
#include "io/gimbal.h" #include "io/gimbal.h"
#include "io/motors.h"
#include "io/servos.h"
#include "io/ledstrip.h"
#include "io/gps.h" #include "io/gps.h"
#include "io/ledstrip.h"
#include "io/motors.h"
#include "io/osd.h" #include "io/osd.h"
#include "io/serial.h"
#include "io/servos.h"
#include "io/vtx.h" #include "io/vtx.h"
#include "rx/rx.h" #include "rx/rx.h"
#include "rx/rx_spi.h" #include "rx/rx_spi.h"
#include "sensors/acceleration.h"
#include "sensors/barometer.h"
#include "sensors/battery.h"
#include "sensors/boardalignment.h"
#include "sensors/compass.h"
#include "sensors/gyro.h"
#include "sensors/sensors.h"
#include "telemetry/telemetry.h" #include "telemetry/telemetry.h"
#include "flight/mixer.h"
#include "flight/servos.h"
#include "flight/pid.h"
#include "flight/imu.h"
#include "flight/failsafe.h"
#include "flight/altitudehold.h"
#include "flight/navigation.h"
#include "config/config_eeprom.h"
#include "config/config_profile.h"
#include "config/config_master.h"
#include "config/feature.h"
#include "config/parameter_group.h"
#ifndef DEFAULT_RX_FEATURE #ifndef DEFAULT_RX_FEATURE
#define DEFAULT_RX_FEATURE FEATURE_RX_PARALLEL_PWM #define DEFAULT_RX_FEATURE FEATURE_RX_PARALLEL_PWM
#endif #endif
@ -1159,6 +1160,12 @@ void writeEEPROM(void)
resumeRxSignal(); resumeRxSignal();
} }
void resetEEPROM(void)
{
resetConfigs();
writeEEPROM();
}
void ensureEEPROMContainsValidData(void) void ensureEEPROMContainsValidData(void)
{ {
if (isEEPROMContentValid()) { if (isEEPROMContentValid()) {
@ -1167,12 +1174,6 @@ void ensureEEPROMContainsValidData(void)
resetEEPROM(); resetEEPROM();
} }
void resetEEPROM(void)
{
resetConfigs();
writeEEPROM();
}
void saveConfigAndNotify(void) void saveConfigAndNotify(void)
{ {
writeEEPROM(); writeEEPROM();

View File

@ -17,8 +17,11 @@
#pragma once #pragma once
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "config/parameter_group.h"
#if FLASH_SIZE <= 128 #if FLASH_SIZE <= 128
#define MAX_PROFILE_COUNT 2 #define MAX_PROFILE_COUNT 2
#else #else