uc: Safeguard against potential race condition. Thx Wutje!
This commit is contained in:
parent
155ec157d0
commit
b69e04c4ac
10
uc/main.c
10
uc/main.c
|
@ -36,7 +36,7 @@
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
// variable declarations
|
// variable declarations
|
||||||
volatile struct state aux[4] = {{false, false, START}, {false, false, START}, {false, false, START}, {false, false, START}};
|
volatile struct state aux[4] = {{false, false, START, 0}, {false, false, START, 0}, {false, false, START, 0}, {false, false, START, 0}};
|
||||||
|
|
||||||
volatile struct sensor EEMEM EEPROM_measurements[4] = {{SENSOR0, START}, {SENSOR1, START}, {SENSOR2, START}, {SENSOR3, START}};
|
volatile struct sensor EEMEM EEPROM_measurements[4] = {{SENSOR0, START}, {SENSOR1, START}, {SENSOR2, START}, {SENSOR3, START}};
|
||||||
volatile struct sensor measurements[4];
|
volatile struct sensor measurements[4];
|
||||||
|
@ -75,6 +75,7 @@ ISR(TIMER2_OVF_vect) {
|
||||||
measurements[0].value++;
|
measurements[0].value++;
|
||||||
aux[0].pulse = true;
|
aux[0].pulse = true;
|
||||||
aux[0].nano -= 1000000000;
|
aux[0].nano -= 1000000000;
|
||||||
|
aux[0].debug = ADC;
|
||||||
}
|
}
|
||||||
// start a new ADC conversion
|
// start a new ADC conversion
|
||||||
ADCSRA |= (1<<ADSC);
|
ADCSRA |= (1<<ADSC);
|
||||||
|
@ -210,9 +211,12 @@ void setup()
|
||||||
void send(const struct sensor *measurement)
|
void send(const struct sensor *measurement)
|
||||||
{
|
{
|
||||||
uint8_t i = 46;
|
uint8_t i = 46;
|
||||||
uint32_t value = measurement->value;
|
|
||||||
char pulse[49];
|
char pulse[49];
|
||||||
|
|
||||||
|
cli();
|
||||||
|
uint32_t value = measurement->value;
|
||||||
|
sei();
|
||||||
|
|
||||||
// generate pulse message structure
|
// generate pulse message structure
|
||||||
strcpy(pulse, "pls ");
|
strcpy(pulse, "pls ");
|
||||||
strcpy(&pulse[4], measurement->id);
|
strcpy(&pulse[4], measurement->id);
|
||||||
|
@ -240,7 +244,7 @@ void loop()
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
//debugging
|
//debugging
|
||||||
printString("msg ADC0 sample value: ");
|
printString("msg ADC0 sample value: ");
|
||||||
printIntegerInBase((unsigned long)ADC, 10);
|
printIntegerInBase((unsigned long)aux[0].debug, 10);
|
||||||
printString("\n");
|
printString("\n");
|
||||||
}
|
}
|
||||||
send((const struct sensor *)&measurements[i]);
|
send((const struct sensor *)&measurements[i]);
|
||||||
|
|
Loading…
Reference in New Issue