Browse Source

Fix kill => disable_all_heaters => print_job_timer.stop (#12146)

- Remove `print_job_timer.stop()` from `disable_all_heaters`
- Call `print_job_timer.stop()` for relevant `disable_all_heaters()`.
- Split up `kill()` for watchdog interrupt safety
Marcio Teixeira 5 years ago
parent
commit
71e19baf69

+ 2
- 3
Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp View File

@@ -63,9 +63,8 @@ void watchdog_init() {
63 63
   ISR(WDT_vect) {
64 64
     sei();  // With the interrupt driven serial we need to allow interrupts.
65 65
     SERIAL_ERROR_START();
66
-    SERIAL_ERRORLNPGM("Watchdog barked, please turn off the printer.");
67
-    kill(PSTR("ERR:Watchdog")); //kill blocks //up to 16 characters so it fits on a 16x2 display
68
-    while (1); //wait for user or serial reset
66
+    SERIAL_ERRORLNPGM(MSG_WATCHDOG_FIRED);
67
+    minkill();  // interrupt-safe final kill and infinite loop
69 68
   }
70 69
 #endif // WATCHDOG_RESET_MANUAL
71 70
 

+ 18
- 14
Marlin/src/Marlin.cpp View File

@@ -351,7 +351,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
351 351
   if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) {
352 352
     SERIAL_ERROR_START();
353 353
     SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr);
354
-    kill(PSTR(MSG_KILLED));
354
+    kill();
355 355
   }
356 356
 
357 357
   // Prevent steppers timing-out in the middle of M600
@@ -408,7 +408,7 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
408 408
     if (killCount >= KILL_DELAY) {
409 409
       SERIAL_ERROR_START();
410 410
       SERIAL_ERRORLNPGM(MSG_KILL_BUTTON);
411
-      kill(PSTR(MSG_KILLED));
411
+      kill();
412 412
     }
413 413
   #endif
414 414
 
