Code: Select all
checkNewConf = 17 + EEBLOCK_SIZE
This gives compiler error. How to satisfy compiler?
Code: Select all
checkNewConf = 17 + EEBLOCK_SIZE
Code: Select all
#define EEBLOCK_SIZE sizeof(eep_entry)/sizeof(eep_entry_t)
static uint8_t checkNewConf = 17 + EEBLOCK_SIZE;
// ************************************************************************************************************
// EEPROM Layout definition
// ************************************************************************************************************
static eep_entry_t eep_entry[] = {
{&checkNewConf, sizeof(checkNewConf)}
, {&P8, sizeof(P8)}
, {&I8, sizeof(I8)}
, {&D8, sizeof(D8)}
, {&rcRate8, sizeof(rcRate8)}
, {&rcExpo8, sizeof(rcExpo8)}
, {&rollPitchRate, sizeof(rollPitchRate)}
, {&yawRate, sizeof(yawRate)}
, {&dynThrPID, sizeof(dynThrPID)}
, {&accZero, sizeof(accZero)}
, {&magZero, sizeof(magZero)}
, {&accTrim, sizeof(accTrim)}
, {&activate1, sizeof(activate1)}
, {&activate2, sizeof(activate2)}
, {&powerTrigger1, sizeof(powerTrigger1)}
#ifdef FLYING_WING
, {&wing_left_mid, sizeof(wing_left_mid)}
, {&wing_right_mid, sizeof(wing_right_mid)}
#endif
#ifdef TRI
, {&tri_yaw_middle, sizeof(tri_yaw_middle)}
#endif
};
Code: Select all
typedef struct config_t {
uint8_t version;
uint8_t mixerConfiguration;
uint32_t enabledFeatures;
uint8_t P8[8];
uint8_t I8[8];
uint8_t D8[8];
uint8_t rcRate8;
uint8_t rcExpo8;
uint8_t rollPitchRate;
uint8_t yawRate;
....
config_t cfg;
and then eeprom writing/reading is just
eeprom_open();
eeprom_write_block(&cfg, (void *)NULL, sizeof(cfg));
eeprom_close();
eeprom_open();
eeprom_read_block(&cfg, (void *)NULL, sizeof(cfg));
eeprom_close();
kos wrote:your have circulare dep (1) in your define .. that can not work
EEBLOCK_SIZE require eep_entry require checkNewConf require EEBLOCK_SIZE
Hamburger wrote:kos wrote:your have circulare dep (1) in your define .. that can not work
EEBLOCK_SIZE require eep_entry require checkNewConf require EEBLOCK_SIZE
I understand the principles of circular dependencies in general. but the size of the struct would be independent from the value of checkNewConf; and the sizeof(checkNewConf) is fixed regardless of its value as well.
So it seems I still should be allowed to separate this in a declaration static uint8_t checkNewConf; and later assign the value checkNewConf = 17 + EEBLOCK_SIZE; right before calling the writeEeprom(), right?
dongs wrote:Why do you even *care* about including EEBLOCK_SIZE into the stuff.
No, with my way, you can just do version = checknewconf + sizeof(config_t) since size of struct will be known.
If you're trying to protect against silly changes, youre gonna screw yourself over when the following occurs:
1) user adds one more value to config struct, bumping size by 1byte, not increasing chknewconf
2) next user increases chknewconf without changing any data in struct. now version # is same.
Code: Select all
uint8_t check_cfg_integrity(config_t *cfg) {
uint8_t chk = 0;
uint8_t i;
for(i=0; i<sizeof(*cfg); i++) {
chk ^= (uint8_t*)cfg[i];
}
return (chk == 0);
}
...
eeprom_open();
eeprom_read_block(&cfg, (void *)NULL, sizeof(cfg));
eeprom_close();
if (! chk_cfg_integrity(&cfg)) {
/* config is broken, reset it */
cfg_load_default_values(&cfg);
}