# HG changeset patch # User ethanzonca@CL-ENS241-08.cedarville.edu # Date 2013-03-22 15:56:41 # Node ID 3243bfc71b35daed832b668b794d7c3eeaaac5b6 # Parent f7fad1196562712e7e14d1688c22d6f24cf62288 Fixed warnings on master, implemented watchdog ISR to flash LEDs and save program timer to EEPROM. Program timer is restored upon reboot after the watchdog triggers, the error LED is activated, and an error message is logged to the SD card. diff --git a/master/master/config.h b/master/master/config.h --- a/master/master/config.h +++ b/master/master/config.h @@ -31,7 +31,7 @@ //#define DEBUG_OUTPUT // Blackout (turn off all but power LEDs) -#define BLACKOUT_ENABLE +//#define BLACKOUT_ENABLE #define BLACKOUT_TIMEOUT 300000 // Blackout after 5 minutes (hopefully after fix) // Board heater setpoint @@ -58,6 +58,7 @@ #define ERROR_ATFAIL 6 #define ERROR_EXITAT 7 #define ERROR_INFOTEXT 8 +#define ERROR_WATCHDOG 9 // !!! Please specify/update detailed messages for these error codes in logger.c // -------------------------------------------------------------------------- @@ -159,6 +160,9 @@ // Log number EEPROM address (this number is incremented on boot, used for filenames) #define LOGGER_ID_EEPROM_ADDR 0x10 +// Watchdog save/restore of program timer +#define WATCHDOG_PROGTIMER_EEPROM_ADDR 0x20 + // Written to the beginning of every log file #define LOGGER_HEADERTEXT "HAB Control Master - 1.0\n" diff --git a/master/master/lib/logger.c b/master/master/lib/logger.c --- a/master/master/lib/logger.c +++ b/master/master/lib/logger.c @@ -28,7 +28,7 @@ #include "led.h" #include "looptime.h" -#define MAX_ERRNO 8 +#define MAX_ERRNO 9 // Label lookup table // Make sure there are never more labels than there are MAX_NUM_SENSORS! @@ -41,6 +41,7 @@ const char err_5[] PROGMEM = "FATAL UNHA const char err_6[] PROGMEM = "enter AT mode failed"; const char err_7[] PROGMEM = "exit AT mode failed"; const char err_8[] PROGMEM = "infotext"; +const char err_9[] PROGMEM = "watchdog"; const char *const errorMessageLookup[] PROGMEM = { @@ -53,6 +54,7 @@ const char *const errorMessageLookup[] P err_6, err_7, err_8, + err_9 }; diff --git a/master/master/lib/looptime.c b/master/master/lib/looptime.c --- a/master/master/lib/looptime.c +++ b/master/master/lib/looptime.c @@ -39,3 +39,8 @@ uint32_t time_millis() { return millis; // meh accuracy, but that's OK } + +void time_watchdogrestore(uint32_t saved_millis) +{ + millis = saved_millis; +} diff --git a/master/master/lib/looptime.h b/master/master/lib/looptime.h --- a/master/master/lib/looptime.h +++ b/master/master/lib/looptime.h @@ -17,5 +17,6 @@ void time_setup(); uint32_t time_millis(); +void time_watchdogrestore(uint32_t saved_millis); #endif /* LOOPTIME_H_ */ \ No newline at end of file diff --git a/master/master/lib/sdcard/sd_raw.c b/master/master/lib/sdcard/sd_raw.c --- a/master/master/lib/sdcard/sd_raw.c +++ b/master/master/lib/sdcard/sd_raw.c @@ -13,7 +13,6 @@ #include "sd_raw.h" #include "sd_raw_config.h" #include "../led.h" -#include /** * \addtogroup sd_raw MMC/SD/SDHC card raw access diff --git a/master/master/lib/slavesensors.c b/master/master/lib/slavesensors.c --- a/master/master/lib/slavesensors.c +++ b/master/master/lib/slavesensors.c @@ -568,6 +568,11 @@ void slavesensors_process(uint8_t parseR } else { numRetries = 0; + + char msg[128]; + snprintf(msg, 128, "Slave %u (%s) failed max retries",currentSlave,slaveNames[currentSlave]); + error_log_msg(ERROR_SLAVETIMEOUT, false, msg); // log error, don't blink LED + gotoNextSlaveOrSensor(true); } } diff --git a/master/master/lib/watchdog.c b/master/master/lib/watchdog.c --- a/master/master/lib/watchdog.c +++ b/master/master/lib/watchdog.c @@ -10,10 +10,16 @@ * */ - +#include "../config.h" #include #include #include +#include +#include + +#include "looptime.h" +#include "led.h" +#include "logger.h" //initialize watchdog void watchdog_setup(void) @@ -21,8 +27,53 @@ void watchdog_setup(void) cli(); wdt_reset(); // Set change enable bit, enable the WDT - WDTCSR = (1< 0) + { + MCUSR &= ~(1<