avr: add version field and s/gv [set/get version] command

This commit is contained in:
Bart Van Der Meerssche 2010-12-29 21:45:41 +01:00
parent 21984e237a
commit b0fd16364e
2 changed files with 23 additions and 3 deletions

View File

@ -33,6 +33,9 @@ cBuffer ctrlTxBuffer; // ctrl transmit buffer
static char ctrlRxData[CTRL_RX_BUFFER_SIZE]; static char ctrlRxData[CTRL_RX_BUFFER_SIZE];
static char ctrlTxData[CTRL_TX_BUFFER_SIZE]; static char ctrlTxData[CTRL_TX_BUFFER_SIZE];
extern uint16_t EEMEM EEPROM_version;
extern uint16_t version;
extern volatile struct event_struct EEMEM EEPROM_event; extern volatile struct event_struct EEMEM EEPROM_event;
extern volatile struct event_struct event; extern volatile struct event_struct event;
@ -225,7 +228,7 @@ void ctrlDecode(void)
break; break;
default: default:
ctrlAddToTxBuffer('e'); ctrlAddToTxBuffer('z');
} }
ctrlAddToTxBuffer('.'); ctrlAddToTxBuffer('.');
@ -240,6 +243,10 @@ void ctrlCmdGet(uint8_t cmd)
uint32_t tmp32, tmp32_bis; uint32_t tmp32, tmp32_bis;
switch (cmd) { switch (cmd) {
case 'v':
ctrlWriteShortToTxBuffer(version);
break;
case 'p': case 'p':
for (i = 0 ; i < MAX_SENSORS; i++) { for (i = 0 ; i < MAX_SENSORS; i++) {
ctrlWriteCharToTxBuffer(phy_to_log[i]); ctrlWriteCharToTxBuffer(phy_to_log[i]);
@ -288,7 +295,7 @@ void ctrlCmdGet(uint8_t cmd)
break; break;
default: default:
ctrlAddToTxBuffer('e'); ctrlAddToTxBuffer('z');
} }
} }
@ -299,6 +306,14 @@ void ctrlCmdSet(uint8_t cmd)
uint32_t tmp32; uint32_t tmp32;
switch (cmd) { switch (cmd) {
case 'v':
ctrlReadShortFromRxBuffer(&tmp16);
cli();
version = tmp16;
sei();
break;
case 'p': case 'p':
for (i = 0 ; i < MAX_SENSORS; i++) { for (i = 0 ; i < MAX_SENSORS; i++) {
ctrlReadCharFromRxBuffer(&tmp8); ctrlReadCharFromRxBuffer(&tmp8);
@ -344,13 +359,14 @@ void ctrlCmdSet(uint8_t cmd)
break; break;
default: default:
ctrlAddToTxBuffer('e'); ctrlAddToTxBuffer('z');
} }
} }
void ctrlCmdCommit(void) void ctrlCmdCommit(void)
{ {
cli(); cli();
eeprom_write_block((const void*)&version, (void*)&EEPROM_version, sizeof(version));
eeprom_write_block((const void*)&event, (void*)&EEPROM_event, sizeof(event)); eeprom_write_block((const void*)&event, (void*)&EEPROM_event, sizeof(event));
eeprom_write_block((const void*)&phy_to_log, (void*)&EEPROM_phy_to_log, sizeof(phy_to_log)); eeprom_write_block((const void*)&phy_to_log, (void*)&EEPROM_phy_to_log, sizeof(phy_to_log));
eeprom_write_block((const void*)&sensor, (void*)&EEPROM_sensor, sizeof(sensor)); eeprom_write_block((const void*)&sensor, (void*)&EEPROM_sensor, sizeof(sensor));

View File

@ -38,6 +38,9 @@ volatile uint8_t spi_status, spi_high_hex;
uint8_t EEMEM first_EEPROM_byte_not_used_to_protect_from_brownout_corruption = 0xab; uint8_t EEMEM first_EEPROM_byte_not_used_to_protect_from_brownout_corruption = 0xab;
uint16_t EEMEM EEPROM_version = 210;
uint16_t version;
volatile struct event_struct EEMEM EEPROM_event = {0, 0}; volatile struct event_struct EEMEM EEPROM_event = {0, 0};
volatile struct event_struct event; volatile struct event_struct event;
@ -228,6 +231,7 @@ ISR(ANALOG_COMP_vect)
void setup_datastructs(void) void setup_datastructs(void)
{ {
eeprom_read_block((void*)&version, (const void*)&EEPROM_version, sizeof(version));
eeprom_read_block((void*)&event, (const void*)&EEPROM_event, sizeof(event)); eeprom_read_block((void*)&event, (const void*)&EEPROM_event, sizeof(event));
eeprom_read_block((void*)&phy_to_log, (const void*)&EEPROM_phy_to_log, sizeof(phy_to_log)); eeprom_read_block((void*)&phy_to_log, (const void*)&EEPROM_phy_to_log, sizeof(phy_to_log));
eeprom_read_block((void*)&sensor, (const void*)&EEPROM_sensor, sizeof(sensor)); eeprom_read_block((void*)&sensor, (const void*)&EEPROM_sensor, sizeof(sensor));