Clean up watchdog impl.

master
Scott Lahteine 9 years ago committed by Richard Wackerbarth
parent 8f16563bbd
commit b4af4441c5

@ -45,13 +45,16 @@
#include "stepper.h" #include "stepper.h"
#include "temperature.h" #include "temperature.h"
#include "cardreader.h" #include "cardreader.h"
#include "watchdog.h"
#include "configuration_store.h" #include "configuration_store.h"
#include "language.h" #include "language.h"
#include "pins_arduino.h" #include "pins_arduino.h"
#include "math.h" #include "math.h"
#include "buzzer.h" #include "buzzer.h"
#if ENABLED(USE_WATCHDOG)
#include "watchdog.h"
#endif
#if ENABLED(BLINKM) #if ENABLED(BLINKM)
#include "blinkm.h" #include "blinkm.h"
#include "Wire.h" #include "Wire.h"
@ -681,7 +684,11 @@ void setup() {
tp_init(); // Initialize temperature loop tp_init(); // Initialize temperature loop
plan_init(); // Initialize planner; plan_init(); // Initialize planner;
#if ENABLED(USE_WATCHDOG)
watchdog_init(); watchdog_init();
#endif
st_init(); // Initialize stepper, this enables interrupts! st_init(); // Initialize stepper, this enables interrupts!
setup_photpin(); setup_photpin();
servo_init(); servo_init();

@ -21,11 +21,13 @@
#include "Marlin.h" #include "Marlin.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "temperature.h" #include "temperature.h"
#include "watchdog.h"
#include "language.h" #include "language.h"
#include "Sd2PinMap.h" #include "Sd2PinMap.h"
#if ENABLED(USE_WATCHDOG)
#include "watchdog.h"
#endif
//=========================================================================== //===========================================================================
//================================== macros ================================= //================================== macros =================================
//=========================================================================== //===========================================================================
@ -819,8 +821,11 @@ static void updateTemperaturesFromRawValues() {
#if HAS_FILAMENT_SENSOR #if HAS_FILAMENT_SENSOR
filament_width_meas = analog2widthFil(); filament_width_meas = analog2widthFil();
#endif #endif
//Reset the watchdog after we know we have a temperature measurement.
#if ENABLED(USE_WATCHDOG)
// Reset the watchdog after we know we have a temperature measurement.
watchdog_reset(); watchdog_reset();
#endif
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
temp_meas_ready = false; temp_meas_ready = false;

@ -1,25 +1,14 @@
#include "Marlin.h" #include "Marlin.h"
#if ENABLED(USE_WATCHDOG) #if ENABLED(USE_WATCHDOG)
#include <avr/wdt.h>
#include "watchdog.h" #include "watchdog.h"
#include "ultralcd.h"
//=========================================================================== // Initialize watchdog with a 4 sec interrupt time
//============================ private variables ============================
//===========================================================================
//===========================================================================
//================================ functions ================================
//===========================================================================
/// intialise watch dog with a 4 sec interrupt time
void watchdog_init() { void watchdog_init() {
#if ENABLED(WATCHDOG_RESET_MANUAL) #if ENABLED(WATCHDOG_RESET_MANUAL)
//We enable the watchdog timer, but only for the interrupt. // We enable the watchdog timer, but only for the interrupt.
//Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details. // Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details.
wdt_reset(); wdt_reset();
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE); _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
_WD_CONTROL_REG = _BV(WDIE) | WDTO_4S; _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
@ -28,23 +17,18 @@ void watchdog_init() {
#endif #endif
} }
/// reset watchdog. MUST be called every 1s after init or avr will reset.
void watchdog_reset() {
wdt_reset();
}
//=========================================================================== //===========================================================================
//=================================== ISR =================================== //=================================== ISR ===================================
//=========================================================================== //===========================================================================
//Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled. // Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled.
#if ENABLED(WATCHDOG_RESET_MANUAL) #if ENABLED(WATCHDOG_RESET_MANUAL)
ISR(WDT_vect) { ISR(WDT_vect) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer."); SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
kill(PSTR("ERR:Please Reset")); //kill blocks //16 characters so it fits on a 16x2 display kill(PSTR("ERR:Please Reset")); //kill blocks //16 characters so it fits on a 16x2 display
while (1); //wait for user or serial reset while (1); //wait for user or serial reset
} }
#endif//RESET_MANUAL #endif //WATCHDOG_RESET_MANUAL
#endif//USE_WATCHDOG #endif //USE_WATCHDOG

@ -2,16 +2,13 @@
#define WATCHDOG_H #define WATCHDOG_H
#include "Marlin.h" #include "Marlin.h"
#include <avr/wdt.h>
#if ENABLED(USE_WATCHDOG) // Initialize watchdog with a 4 second interrupt time
// initialize watch dog with a 1 sec interrupt time void watchdog_init();
void watchdog_init();
// pad the dog/reset watchdog. MUST be called at least every second after the first watchdog_init or AVR will go into emergency procedures.. // Reset watchdog. MUST be called at least every 4 seconds after the
void watchdog_reset(); // first watchdog_init or AVR will go into emergency procedures.
#else inline void watchdog_reset() { wdt_reset(); }
//If we do not have a watchdog, then we can have empty functions which are optimized away.
FORCE_INLINE void watchdog_init() {};
FORCE_INLINE void watchdog_reset() {};
#endif
#endif #endif

Loading…
Cancel
Save