@@ -609,7 +609,7 @@ void idle(
609 609
  * Kill all activity and lock the machine.
610 610
  * After this the machine will need to be reset.
611 611
  */
612
-void kill(PGM_P lcd_msg) {
612
+void kill(PGM_P const lcd_msg/*=NULL*/) {
613 613
   SERIAL_ERROR_START();
614 614
   SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
615 615
 
@@ -617,23 +617,28 @@ void kill(PGM_P lcd_msg) {
617 617
   disable_all_steppers();
618 618
 
619 619
   #if ENABLED(EXTENSIBLE_UI)
620
-    UI::onPrinterKilled(lcd_msg);
620
+    UI::onPrinterKilled(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
621 621
   #elif ENABLED(ULTRA_LCD)
622
-    kill_screen(lcd_msg);
622
+    kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
623 623
   #else
624 624
     UNUSED(lcd_msg);
625 625
   #endif
626 626
 
627
-  _delay_ms(600); // Wait a short time (allows messages to get out before shutting down.
628
-  cli(); // Stop interrupts
629
-
630
-  _delay_ms(250); //Wait to ensure all interrupts routines stopped
631
-  thermalManager.disable_all_heaters(); //turn off heaters again
632
-
633 627
   #ifdef ACTION_ON_KILL
634 628
     SERIAL_ECHOLNPGM("//action:" ACTION_ON_KILL);
635 629
   #endif
636 630
 
631
+  minkill();
632
+}
633
+
634
+void minkill() {
635
+
636
+  _delay_ms(600); // Wait a short time (allows messages to get out before shutting down.
637
+  cli(); // Stop interrupts
638
+  _delay_ms(250); // Wait to ensure all interrupts stopped
639
+
640
+  thermalManager.disable_all_heaters(); // turn off heaters again
641
+
637 642
   #if HAS_POWER_SWITCH
638 643
     PSU_OFF();
639 644
   #endif
@@ -655,6 +660,7 @@ void kill(PGM_P lcd_msg) {
655 660
  */
656 661
 void stop() {
657 662
   thermalManager.disable_all_heaters(); // 'unpause' taken care of in here
663
+  print_job_timer.stop();
658 664
 
659 665
   #if ENABLED(PROBING_FANS_OFF)
660 666
     if (fans_paused) fans_pause(false); // put things back the way they were
@@ -979,9 +985,7 @@ void loop() {
979 985
         quickstop_stepper();
980 986
         print_job_timer.stop();
981 987
         thermalManager.disable_all_heaters();
982
-        #if FAN_COUNT > 0
983
-          for (uint8_t i = 0; i < FAN_COUNT; i++) fan_speed[i] = 0;
984
-        #endif
988
+        zero_fan_speeds();
985 989
         wait_for_heatup = false;
986 990
         #if ENABLED(POWER_LOSS_RECOVERY)
987 991
           card.removeJobRecoveryFile();

+ 8
- 1
Marlin/src/Marlin.h View File

@@ -180,7 +180,8 @@ void disable_e_stepper(const uint8_t e);
180 180
 void disable_e_steppers();
181 181
 void disable_all_steppers();
182 182
 
183
-void kill(PGM_P);
183
+void kill(PGM_P const lcd_msg=NULL);
184
+void minkill();
184 185
 
185 186
 void quickstop_stepper();
186 187
 
@@ -218,6 +219,12 @@ extern millis_t max_inactive_time, stepper_inactive_time;
218 219
   #endif
219 220
 #endif
220 221
 
222
+inline void zero_fan_speeds() {
223
+  #if FAN_COUNT > 0
224
+    LOOP_L_N(i, FAN_COUNT) fan_speed[i] = 0;
225
+  #endif
226
+}
227
+
221 228
 #if ENABLED(USE_CONTROLLER_FAN)
222 229
   extern uint8_t controllerfan_speed;
223 230
 #endif

+ 1
- 0
Marlin/src/core/language.h View File

@@ -131,6 +131,7 @@
131 131
 #define MSG_M115_REPORT                     "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID
132 132
 #define MSG_COUNT_X                         " Count X:"
133 133
 #define MSG_COUNT_A                         " Count A:"
134
+#define MSG_WATCHDOG_FIRED                  "Watchdog timeout. Reset required."
134 135
 #define MSG_ERR_KILLED                      "Printer halted. kill() called!"
135 136
 #define MSG_ERR_STOPPED                     "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"
136 137
 #define MSG_BUSY_PROCESSING                 "busy: processing"

+ 1
- 1
Marlin/src/feature/I2CPositionEncoder.cpp View File

@@ -164,7 +164,7 @@ void I2CPositionEncoder::update() {
164 164
 
165 165
     #ifdef I2CPE_ERR_THRESH_ABORT
166 166
       if (ABS(error) > I2CPE_ERR_THRESH_ABORT * planner.settings.axis_steps_per_mm[encoderAxis]) {
167
-        //kill("Significant Error");
167
+        //kill(PSTR("Significant Error"));
168 168
         SERIAL_ECHOPGM("Axis error greater than set threshold, aborting!");
169 169
         SERIAL_ECHOLN(error);
170 170
         safe_delay(5000);

+ 1
- 1
Marlin/src/gcode/control/M108_M112_M410.cpp View File

@@ -41,7 +41,7 @@ void GcodeSuite::M108() {
41 41
  * M112: Emergency Stop
42 42
  */
43 43
 void GcodeSuite::M112() {
44
-  kill(PSTR(MSG_KILLED));
44
+  kill();
45 45
 }
46 46
 
47 47
 /**

+ 3
- 1
Marlin/src/gcode/control/M80_M81.cpp View File

@@ -23,6 +23,7 @@
23 23
 #include "../gcode.h"
24 24
 #include "../../module/temperature.h"
25 25
 #include "../../module/stepper.h"
26
+#include "../../module/printcounter.h" // for print_job_timer
26 27
 
27 28
 #include "../../inc/MarlinConfig.h"
28 29
 
@@ -95,10 +96,11 @@
95 96
  */
96 97
 void GcodeSuite::M81() {
97 98
   thermalManager.disable_all_heaters();
99
+  print_job_timer.stop();
98 100
   planner.finish_and_disable();
99 101
 
100 102
   #if FAN_COUNT > 0
101
-    for (uint8_t i = 0; i < FAN_COUNT; i++) fan_speed[i] = 0;
103
+    zero_fan_speeds();
102 104
     #if ENABLED(PROBING_FANS_OFF)
103 105
       fans_paused = false;
104 106
       ZERO(paused_fan_speed);

+ 1
- 1
Marlin/src/gcode/queue.cpp View File

@@ -391,7 +391,7 @@ inline void get_serial_commands() {
391 391
               wait_for_user = false;
392 392
             #endif
393 393
           }
394
-          if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
394
+          if (strcmp(command, "M112") == 0) kill();
395 395
           if (strcmp(command, "M410") == 0) quickstop_stepper();
396 396
         #endif
397 397
 

+ 1
- 3
Marlin/src/lcd/malyanlcd.cpp View File

@@ -254,9 +254,7 @@ void process_lcd_p_command(const char* command) {
254 254
         quickstop_stepper();
255 255
         print_job_timer.stop();
256 256
         thermalManager.disable_all_heaters();
257
-        #if FAN_COUNT > 0
258
-          for (uint8_t i = 0; i < FAN_COUNT; i++) fan_speed[i] = 0;
259
-        #endif
257
+        zero_fan_speeds();
260 258
         wait_for_heatup = false;
261 259
         write_to_lcd_P(PSTR("{SYS:STARTED}"));
262 260
       #endif

+ 1
- 3
Marlin/src/lcd/ultralcd.cpp View File

@@ -1918,9 +1918,7 @@ void lcd_quick_feedback(const bool clear_buttons) {
1918 1918
   #endif // HAS_TEMP_HOTEND || HAS_HEATED_BED
1919 1919
 
1920 1920
   void lcd_cooldown() {
1921
-    #if FAN_COUNT > 0
1922
-      for (uint8_t i = 0; i < FAN_COUNT; i++) fan_speed[i] = 0;
1923
-    #endif
1921
+    zero_fan_speeds();
1924 1922
     thermalManager.disable_all_heaters();
1925 1923
     lcd_return_to_status();
1926 1924
   }

+ 6
- 1
Marlin/src/module/endstops.cpp View File

@@ -36,6 +36,10 @@
36 36
   #include HAL_PATH(../HAL, endstop_interrupts.h)
37 37
 #endif
38 38
 
39
+#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
40
+  #include "../module/printcounter.h" // for print_job_timer
41
+#endif
42
+
39 43
 Endstops endstops;
40 44
 
41 45
 // public:
@@ -359,7 +363,8 @@ void Endstops::event_handler() {
359 363
         card.sdprinting = false;
360 364
         card.closefile();
361 365
         quickstop_stepper();
362
-        thermalManager.disable_all_heaters(); // switch off all heaters.
366
+        thermalManager.disable_all_heaters();
367
+        print_job_timer.stop();
363 368
       }
364 369
     #endif
365 370
   }

+ 3
- 6
Marlin/src/module/temperature.cpp View File

@@ -304,7 +304,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
304 304
 
305 305
     SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
306 306
 
307
-    disable_all_heaters(); // switch off all heaters.
307
+    disable_all_heaters();
308 308
 
309 309
     SHV(soft_pwm_amount, bias = d = (MAX_BED_POWER) >> 1, bias = d = (PID_MAX) >> 1);
310 310
 
@@ -779,7 +779,7 @@ void Temperature::manage_heater() {
779 779
   #endif
780 780
 
781 781
   #if ENABLED(EMERGENCY_PARSER)
782
-    if (emergency_parser.killed_by_M112) kill(PSTR(MSG_KILLED));
782
+    if (emergency_parser.killed_by_M112) kill();
783 783
   #endif
784 784
 
785 785
   if (!temp_meas_ready) return;
@@ -949,7 +949,7 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
949 949
       SERIAL_ERROR_START();
950 950
       SERIAL_ERROR((int)e);
951 951
       SERIAL_ERRORLNPGM(MSG_INVALID_EXTRUDER_NUM);
952
-      kill(PSTR(MSG_KILLED));
952
+      kill();
953 953
       return 0.0;
954 954
     }
955 955
 
@@ -1551,9 +1551,6 @@ void Temperature::disable_all_heaters() {
1551 1551
     pause(false);
1552 1552
   #endif
1553 1553
 
1554
-  // If all heaters go down then for sure our print job has stopped
1555
-  print_job_timer.stop();
1556
-
1557 1554
   #define DISABLE_HEATER(NR) { \
1558 1555
     setTargetHotend(0, NR); \
1559 1556
     soft_pwm_amount[NR] = 0; \

+ 1
- 1
Marlin/src/sd/cardreader.cpp View File

@@ -394,7 +394,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall
394 394
         SERIAL_ERROR_START();
395 395
         SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
396 396
         SERIAL_ERRORLN((int)SD_PROCEDURE_DEPTH);
397
-        kill(PSTR(MSG_KILLED));
397
+        kill();
398 398
         return;
399 399
       }
400 400
 

+ 1
- 1
Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp View File

@@ -38,7 +38,7 @@ Sd2Card::state_t Sd2Card::state;
38 38
 
39 39
 // The USB library needs to be called periodically to detect USB thumbdrive
40 40
 // insertion and removals. Call this idle() function periodically to allow
41
-// the USB libary to monitor for such events. This function also takes care
41
+// the USB library to monitor for such events. This function also takes care
42 42
 // of initializing the USB library for the first time.
43 43
 
44 44
 void Sd2Card::idle() {

Loading…
Cancel
Save