Browse Source

watchdog into dedicated file

Bernhard Kubicek 12 years ago
parent
commit
e8092898b1
4 changed files with 73 additions and 55 deletions
  1. 15
    1
      Marlin/Marlin.h
  2. 0
    54
      Marlin/Marlin.pde
  3. 48
    0
      watchdog.cpp
  4. 10
    0
      watchdog.h

+ 15
- 1
Marlin/Marlin.h View File

@@ -78,5 +78,19 @@ void enquecommand(const char *cmd);
78 78
 extern float homing_feedrate[];
79 79
 extern bool axis_relative_modes[];
80 80
 
81
-void wd_reset() ;
81
+
82
+inline void kill()
83
+{
84
+  disable_heater();
85
+
86
+  disable_x();
87
+  disable_y();
88
+  disable_z();
89
+  disable_e();
90
+  
91
+  if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
92
+  Serial.println("!! Printer halted. kill() called !!");
93
+  while(1); // Wait for reset
94
+}
95
+
82 96
 #endif

+ 0
- 54
Marlin/Marlin.pde View File

@@ -1263,63 +1263,9 @@ void prepare_arc_move(char isclockwise) {
1263 1263
   }
1264 1264
 }
1265 1265
 
1266
-#ifdef USE_WATCHDOG
1267 1266
 
1268
-#include  <avr/wdt.h>
1269
-#include  <avr/interrupt.h>
1270 1267
 
1271
-volatile uint8_t timeout_seconds=0;
1272 1268
 
1273
-void(* ctrlaltdelete) (void) = 0;
1274
-
1275
-ISR(WDT_vect) { //Watchdog timer interrupt, called if main program blocks >1sec
1276
-  if(timeout_seconds++ >= WATCHDOG_TIMEOUT)
1277
-  {
1278
-   kill();
1279
-#ifdef RESET_MANUAL
1280
-    LCD_MESSAGE("Please Reset!");
1281
-    ECHOLN("echo_: Something is wrong, please turn off the printer.");
1282
-#else
1283
-    LCD_MESSAGE("Timeout, resetting!");
1284
-#endif 
1285
-    //disable watchdog, it will survife reboot.
1286
-    WDTCSR |= (1<<WDCE) | (1<<WDE);
1287
-    WDTCSR = 0;
1288
-#ifdef RESET_MANUAL
1289
-    while(1); //wait for user or serial reset
1290
-#else
1291
-    ctrlaltdelete();
1292
-#endif
1293
-  }
1294
-}
1295
-
1296
-/// intialise watch dog with a 1 sec interrupt time
1297
-void wd_init() {
1298
-  WDTCSR = (1<<WDCE )|(1<<WDE ); //allow changes
1299
-  WDTCSR = (1<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )|  (1<<WDP2 )|(1<<WDP1)|(0<<WDP0);
1300
-}
1301
-
1302
-/// reset watchdog. MUST be called every 1s after init or avr will reset.
1303
-void wd_reset() {
1304
-  wdt_reset();
1305
-  timeout_seconds=0; //reset counter for resets
1306
-}
1307
-#endif /* USE_WATCHDOG */
1308
-
1309
-
1310
-inline void kill()
1311
-{
1312
-  disable_heater();
1313
-
1314
-  disable_x();
1315
-  disable_y();
1316
-  disable_z();
1317
-  disable_e();
1318
-  
1319
-  if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
1320
-  Serial.println("!! Printer halted. kill() called !!");
1321
-  while(1); // Wait for reset
1322
-}
1323 1269
 
1324 1270
 void manage_inactivity(byte debug) { 
1325 1271
   if( (millis()-previous_millis_cmd) >  max_inactive_time ) if(max_inactive_time) kill(); 

+ 48
- 0
watchdog.cpp View File

@@ -0,0 +1,48 @@
1
+#ifdef USE_WATCHDOG
2
+
3
+#include  <avr/wdt.h>
4
+#include  <avr/interrupt.h>
5
+
6
+volatile uint8_t timeout_seconds=0;
7
+
8
+void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560
9
+
10
+//Watchdog timer interrupt, called if main program blocks >1sec
11
+ISR(WDT_vect) 
12
+{ 
13
+  if(timeout_seconds++ >= WATCHDOG_TIMEOUT)
14
+  {
15
+ 
16
+    #ifdef RESET_MANUAL
17
+      LCD_MESSAGE("Please Reset!");
18
+      ECHOLN("echo_: Something is wrong, please turn off the printer.");
19
+    #else
20
+      LCD_MESSAGE("Timeout, resetting!");
21
+    #endif 
22
+    //disable watchdog, it will survife reboot.
23
+    WDTCSR |= (1<<WDCE) | (1<<WDE);
24
+    WDTCSR = 0;
25
+    #ifdef RESET_MANUAL
26
+      kill(); //kill blocks
27
+      while(1); //wait for user or serial reset
28
+    #else
29
+      ctrlaltdelete();
30
+    #endif
31
+  }
32
+}
33
+
34
+/// intialise watch dog with a 1 sec interrupt time
35
+void wd_init() 
36
+{
37
+  WDTCSR = (1<<WDCE )|(1<<WDE ); //allow changes
38
+  WDTCSR = (1<<WDIF)|(1<<WDIE)| (1<<WDCE )|(1<<WDE )|  (1<<WDP2 )|(1<<WDP1)|(0<<WDP0);
39
+}
40
+
41
+/// reset watchdog. MUST be called every 1s after init or avr will reset.
42
+void wd_reset() 
43
+{
44
+  wdt_reset();
45
+  timeout_seconds=0; //reset counter for resets
46
+}
47
+
48
+#endif /* USE_WATCHDOG */

+ 10
- 0
watchdog.h View File

@@ -0,0 +1,10 @@
1
+#ifndef __WATCHDOGH
2
+#define __WATCHDOGH
3
+#ifdef
4
+/// intialise watch dog with a 1 sec interrupt time
5
+void wd_init();
6
+/// pad the dog/reset watchdog. MUST be called at least every second after the first wd_init or avr will go into emergency procedures..
7
+void wd_reset();
8
+
9
+
10
+#endif

Loading…
Cancel
Save