关于MWC四轴代码读写EEPROM的问题
最近在研究WMC代码时发现,在MWC的2.2版本代码中读写EEPROM时用到以下函数,像是较验用的,但具体还是不很明白,希望能够得到高人的指点,先谢过了!uint8_t calculate_sum(uint8_t *cb , uint8_t siz)
{
uint8_t sum=0x55;// checksum init
while(--siz) sum += *cb++;// calculate checksum (without checksum byte)
return sum;
}
上面这个函数在读EEPROM的函数中调用了,不知道具体做什么用
void readEEPROM() {
uint8_t i;
#ifdef MULTIPLE_CONFIGURATION_PROFILES
if(global_conf.currentSet>2) global_conf.currentSet=0;
#else
global_conf.currentSet=0;
#endif
eeprom_read_block((void*)&conf, (void*)(global_conf.currentSet * sizeof(conf) + sizeof(global_conf)), sizeof(conf));
if(calculate_sum((uint8_t*)&conf, sizeof(conf)) != conf.checksum) {
blinkLED(6,100,3);
#if defined(BUZZER)
alarmArray = 3;
#endif
LoadDefaults(); // force load defaults
}
for(i=0;i<6;i++) {
lookupPitchRollRC = (2500+conf.rcExpo8*(i*i-25))*i*(int32_t)conf.rcRate8/2500;
}
for(i=0;i<11;i++) {
int16_t tmp = 10*i-conf.thrMid8;
uint8_t y = 1;
if (tmp>0) y = 100-conf.thrMid8;
if (tmp<0) y = conf.thrMid8;
lookupThrottleRC = 10*conf.thrMid8 + tmp*( 100-conf.thrExpo8+(int32_t)conf.thrExpo8*(tmp*tmp)/(y*y) )/10; //
lookupThrottleRC = conf.minthrottle + (int32_t)(MAXTHROTTLE-conf.minthrottle)* lookupThrottleRC/1000; // ->
}
#if defined(POWERMETER)
pAlarm = (uint32_t) conf.powerTrigger1 * (uint32_t) PLEVELSCALE * (uint32_t) conf.pleveldiv; // need to cast before multiplying
#endif
#ifdef FLYING_WING
#ifdef LCD_CONF
conf.wing_left_mid= constrain(conf.wing_left_mid, WING_LEFT_MIN,WING_LEFT_MAX); //LEFT
conf.wing_right_mid = constrain(conf.wing_right_mid, WING_RIGHT_MIN, WING_RIGHT_MAX); //RIGHT
#else // w.o LCD support user may not find this value stored in eeprom, so always use the define value
conf.wing_left_mid= WING_LEFT_MID;
conf.wing_right_mid = WING_RIGHT_MID;
#endif
#endif
#ifdef TRI
#ifdef LCD_CONF
conf.tri_yaw_middle = constrain(conf.tri_yaw_middle, TRI_YAW_CONSTRAINT_MIN, TRI_YAW_CONSTRAINT_MAX); //REAR
#else // w.o LCD support user may not find this value stored in eeprom, so always use the define value
conf.tri_yaw_middle = TRI_YAW_MIDDLE;
#endif
#endif
#if GPS
if (f.I2C_INIT_DONE) GPS_set_pids();
#endif
#ifdef POWERMETER_HARD
conf.pleveldivsoft = PLEVELDIVSOFT;
#endif
#ifdef POWERMETER_SOFT
conf.pleveldivsoft = conf.pleveldiv;
#endif
#if defined(ARMEDTIMEWARNING)
ArmedTimeWarningMicroSeconds = (conf.armedtimewarning *1000000);
#endif
}
页:
[1]