瀏覽代碼

Remove duplication in crash handlers

It's kind of nice that all handlers eventually came to become the same.
Yuri D'Elia 3 年之前
父節點
當前提交
96aad0a475
共有 1 個文件被更改,包括 15 次插入25 次删除
  1. 15 25
      Firmware/Marlin_main.cpp

+ 15 - 25
Firmware/Marlin_main.cpp

@@ -1715,46 +1715,36 @@ void setup()
 #endif //WATCHDOG
 }
 
-#if defined(WATCHDOG) && defined(EMERGENCY_HANDLERS)
-ISR(WDT_vect)
+
+static inline void crash_and_burn(dump_crash_reason reason)
 {
     WRITE(BEEPER, HIGH);
-    eeprom_update_byte((uint8_t*)EEPROM_FW_CRASH_FLAG, (uint8_t)dump_crash_reason::watchdog);
+    eeprom_update_byte((uint8_t*)EEPROM_FW_CRASH_FLAG, (uint8_t)reason);
 #ifdef EMERGENCY_DUMP
-    xfdump_full_dump_and_reset(dump_crash_reason::watchdog);
+    xfdump_full_dump_and_reset(reason);
 #elif defined(EMERGENCY_SERIAL_DUMP)
     if(emergency_serial_dump)
-        serial_dump_and_reset(dump_crash_reason::watchdog);
+        serial_dump_and_reset(reason);
 #endif
     softReset();
 }
-#endif
 
 #ifdef EMERGENCY_HANDLERS
-ISR(BADISR_vect)
+#ifdef WATCHDOG
+ISR(WDT_vect)
 {
-    WRITE(BEEPER, HIGH);
-    eeprom_update_byte((uint8_t*)EEPROM_FW_CRASH_FLAG, (uint8_t)dump_crash_reason::bad_isr);
-#ifdef EMERGENCY_DUMP
-    xfdump_full_dump_and_reset(dump_crash_reason::bad_isr);
-#elif defined(EMERGENCY_SERIAL_DUMP)
-    if(emergency_serial_dump)
-        serial_dump_and_reset(dump_crash_reason::bad_isr);
-#endif
-    softReset();
+    crash_and_burn(dump_crash_reason::watchdog);
 }
 #endif
 
+ISR(BADISR_vect)
+{
+    crash_and_burn(dump_crash_reason::bad_isr);
+}
+#endif //EMERGENCY_HANDLERS
+
 void stack_error() {
-    WRITE(BEEPER, HIGH);
-    eeprom_update_byte((uint8_t*)EEPROM_FW_CRASH_FLAG, (uint8_t)dump_crash_reason::stack_error);
-#ifdef EMERGENCY_DUMP
-    xfdump_full_dump_and_reset(dump_crash_reason::stack_error);
-#elif defined(EMERGENCY_SERIAL_DUMP)
-    if (emergency_serial_dump)
-        serial_dump_and_reset(dump_crash_reason::stack_error);
-#endif
-    softReset();
+    crash_and_burn(dump_crash_reason::stack_error);
 }