76,6 → 76,30 |
MixerTable_t Mixer; |
|
|
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
{ |
uint8_t crc = 0xAA; |
uint16_t i; |
|
for(i=0; i<len; i++) |
{ |
crc += pBuffer[i]; |
} |
return crc; |
} |
|
uint8_t EEProm_Checksum(uint16_t EEAddr, uint16_t len) |
{ |
uint8_t crc = 0xAA; |
uint16_t off; |
|
for(off=0; off<len; off++) |
{ |
crc += eeprom_read_byte((uint8_t*)(EEAddr + off));; |
} |
return crc; |
} |
|
void ParamSet_DefaultStickMapping(void) |
{ |
ParamSet.ChannelAssignment[CH_GAS] = 1; |
98,6 → 122,7 |
/***************************************************/ |
void ParamSet_DefaultSet1(void) // sport |
{ |
ParamSet.Revision = EEPARAM_REVISION; |
if(BoardRelease >= 20) |
{ |
ParamSet.GyroD = 5; |
193,6 → 218,7 |
ParamSet.NaviAngleLimitation = 100; |
ParamSet.NaviPHLoginTime = 4; |
memcpy(ParamSet.Name, "Sport\0",6); |
ParamSet.crc = RAM_Checksum((uint8_t*)(&ParamSet), sizeof(ParamSet)-1); |
} |
|
|
201,6 → 227,7 |
/***************************************************/ |
void ParamSet_DefaultSet2(void) // normal |
{ |
ParamSet.Revision = EEPARAM_REVISION; |
if(BoardRelease >= 20) |
{ |
ParamSet.GyroD = 5; |
296,6 → 323,7 |
ParamSet.NaviAngleLimitation = 100; |
ParamSet.NaviPHLoginTime = 4; |
memcpy(ParamSet.Name, "Normal\0", 7); |
ParamSet.crc = RAM_Checksum((uint8_t*)(&ParamSet), sizeof(ParamSet)-1); |
} |
|
|
304,6 → 332,7 |
/***************************************************/ |
void ParamSet_DefaultSet3(void) // beginner |
{ |
ParamSet.Revision = EEPARAM_REVISION; |
if(BoardRelease >= 20) |
{ |
ParamSet.GyroD = 5; |
399,6 → 428,7 |
ParamSet.NaviAngleLimitation = 100; |
ParamSet.NaviPHLoginTime = 4; |
memcpy(ParamSet.Name, "Beginner\0", 9); |
ParamSet.crc = RAM_Checksum((uint8_t*)(&ParamSet), sizeof(ParamSet)-1); |
} |
|
/***************************************************/ |
437,11 → 467,30 |
/* Read Parameter Set from EEPROM */ |
/***************************************************/ |
// number [1..5] |
void ParamSet_ReadFromEEProm(uint8_t setnumber) |
uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber) |
{ |
uint8_t crc; |
uint16_t eeaddr; |
|
// range the setnumber |
if((1 > setnumber) || (setnumber > 5)) setnumber = 3; |
eeprom_read_block((void *) &ParamSet.ChannelAssignment[0], (void*)(EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
|
// calculate eeprom addr |
eeaddr = EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1); |
|
// calculate checksum from eeprom |
crc = EEProm_Checksum(eeaddr, PARAMSET_STRUCT_LEN - 1); |
|
// check crc |
if(crc != eeprom_read_byte((uint8_t*)(eeaddr + PARAMSET_STRUCT_LEN - 1))) return 0; |
|
// check revision |
if(eeprom_read_byte((uint8_t*)(eeaddr)) != EEPARAM_REVISION) return 0; |
|
// read paramset from eeprom |
eeprom_read_block((void *) &ParamSet, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
LED_Init(); |
return 1; |
} |
|
/***************************************************/ |
448,16 → 497,35 |
/* Write Parameter Set to EEPROM */ |
/***************************************************/ |
// number [1..5] |
void ParamSet_WriteToEEProm(uint8_t setnumber) |
uint8_t ParamSet_WriteToEEProm(uint8_t setnumber) |
{ |
if(setnumber > 5) setnumber = 5; |
if(setnumber < 1) return; |
eeprom_write_block((void *) &ParamSet.ChannelAssignment[0], (void*)(EEPROM_ADR_PARAMSET_BEGIN + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
eeprom_write_word((uint16_t *)(EEPROM_ADR_PARAMSET_LENGTH), PARAMSET_STRUCT_LEN); |
eeprom_write_block( (void*)(&ParamSet.ChannelAssignment[0]), (void*)(EEPROM_ADR_CHANNELS), 12); // backup the first 12 bytes that is the rc channel mapping |
// set this parameter set to active set |
SetActiveParamSet(setnumber); |
LED_Init(); |
uint8_t crc; |
|
if(ParamSet.Revision == EEPARAM_REVISION) // write only the right revision to eeprom |
{ |
if(setnumber > 5) setnumber = 5; |
if(setnumber < 1) return 0; |
|
// update checksum |
ParamSet.crc = RAM_Checksum((uint8_t*)(&ParamSet), sizeof(ParamSet)-1); |
|
// write paramset to eeprom |
eeprom_write_block((void *) &ParamSet, (void*)(EEPROM_ADR_PARAMSET + PARAMSET_STRUCT_LEN * (setnumber - 1)), PARAMSET_STRUCT_LEN); |
|
// backup channel settings to separate block in eeprom |
eeprom_write_block( (void*)(ParamSet.ChannelAssignment), (void*)(EEPROM_ADR_CHANNELS), sizeof(ParamSet.ChannelAssignment)); |
|
// write crc of channel block to eeprom |
crc = RAM_Checksum((uint8_t*)(ParamSet.ChannelAssignment), sizeof(ParamSet.ChannelAssignment)); |
eeprom_write_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(ParamSet.ChannelAssignment)), crc); |
|
// update active settings number |
SetActiveParamSet(setnumber); |
LED_Init(); |
return 1; |
} |
// wrong revision |
return 0; |
} |
|
/***************************************************/ |
465,12 → 533,20 |
/***************************************************/ |
uint8_t MixerTable_ReadFromEEProm(void) |
{ |
if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXER_TABLE)) == EEMIXER_REVISION) |
{ |
eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer)); |
return 1; |
} |
else return 0; |
uint8_t crc; |
|
// calculate checksum in eeprom |
crc = EEProm_Checksum(EEPROM_ADR_MIXERTABLE, sizeof(Mixer) - 1); |
|
// check crc |
if( crc != eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE + sizeof(Mixer) - 1)) ) return 0; |
|
// check revision |
if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_MIXERTABLE)) != EEMIXER_REVISION) return 0; |
|
// read mixer table |
eeprom_read_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
return 1; |
} |
|
/***************************************************/ |
480,7 → 556,11 |
{ |
if(Mixer.Revision == EEMIXER_REVISION) |
{ |
eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXER_TABLE), sizeof(Mixer)); |
// update crc |
Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
|
// write to eeprom |
eeprom_write_block((void *) &Mixer, (void*)(EEPROM_ADR_MIXERTABLE), sizeof(Mixer)); |
return 1; |
} |
else return 0; |
508,6 → 588,7 |
Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
memcpy(Mixer.Name, "Quadro\0", 7); |
Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
} |
|
|
541,26 → 622,30 |
/***************************************************/ |
void ParamSet_Init(void) |
{ |
uint8_t Channel_Backup = 0, i; |
uint8_t channel_backup = 0, bad_params = 0, ee_default = 0,i; |
|
// parameter version check |
if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_PARAM_BEGIN + PID_PARAM_REVISION)) != EEPARAM_REVISION) |
|
if(EEPARAM_REVISION != GetParamByte(PID_EE_REVISION) ) |
{ |
// if version check faild |
printf("\n\rInit Parameter in EEPROM"); |
eeprom_write_byte((uint8_t*)(EEPROM_ADR_MIXER_TABLE), 0xFF); // reset also mixer table |
// check if channel mapping backup is valid |
if( (eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+0)) < 12) |
&& (eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+1)) < 12) |
&& (eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+2)) < 12) |
&& (eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+3)) < 12) |
) |
ee_default = 1; // software update or forced by mktool |
SetParamByte(PID_EE_REVISION, EEPARAM_REVISION); |
} |
|
|
// 1st check for a valid channel backup in eeprom |
i = EEProm_Checksum(EEPROM_ADR_CHANNELS, sizeof(ParamSet.ChannelAssignment)); |
if(i == eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS + sizeof(ParamSet.ChannelAssignment))) ) channel_backup = 1; |
|
|
// parameter check |
|
// check all 5 parameter settings |
for (i = 1;i < 6; i++) |
{ |
if(ee_default || !ParamSet_ReadFromEEProm(i)) // could not read paramset from eeprom |
{ |
Channel_Backup = 1; |
} |
// fill all 5 parameter settings |
for (i = 1;i < 6; i++) |
{ |
bad_params = 1; |
printf("\n\rGenerating default Parameter Set %d",i); |
switch(i) |
{ |
case 1: |
576,49 → 661,30 |
ParamSet_DefaultSet2(); // Kamera |
break; |
} |
if(Channel_Backup) // if we have a rc channel mapping backup in eeprom |
{ |
// restore it |
ParamSet.ChannelAssignment[0] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+0)); |
ParamSet.ChannelAssignment[1] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+1)); |
ParamSet.ChannelAssignment[2] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+2)); |
ParamSet.ChannelAssignment[3] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+3)); |
ParamSet.ChannelAssignment[4] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+4)); |
ParamSet.ChannelAssignment[5] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+5)); |
ParamSet.ChannelAssignment[6] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+6)); |
ParamSet.ChannelAssignment[7] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+7)); |
if(eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+8)) < 255) |
{ |
ParamSet.ChannelAssignment[8] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+8)); |
ParamSet.ChannelAssignment[9] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+9)); |
ParamSet.ChannelAssignment[10] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+10)); |
ParamSet.ChannelAssignment[11] = eeprom_read_byte((uint8_t*)(EEPROM_ADR_CHANNELS+11)); |
} |
else |
{ |
ParamSet.ChannelAssignment[8] = 9; |
ParamSet.ChannelAssignment[9] = 10; |
ParamSet.ChannelAssignment[10] = 11; |
ParamSet.ChannelAssignment[11] = 12; |
} |
if(channel_backup) // if we have an channel mapping backup in eeprom |
{ // restore it from eeprom |
eeprom_read_block((void *)ParamSet.ChannelAssignment, (void*)(EEPROM_ADR_CHANNELS), sizeof(ParamSet.ChannelAssignment)); |
} |
else |
{ |
{ // use default mapping |
ParamSet_DefaultStickMapping(); |
} |
ParamSet_WriteToEEProm(i); |
} |
} |
if(bad_params) // at least one of the parameter settings were invalid |
{ |
// default-Setting is parameter set 3 |
SetActiveParamSet(3); |
// update version info |
SetParamByte(PID_PARAM_REVISION, EEPARAM_REVISION); |
} |
|
|
// read active parameter set to ParamSet stucture |
ParamSet_ReadFromEEProm(GetActiveParamSet()); |
printf("\n\rUsing Parameter Set %d", GetActiveParamSet()); |
|
// load mixer table |
if(!MixerTable_ReadFromEEProm() ) |
if(ee_default || !MixerTable_ReadFromEEProm() ) |
{ |
printf("\n\rGenerating default Mixer Table"); |
MixerTable_Default(); // Quadro |