mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 17:25:20 +03:00
Reset the entire config when parameter groups have changed.
This commit is contained in:
parent
1ab7b7816b
commit
464da66ee1
7 changed files with 35 additions and 19 deletions
|
@ -95,7 +95,7 @@ void initEEPROM(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the EEPROM config. Returns true if the config is valid.
|
// Scan the EEPROM config. Returns true if the config is valid.
|
||||||
bool isEEPROMContentValid(void)
|
bool isEEPROMStructureValid(void)
|
||||||
{
|
{
|
||||||
const uint8_t *p = &__config_start;
|
const uint8_t *p = &__config_start;
|
||||||
const configHeader_t *header = (const configHeader_t *)p;
|
const configHeader_t *header = (const configHeader_t *)p;
|
||||||
|
@ -176,16 +176,23 @@ static const configRecord_t *findEEPROM(const pgRegistry_t *reg, configRecordFla
|
||||||
// but each PG is loaded/initialized exactly once and in defined order.
|
// but each PG is loaded/initialized exactly once and in defined order.
|
||||||
bool loadEEPROM(void)
|
bool loadEEPROM(void)
|
||||||
{
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
PG_FOREACH(reg) {
|
PG_FOREACH(reg) {
|
||||||
const configRecord_t *rec = findEEPROM(reg, CR_CLASSICATION_SYSTEM);
|
const configRecord_t *rec = findEEPROM(reg, CR_CLASSICATION_SYSTEM);
|
||||||
if (rec) {
|
if (rec) {
|
||||||
// config from EEPROM is available, use it to initialize PG. pgLoad will handle version mismatch
|
// config from EEPROM is available, use it to initialize PG. pgLoad will handle version mismatch
|
||||||
pgLoad(reg, rec->pg, rec->size - offsetof(configRecord_t, pg), rec->version);
|
if (!pgLoad(reg, rec->pg, rec->size - offsetof(configRecord_t, pg), rec->version)) {
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pgReset(reg);
|
pgReset(reg);
|
||||||
|
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool writeSettingsToEEPROM(void)
|
static bool writeSettingsToEEPROM(void)
|
||||||
|
@ -247,7 +254,7 @@ void writeConfigToEEPROM(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success && isEEPROMContentValid()) {
|
if (success && isEEPROMStructureValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#define EEPROM_CONF_VERSION 169
|
#define EEPROM_CONF_VERSION 169
|
||||||
|
|
||||||
bool isEEPROMContentValid(void);
|
bool isEEPROMStructureValid(void);
|
||||||
bool loadEEPROM(void);
|
bool loadEEPROM(void);
|
||||||
void writeConfigToEEPROM(void);
|
void writeConfigToEEPROM(void);
|
||||||
uint16_t getEEPROMConfigSize(void);
|
uint16_t getEEPROMConfigSize(void);
|
||||||
|
|
|
@ -454,16 +454,14 @@ void validateAndFixGyroConfig(void)
|
||||||
}
|
}
|
||||||
#endif // USE_OSD_SLAVE
|
#endif // USE_OSD_SLAVE
|
||||||
|
|
||||||
void readEEPROM(void)
|
bool readEEPROM(void)
|
||||||
{
|
{
|
||||||
#ifndef USE_OSD_SLAVE
|
#ifndef USE_OSD_SLAVE
|
||||||
suspendRxSignal();
|
suspendRxSignal();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Sanity check, read flash
|
// Sanity check, read flash
|
||||||
if (!loadEEPROM()) {
|
bool success = loadEEPROM();
|
||||||
failureMode(FAILURE_INVALID_EEPROM_CONTENTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
validateAndFixConfig();
|
validateAndFixConfig();
|
||||||
activateConfig();
|
activateConfig();
|
||||||
|
@ -471,6 +469,8 @@ void readEEPROM(void)
|
||||||
#ifndef USE_OSD_SLAVE
|
#ifndef USE_OSD_SLAVE
|
||||||
resumeRxSignal();
|
resumeRxSignal();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeEEPROM(void)
|
void writeEEPROM(void)
|
||||||
|
@ -489,12 +489,16 @@ void writeEEPROM(void)
|
||||||
void resetEEPROM(void)
|
void resetEEPROM(void)
|
||||||
{
|
{
|
||||||
resetConfigs();
|
resetConfigs();
|
||||||
|
|
||||||
|
validateAndFixConfig();
|
||||||
|
activateConfig();
|
||||||
|
|
||||||
writeEEPROM();
|
writeEEPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureEEPROMContainsValidData(void)
|
void ensureEEPROMStructureIsValid(void)
|
||||||
{
|
{
|
||||||
if (isEEPROMContentValid()) {
|
if (isEEPROMStructureValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetEEPROM();
|
resetEEPROM();
|
||||||
|
|
|
@ -60,9 +60,9 @@ void setPreferredBeeperOffMask(uint32_t mask);
|
||||||
|
|
||||||
void initEEPROM(void);
|
void initEEPROM(void);
|
||||||
void resetEEPROM(void);
|
void resetEEPROM(void);
|
||||||
void readEEPROM(void);
|
bool readEEPROM(void);
|
||||||
void writeEEPROM(void);
|
void writeEEPROM(void);
|
||||||
void ensureEEPROMContainsValidData(void);
|
void ensureEEPROMStructureIsValid(void);
|
||||||
|
|
||||||
void saveConfigAndNotify(void);
|
void saveConfigAndNotify(void);
|
||||||
void validateAndFixGyroConfig(void);
|
void validateAndFixGyroConfig(void);
|
||||||
|
|
|
@ -237,12 +237,13 @@ void init(void)
|
||||||
|
|
||||||
initEEPROM();
|
initEEPROM();
|
||||||
|
|
||||||
ensureEEPROMContainsValidData();
|
ensureEEPROMStructureIsValid();
|
||||||
readEEPROM();
|
bool readSuccess = readEEPROM();
|
||||||
|
|
||||||
// !!TODO: Check to be removed when moving to generic targets
|
if (!readSuccess || strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
|
||||||
if (strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
|
|
||||||
resetEEPROM();
|
resetEEPROM();
|
||||||
|
|
||||||
|
activateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
systemState |= SYSTEM_STATE_CONFIG_LOADED;
|
systemState |= SYSTEM_STATE_CONFIG_LOADED;
|
||||||
|
|
|
@ -72,14 +72,18 @@ bool pgResetCopy(void *copy, pgn_t pgn)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pgLoad(const pgRegistry_t* reg, const void *from, int size, int version)
|
bool pgLoad(const pgRegistry_t* reg, const void *from, int size, int version)
|
||||||
{
|
{
|
||||||
pgResetInstance(reg, pgOffset(reg));
|
pgResetInstance(reg, pgOffset(reg));
|
||||||
// restore only matching version, keep defaults otherwise
|
// restore only matching version, keep defaults otherwise
|
||||||
if (version == pgVersion(reg)) {
|
if (version == pgVersion(reg)) {
|
||||||
const int take = MIN(size, pgSize(reg));
|
const int take = MIN(size, pgSize(reg));
|
||||||
memcpy(pgOffset(reg), from, take);
|
memcpy(pgOffset(reg), from, take);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pgStore(const pgRegistry_t* reg, void *to, int size)
|
int pgStore(const pgRegistry_t* reg, void *to, int size)
|
||||||
|
|
|
@ -187,7 +187,7 @@ extern const uint8_t __pg_resetdata_end[];
|
||||||
|
|
||||||
const pgRegistry_t* pgFind(pgn_t pgn);
|
const pgRegistry_t* pgFind(pgn_t pgn);
|
||||||
|
|
||||||
void pgLoad(const pgRegistry_t* reg, const void *from, int size, int version);
|
bool pgLoad(const pgRegistry_t* reg, const void *from, int size, int version);
|
||||||
int pgStore(const pgRegistry_t* reg, void *to, int size);
|
int pgStore(const pgRegistry_t* reg, void *to, int size);
|
||||||
void pgResetAll(void);
|
void pgResetAll(void);
|
||||||
void pgResetInstance(const pgRegistry_t *reg, uint8_t *base);
|
void pgResetInstance(const pgRegistry_t *reg, uint8_t *base);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue