uc: No function calls should be made from within TIMER2_OVF_vect ISR. Thanks Wutje!

This commit is contained in:
Bart Van Der Meerssche 2009-11-13 20:16:16 +00:00
parent fc790d6ed6
commit 155ec157d0
2 changed files with 13 additions and 17 deletions

View File

@ -91,17 +91,10 @@ F_CPU = 1000000
# #
##################################################################################### #####################################################################################
ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino
AVR_TOOLS_PATH = /usr/bin AVR_TOOLS_PATH = /usr/bin
#SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
#CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp
SRC = wiring/serial.c SRC = wiring/serial.c
FORMAT = ihex FORMAT = ihex
# Name of this Makefile (used for "make depend"). # Name of this Makefile (used for "make depend").
MAKEFILE = Makefile MAKEFILE = Makefile
@ -116,10 +109,6 @@ OPT = s
CDEFS = -DF_CPU=$(F_CPU) CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU) CXXDEFS = -DF_CPU=$(F_CPU)
# Place -I options here
#CINCS = -I$(ARDUINO)
#CXXINCS = -I$(ARDUINO)
# Compiler flag to set the C Standard level. # Compiler flag to set the C Standard level.
# c89 - "ANSI" C # c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions # gnu89 - c89 plus GCC extensions

View File

@ -36,8 +36,6 @@
#include <avr/wdt.h> #include <avr/wdt.h>
// variable declarations // variable declarations
uint8_t i;
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}, {false, false, START}, {false, false, START}, {false, false, START}};
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}};
@ -74,10 +72,6 @@ ISR(TIMER2_OVF_vect) {
// add to nano(Wh) counter // add to nano(Wh) counter
aux[0].nano += (uint32_t)METERCONST * ADC; aux[0].nano += (uint32_t)METERCONST * ADC;
if (aux[0].nano > 1000000000) { if (aux[0].nano > 1000000000) {
printString("msg ADC0 sample value: ");
printIntegerInBase((unsigned long)ADC, 10);
printString("\n");
//debugging
measurements[0].value++; measurements[0].value++;
aux[0].pulse = true; aux[0].pulse = true;
aux[0].nano -= 1000000000; aux[0].nano -= 1000000000;
@ -88,6 +82,7 @@ ISR(TIMER2_OVF_vect) {
// interrupt service routine for analog comparator // interrupt service routine for analog comparator
ISR(ANALOG_COMP_vect) { ISR(ANALOG_COMP_vect) {
uint8_t i;
//debugging: //debugging:
//measurements[3].value = END3; //measurements[3].value = END3;
@ -118,6 +113,8 @@ ISR(ANALOG_COMP_vect) {
// interrupt service routine for watchdog timeout // interrupt service routine for watchdog timeout
ISR(WDT_vect) { ISR(WDT_vect) {
uint8_t i;
for (i=0; i<4; i++) for (i=0; i<4; i++)
eeprom_write_block((const void*)&measurements[i].value, (void*)&EEPROM_measurements[i].value, 4); eeprom_write_block((const void*)&measurements[i].value, (void*)&EEPROM_measurements[i].value, 4);
@ -235,9 +232,17 @@ void send(const struct sensor *measurement)
void loop() void loop()
{ {
uint8_t i;
// check whether we have to send out a pls to the deamon // check whether we have to send out a pls to the deamon
for (i=0; i<4; i++) { for (i=0; i<4; i++) {
if (aux[i].pulse == true) { if (aux[i].pulse == true) {
if (i == 0) {
//debugging
printString("msg ADC0 sample value: ");
printIntegerInBase((unsigned long)ADC, 10);
printString("\n");
}
send((const struct sensor *)&measurements[i]); send((const struct sensor *)&measurements[i]);
aux[i].pulse = false; aux[i].pulse = false;
} }
@ -249,6 +254,8 @@ void loop()
int main(void) int main(void)
{ {
uint8_t i;
WDT_off(); WDT_off();
setup(); setup();