2011-11-06 07:58:12 -06:00
|
|
|
#ifdef USE_WATCHDOG
|
2011-12-22 07:55:45 -06:00
|
|
|
#include "Marlin.h"
|
2011-11-06 08:10:29 -06:00
|
|
|
#include "watchdog.h"
|
2011-11-06 07:58:12 -06:00
|
|
|
|
2011-11-06 16:34:40 -06:00
|
|
|
//===========================================================================
|
|
|
|
//=============================private variables ============================
|
|
|
|
//===========================================================================
|
|
|
|
|
2011-11-06 12:23:08 -06:00
|
|
|
static volatile uint8_t timeout_seconds=0;
|
2011-11-06 07:58:12 -06:00
|
|
|
|
|
|
|
void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560
|
|
|
|
|
2011-11-06 16:34:40 -06:00
|
|
|
//===========================================================================
|
|
|
|
//=============================functinos ============================
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/// intialise watch dog with a 1 sec interrupt time
|
|
|
|
void wd_init()
|
|
|
|
{
|
2011-11-18 11:59:17 -06:00
|
|
|
WDTCSR |= (1<<WDCE )|(1<<WDE ); //allow changes
|
|
|
|
WDTCSR = (1<<WDCE )|(1<<WDE )|(1<<WDP3 )|(1<<WDP0); // Reset after 8 sec.
|
|
|
|
// WDTCSR = (1<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )| (1<<WDP3) | (1<<WDP0);
|
2011-11-06 16:34:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// reset watchdog. MUST be called every 1s after init or avr will reset.
|
|
|
|
void wd_reset()
|
|
|
|
{
|
|
|
|
wdt_reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//=============================ISR ============================
|
|
|
|
//===========================================================================
|
|
|
|
|
2011-11-06 07:58:12 -06:00
|
|
|
//Watchdog timer interrupt, called if main program blocks >1sec
|
|
|
|
ISR(WDT_vect)
|
|
|
|
{
|
|
|
|
if(timeout_seconds++ >= WATCHDOG_TIMEOUT)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef RESET_MANUAL
|
2011-11-09 13:27:15 -06:00
|
|
|
LCD_MESSAGEPGM("Please Reset!");
|
2011-11-15 13:54:40 -06:00
|
|
|
LCD_STATUS;
|
2011-11-09 13:27:15 -06:00
|
|
|
SERIAL_ERROR_START;
|
|
|
|
SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
|
2011-11-06 07:58:12 -06:00
|
|
|
#else
|
2011-11-09 13:27:15 -06:00
|
|
|
LCD_MESSAGEPGM("Timeout, resetting!");
|
2011-11-15 13:54:40 -06:00
|
|
|
LCD_STATUS;
|
2011-11-06 07:58:12 -06:00
|
|
|
#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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_WATCHDOG */
|