From 7cc358b56b02a121e90e1c5a80ccc91d328487b0 Mon Sep 17 00:00:00 2001 From: Bernhard Kubicek <kubicek@gmx.at> Date: Sun, 6 Nov 2011 14:58:12 +0100 Subject: [PATCH] wrong file location --- Marlin/watchdog.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ Marlin/watchdog.h | 10 ++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Marlin/watchdog.cpp create mode 100644 Marlin/watchdog.h diff --git a/Marlin/watchdog.cpp b/Marlin/watchdog.cpp new file mode 100644 index 00000000000..0adf9cc7d7c --- /dev/null +++ b/Marlin/watchdog.cpp @@ -0,0 +1,48 @@ +#ifdef USE_WATCHDOG + +#include <avr/wdt.h> +#include <avr/interrupt.h> + +volatile uint8_t timeout_seconds=0; + +void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560 + +//Watchdog timer interrupt, called if main program blocks >1sec +ISR(WDT_vect) +{ + if(timeout_seconds++ >= WATCHDOG_TIMEOUT) + { + + #ifdef RESET_MANUAL + LCD_MESSAGE("Please Reset!"); + ECHOLN("echo_: Something is wrong, please turn off the printer."); + #else + LCD_MESSAGE("Timeout, resetting!"); + #endif + //disable watchdog, it will survife reboot. + WDTCSR |= (1<<WDCE) | (1<<WDE); + WDTCSR = 0; + #ifdef RESET_MANUAL + kill(); //kill blocks + while(1); //wait for user or serial reset + #else + ctrlaltdelete(); + #endif + } +} + +/// intialise watch dog with a 1 sec interrupt time +void wd_init() +{ + WDTCSR = (1<<WDCE )|(1<<WDE ); //allow changes + WDTCSR = (1<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )| (1<<WDP2 )|(1<<WDP1)|(0<<WDP0); +} + +/// reset watchdog. MUST be called every 1s after init or avr will reset. +void wd_reset() +{ + wdt_reset(); + timeout_seconds=0; //reset counter for resets +} + +#endif /* USE_WATCHDOG */ diff --git a/Marlin/watchdog.h b/Marlin/watchdog.h new file mode 100644 index 00000000000..2577bc13843 --- /dev/null +++ b/Marlin/watchdog.h @@ -0,0 +1,10 @@ +#ifndef __WATCHDOGH +#define __WATCHDOGH +#ifdef +/// intialise watch dog with a 1 sec interrupt time +void wd_init(); +/// pad the dog/reset watchdog. MUST be called at least every second after the first wd_init or avr will go into emergency procedures.. +void wd_reset(); + + +#endif