avr: prevent race conditions when getting/setting parameters

This commit is contained in:
Bart Van Der Meerssche 2010-12-28 00:34:50 +01:00
parent 1ada193cea
commit 263d3d107a
1 changed files with 35 additions and 7 deletions

View File

@ -223,6 +223,7 @@ void ctrlDecode(void)
void ctrlCmdGet(uint8_t cmd) void ctrlCmdGet(uint8_t cmd)
{ {
uint8_t i; uint8_t i;
uint32_t tmp32;
switch (cmd) { switch (cmd) {
case 'p': case 'p':
@ -233,7 +234,12 @@ void ctrlCmdGet(uint8_t cmd)
case 'v': case 'v':
ctrlReadCharFromRxBuffer(&i); ctrlReadCharFromRxBuffer(&i);
ctrlWriteLongToTxBuffer(sensor[i].value);
cli();
tmp32 = sensor[i].value;
sei();
ctrlWriteLongToTxBuffer(tmp32);
break; break;
case 'm': case 'm':
@ -253,31 +259,53 @@ void ctrlCmdGet(uint8_t cmd)
void ctrlCmdSet(uint8_t cmd) void ctrlCmdSet(uint8_t cmd)
{ {
uint8_t i; uint8_t i, tmp8;
uint16_t tmp16;
uint32_t tmp32;
switch (cmd) { switch (cmd) {
case 'p': case 'p':
for (i = 0 ; i < MAX_SENSORS; i++) { for (i = 0 ; i < MAX_SENSORS; i++) {
ctrlReadCharFromRxBuffer(&phy_to_log[i]); ctrlReadCharFromRxBuffer(&tmp8);
cli();
phy_to_log[i] = tmp8;
sei();
} }
break; break;
case 'v': case 'v':
ctrlReadCharFromRxBuffer(&i); ctrlReadCharFromRxBuffer(&i);
ctrlReadLongFromRxBuffer((uint32_t *)&sensor[i].value); ctrlReadLongFromRxBuffer(&tmp32);
cli();
sensor[i].value = tmp32;
sei();
break; break;
case 'm': case 'm':
ctrlReadCharFromRxBuffer(&i); ctrlReadCharFromRxBuffer(&i);
ctrlReadShortFromRxBuffer((uint16_t *)&sensor[i].meterconst); ctrlReadShortFromRxBuffer(&tmp16);
cli();
sensor[i].meterconst = tmp16;
sei();
break; break;
case 'w': case 'w':
ctrlReadShortFromRxBuffer((uint16_t *)&event.wdt); ctrlReadShortFromRxBuffer(&tmp16);
cli();
event.wdt = tmp16;
sei();
break; break;
case 'b': case 'b':
ctrlReadShortFromRxBuffer((uint16_t *)&event.brown_out); ctrlReadShortFromRxBuffer(&tmp16);
cli();
event.brown_out = tmp16;
sei();
break; break;
} }
} }