From 834ae6d1d52cdb1fa55a3dc81f202160273c1aa2 Mon Sep 17 00:00:00 2001 From: Ted Hess Date: Thu, 15 Mar 2018 10:35:52 -0400 Subject: [PATCH] Remove private watchdog and use built-in wdt instead --- Firmware/Configuration.h | 2 +- Firmware/Configuration_adv.h | 14 +++------ Firmware/Marlin_main.cpp | 16 +++++++---- Firmware/temperature.cpp | 8 ++++-- Firmware/watchdog.cpp | 56 ------------------------------------ Firmware/watchdog.h | 17 ----------- 6 files changed, 22 insertions(+), 91 deletions(-) delete mode 100644 Firmware/watchdog.cpp delete mode 100644 Firmware/watchdog.h diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 491a446ba..aacc61c29 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -10,7 +10,7 @@ // Firmware version #define FW_version "3.1.0" -#define FW_local_variant 9 +#define FW_local_variant 10 #define FW_report_version FW_version " r" STR(FW_local_variant) #define FW_PRUSA3D_MAGIC "PRUSA3DFW" diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index c9d608ce8..478603f64 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -217,6 +217,10 @@ //=============================Additional Features=========================== //=========================================================================== +// The hardware watchdog should reset the microcontroller disabling all outputs +// in case the firmware gets stuck and doesn't do temperature regulation. +//#define WATCHDOG + //#define CHDK 4 //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/ #define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again @@ -291,16 +295,6 @@ //#define PROGRESS_MSG_ONCE #endif -// The hardware watchdog should reset the microcontroller disabling all outputs, in case the firmware gets stuck and doesn't do temperature regulation. -//#define USE_WATCHDOG - -#ifdef USE_WATCHDOG -// If you have a watchdog reboot in an ArduinoMega2560 then the device will hang forever, as a watchdog reset will leave the watchdog on. -// The "WATCHDOG_RESET_MANUAL" goes around this by not using the hardware reset. -// However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled. -//#define WATCHDOG_RESET_MANUAL -#endif - // Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled. //#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 9b6027c60..a0aaec9b5 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -48,14 +48,15 @@ #include "temperature.h" #include "motion_control.h" #include "cardreader.h" -#include "watchdog.h" #include "ConfigurationStore.h" #include "language.h" #include "pins_arduino.h" #include "math.h" #include "util.h" +#ifdef WATCHDOG #include +#endif #ifdef BLINKM #include "BlinkM.h" @@ -1103,7 +1104,6 @@ void setup() SdFatUtil::set_stack_guard(); //writes magic number at the end of static variables to protect against overwriting static memory by stack tp_init(); // Initialize temperature loop plan_init(); // Initialize planner; - watchdog_init(); st_init(); // Initialize stepper, this enables interrupts! setup_photpin(); servo_init(); @@ -1282,6 +1282,9 @@ void setup() // so the next time the firmware gets updated, it will know from which version it has been updated. update_current_firmware_version_to_eeprom(); KEEPALIVE_STATE(NOT_BUSY); +#ifdef WATCHDOG + wdt_enable(WDTO_4S); +#endif } void trace(); @@ -6582,9 +6585,12 @@ void kill(const char *full_screen_message) #endif suicide(); // Wait for reset - while(1) { - // nice doggie - watchdog_reset(); + while(1) { +#ifdef WATCHDOG + // nice doggie + wdt_reset(); +#endif + _delay_ms(20); } } diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 48c0cb8ce..c72363e4a 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -32,11 +32,13 @@ #include "Marlin.h" #include "ultralcd.h" #include "temperature.h" -#include "watchdog.h" #include "cardreader.h" #include "Sd2PinMap.h" +#ifdef WATCHDOG +#include +#endif //=========================================================================== //=============================public variables============================ @@ -841,7 +843,9 @@ static void updateTemperaturesFromRawValues() filament_width_meas = analog2widthFil(); #endif //Reset the watchdog after we know we have a temperature measurement. - watchdog_reset(); + #ifdef WATCHDOG + wdt_reset(); + #endif CRITICAL_SECTION_START; temp_meas_ready = false; diff --git a/Firmware/watchdog.cpp b/Firmware/watchdog.cpp deleted file mode 100644 index b378ca706..000000000 --- a/Firmware/watchdog.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "Marlin.h" - -#ifdef USE_WATCHDOG -#include - -#include "watchdog.h" -#include "ultralcd.h" - -//=========================================================================== -//=============================private variables ============================ -//=========================================================================== - -//=========================================================================== -//=============================functinos ============================ -//=========================================================================== - - -/// intialise watch dog with a 4 sec interrupt time -void watchdog_init() -{ -#ifdef WATCHDOG_RESET_MANUAL - //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. - wdt_reset(); - _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE); - _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S; -#else - wdt_enable(WDTO_4S); -#endif -} - -/// reset watchdog. MUST be called every 1s after init or avr will reset. -void watchdog_reset() -{ - wdt_reset(); -} - -//=========================================================================== -//=============================ISR ============================ -//=========================================================================== - -//Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled. -#ifdef WATCHDOG_RESET_MANUAL -ISR(WDT_vect) -{ - //TODO: This message gets overwritten by the kill() call - LCD_ALERTMESSAGEPGM("ERR:Please Reset");//16 characters so it fits on a 16x2 display - lcd_update(); - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer."); - kill(); //kill blocks - while(1); //wait for user or serial reset -} -#endif//RESET_MANUAL - -#endif//USE_WATCHDOG diff --git a/Firmware/watchdog.h b/Firmware/watchdog.h deleted file mode 100644 index a73f3a846..000000000 --- a/Firmware/watchdog.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WATCHDOG_H -#define WATCHDOG_H - -#include "Marlin.h" - -#ifdef USE_WATCHDOG - // initialize watch dog with a 1 sec interrupt time - 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.. - void watchdog_reset(); -#else - //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