Some redundant core refactorized.

This commit is contained in:
klaute 2016-10-14 09:46:04 +02:00
parent 6eb1e9a5dd
commit 03a0135f20
2 changed files with 62 additions and 50 deletions

View file

@ -394,7 +394,7 @@ void cc_disableClk(void)
void cc_saveDefaults(void)
{
saveEEPValues();
writeEEPROMConfig();
Serial.write(MSG_SOM1);
Serial.write(MSG_SOM2);

View file

@ -97,68 +97,66 @@ void loop()
/*****************************************************************************/
void saveEEPValues()
void write32BitEEPROM(uint8_t addr, uint32_t value)
{
EEPROM.write(addr , (uint8_t)((value & 0xff000000) >> 24));
EEPROM.write(addr + 1, (uint8_t)((value & 0x00ff0000) >> 16));
EEPROM.write(addr + 2, (uint8_t)((value & 0x0000ff00) >> 8));
EEPROM.write(addr + 3, (uint8_t) (value & 0x000000ff));
}
void write16BitEEPROM(uint8_t addr, uint16_t value)
{
EEPROM.write(addr , (uint8_t)((value & 0xff00) >> 8));
EEPROM.write(addr + 1, (uint8_t) (value & 0x00ff));
}
void writeEEPROMConfig()
{
EEPROM.write( 0, (uint8_t)((start_freq & 0xff000000) >> 24));
EEPROM.write( 1, (uint8_t)((start_freq & 0x00ff0000) >> 16));
EEPROM.write( 2, (uint8_t)((start_freq & 0x0000ff00) >> 8));
EEPROM.write( 3, (uint8_t) (start_freq & 0x000000ff));
EEPROM.write( 4, (uint8_t)((end_freq & 0xff000000) >> 24));
EEPROM.write( 5, (uint8_t)((end_freq & 0x00ff0000) >> 16));
EEPROM.write( 6, (uint8_t)((end_freq & 0x0000ff00) >> 8));
EEPROM.write( 7, (uint8_t) (end_freq & 0x000000ff));
EEPROM.write( 8, (uint8_t)((step_freq & 0xff000000) >> 24));
EEPROM.write( 9, (uint8_t)((step_freq & 0x00ff0000) >> 16));
EEPROM.write(10, (uint8_t)((step_freq & 0x0000ff00) >> 8));
EEPROM.write(11, (uint8_t) (step_freq & 0x000000ff));
EEPROM.write(12, (uint8_t)((intervall & 0xff00) >> 8));
EEPROM.write(13, (uint8_t) (intervall & 0x00ff));
write32BitEEPROM( 0, start_freq);
write32BitEEPROM( 4, end_freq);
write32BitEEPROM( 8, step_freq);
write16BitEEPROM(12, intervall);
EEPROM.write(14, (uint8_t)drive_str);
}
/*****************************************************************************/
uint32_t read32BitEEPROM(uint8_t addr)
{
uint32_t tmp = (uint32_t)EEPROM.read(addr ) << 24;
tmp += (uint32_t)EEPROM.read(addr + 1) << 16;
tmp += (uint32_t)EEPROM.read(addr + 2) << 8;
tmp += (uint32_t)EEPROM.read(addr + 3);
return tmp;
}
uint16_t read16BitEEPROM(uint8_t addr)
{
uint16_t tmp = (uint16_t)EEPROM.read(addr ) << 8;
tmp += (uint16_t)EEPROM.read(addr + 1);
}
/*****************************************************************************/
void readEEPValues()
{
uint32_t tmp_start_freq = (uint32_t)EEPROM.read(0) << 24;
tmp_start_freq += (uint32_t)EEPROM.read(1) << 16;
tmp_start_freq += (uint32_t)EEPROM.read(2) << 8;
tmp_start_freq += (uint32_t)EEPROM.read(3);
if (tmp_start_freq < 1)
tmp_start_freq = 1;
if (tmp_start_freq > 150000000)
tmp_start_freq = 150000000;
uint32_t tmp_start_freq = read32BitEEPROM(0);
start_freq = tmp_start_freq;
start_freq = keepFreqRange(tmp_start_freq);
uint32_t tmp_end_freq = (uint32_t)EEPROM.read(4) << 24;
tmp_end_freq += (uint32_t)EEPROM.read(5) << 16;
tmp_end_freq += (uint32_t)EEPROM.read(6) << 8;
tmp_end_freq += (uint32_t)EEPROM.read(7);
if (tmp_end_freq < 1)
tmp_end_freq = 1;
if (tmp_end_freq > 150000000)
tmp_end_freq = 150000000;
uint32_t tmp_end_freq = read32BitEEPROM(4);
end_freq = tmp_end_freq;
end_freq = keepFreqRange(tmp_end_freq);
uint32_t tmp_step_freq = (uint32_t)EEPROM.read( 8) << 24;
tmp_step_freq += (uint32_t)EEPROM.read( 9) << 16;
tmp_step_freq += (uint32_t)EEPROM.read(10) << 8;
tmp_step_freq += (uint32_t)EEPROM.read(11);
if (tmp_step_freq < 1)
tmp_step_freq = 1;
if (tmp_step_freq > 150000000)
tmp_step_freq = 150000000;
uint32_t tmp_step_freq = read32BitEEPROM(8);
step_freq = tmp_step_freq;
step_freq = keepFreqRange(tmp_step_freq);
uint16_t tmp_intervall = (uint16_t)EEPROM.read(12) << 8;
tmp_intervall += (uint16_t)EEPROM.read(13);
if (tmp_intervall < 1)
tmp_intervall = 1;
if (tmp_intervall > 150000000)
tmp_intervall = 150000000;
uint16_t tmp_intervall = read16BitEEPROM(12);
intervall = tmp_intervall;
@ -176,3 +174,17 @@ void readEEPValues()
/*****************************************************************************/
uint32_t keepFreqRange(uint32_t freq)
{
uint32_t f = freq;
if (freq < 1)
f = 1;
else if (freq > 150000000)
f = 150000000;
return f;
}
/*****************************************************************************/