1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-24 16:55:29 +03:00

integrated tommie's eeprom sanity check. much less chances of new firmware screwing up due to old config version.

fixed pwm init for airplane mode mistakenly deleting motors from the mix. flyingwing should really work now.
removed led debug from althold


git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@223 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop@gmail.com 2012-09-21 04:12:17 +00:00
parent 9d5bfdb60b
commit 1dea2b3b3b
7 changed files with 2952 additions and 2900 deletions

View file

@ -12,8 +12,9 @@
config_t cfg;
const char rcChannelLetters[] = "AERT1234";
static uint8_t EEPROM_CONF_VERSION = 32;
static uint32_t enabledSensors = 0;
uint8_t checkNewConf = 31;
static void resetConf(void);
void parseRcChannels(const char *input)
{
@ -26,6 +27,32 @@ void parseRcChannels(const char *input)
}
}
static uint8_t validEEPROM(void)
{
const config_t *temp = (const config_t *)FLASH_WRITE_ADDR;
const uint8_t *p;
uint8_t chk = 0;
// check version number
if (EEPROM_CONF_VERSION != temp->version)
return 0;
// check size and magic numbers
if (temp->size != sizeof(config_t) || temp->magic_be != 0xBE || temp->magic_ef != 0xEF)
return 0;
// verify integrity of temporary copy
for (p = (const uint8_t *)temp; p < ((const uint8_t *)temp + sizeof(config_t)); p++)
chk ^= *p;
// checksum failed
if (chk != 0)
return 0;
// looks good, let's roll!
return 1;
}
void readEEPROM(void)
{
uint8_t i;
@ -54,9 +81,21 @@ void writeParams(uint8_t b)
{
FLASH_Status status;
uint32_t i;
uint8_t chk = 0;
const uint8_t *p;
cfg.version = EEPROM_CONF_VERSION;
cfg.size = sizeof(config_t);
cfg.magic_be = 0xBE;
cfg.magic_ef = 0xEF;
cfg.chk = 0;
// recalculate checksum before writing
for (p = (const uint8_t *)&cfg; p < ((const uint8_t *)&cfg + sizeof(config_t)); p++)
chk ^= *p;
cfg.chk = chk;
// write it
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
if (FLASH_ErasePage(FLASH_WRITE_ADDR) == FLASH_COMPLETE) {
@ -66,7 +105,6 @@ void writeParams(uint8_t b)
break; // TODO: fail
}
}
FLASH_Lock();
readEEPROM();
@ -76,15 +114,18 @@ void writeParams(uint8_t b)
void checkFirstTime(bool reset)
{
uint8_t test_val, i;
// check the EEPROM integrity before resetting values
if (!validEEPROM() || reset)
resetConf();
}
test_val = *(uint8_t *) FLASH_WRITE_ADDR;
// Default settings
static void resetConf(void)
{
int i;
memset(&cfg, 0, sizeof(config_t));
if (!reset && test_val == checkNewConf)
return;
// Default settings
cfg.version = checkNewConf;
cfg.version = EEPROM_CONF_VERSION;
cfg.mixerConfiguration = MULTITYPE_QUADX;
featureClearAll();
featureSet(FEATURE_VBAT);