chiark / gitweb /
watchdog into dedicated file
authorBernhard Kubicek <kubicek@gmx.at>
Sun, 6 Nov 2011 13:22:15 +0000 (14:22 +0100)
committerBernhard Kubicek <kubicek@gmx.at>
Sun, 6 Nov 2011 13:22:15 +0000 (14:22 +0100)
Marlin/Marlin.h
Marlin/Marlin.pde
watchdog.cpp [new file with mode: 0644]
watchdog.h [new file with mode: 0644]

index 15e6570c938da83ce2b0d8cfd7153cb67deea489..07dd0d8bf17bcb6086e992ace53d75f50fe310e3 100644 (file)
@@ -78,5 +78,19 @@ void enquecommand(const char *cmd);
 extern float homing_feedrate[];
 extern bool axis_relative_modes[];
 
-void wd_reset() ;
+
+inline void kill()
+{
+  disable_heater();
+
+  disable_x();
+  disable_y();
+  disable_z();
+  disable_e();
+  
+  if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
+  Serial.println("!! Printer halted. kill() called !!");
+  while(1); // Wait for reset
+}
+
 #endif
index 698b137803fcf9b406b85d5bcdbfb2f3eb9846af..6a6fb80f43e1ddb8570e580857c882caecbf865a 100644 (file)
@@ -1263,63 +1263,9 @@ void prepare_arc_move(char isclockwise) {
   }
 }
 
-#ifdef USE_WATCHDOG
 
-#include  <avr/wdt.h>
-#include  <avr/interrupt.h>
 
-volatile uint8_t timeout_seconds=0;
 
-void(* ctrlaltdelete) (void) = 0;
-
-ISR(WDT_vect) { //Watchdog timer interrupt, called if main program blocks >1sec
-  if(timeout_seconds++ >= WATCHDOG_TIMEOUT)
-  {
-   kill();
-#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
-    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 */
-
-
-inline void kill()
-{
-  disable_heater();
-
-  disable_x();
-  disable_y();
-  disable_z();
-  disable_e();
-  
-  if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
-  Serial.println("!! Printer halted. kill() called !!");
-  while(1); // Wait for reset
-}
 
 void manage_inactivity(byte debug) { 
   if( (millis()-previous_millis_cmd) >  max_inactive_time ) if(max_inactive_time) kill(); 
diff --git a/watchdog.cpp b/watchdog.cpp
new file mode 100644 (file)
index 0000000..0adf9cc
--- /dev/null
@@ -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/watchdog.h b/watchdog.h
new file mode 100644 (file)
index 0000000..2577bc1
--- /dev/null
@@ -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