Browse Source

xfdump: report to the host that a dump is available

As suggested by @3d-gussner, announce to the host that a dump is
available for retrieval using an action "dump_available".

Any kind of dump is announced (even if manually triggered).

To avoid reading from xflash twice, remove some duplication and return
the crash reason directly in xfdump_check_state().
Yuri D'Elia 2 years ago
parent
commit
3187b96ca4
3 changed files with 32 additions and 25 deletions
  1. 21 9
      Firmware/Marlin_main.cpp
  2. 8 14
      Firmware/xflash_dump.cpp
  3. 3 2
      Firmware/xflash_dump.h

+ 21 - 9
Firmware/Marlin_main.cpp

@@ -108,7 +108,7 @@
 #include "optiboot_xflash.h"
 #endif //XFLASH
 
-#ifdef EMERGENCY_DUMP
+#ifdef XFLASH_DUMP
 #include "xflash_dump.h"
 #endif
 
@@ -1610,15 +1610,27 @@ void setup()
 	if (tmc2130_home_enabled == 0xff) tmc2130_home_enabled = 0;
 #endif //TMC2130
 
-#ifdef EMERGENCY_DUMP
-    if(xfdump_check_crash() && eeprom_read_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED) != 1)
+#ifdef XFLASH_DUMP
     {
-        // prevent the prompt to reappear once acknowledged
-        eeprom_update_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED, 1);
-        lcd_show_fullscreen_message_and_wait_P(
-                _i("!!!FIRMWARE CRASH!!!\n"
-                   "Debug data available for analysis. "
-                   "Contact support to submit details."));
+        dump_crash_reason crash_reason;
+        if(xfdump_check_state(&crash_reason))
+        {
+            // always signal to the host that a dump is available for retrieval
+            puts_P(_N("// action:dump_available"));
+
+#ifdef EMERGENCY_DUMP
+            if(crash_reason != dump_crash_reason::manual &&
+               eeprom_read_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED) != 1)
+            {
+                // prevent the prompt to reappear once acknowledged
+                eeprom_update_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED, 1);
+                lcd_show_fullscreen_message_and_wait_P(
+                        _i("!!!FIRMWARE CRASH!!!\n"
+                           "Debug data available for analysis. "
+                           "Contact support to submit details."));
+            }
+#endif
+        }
     }
 #endif
 

+ 8 - 14
Firmware/xflash_dump.cpp

@@ -8,28 +8,22 @@
 #include "xflash.h"
 #include "Marlin.h" // for softReset
 
-bool xfdump_check_state()
+bool xfdump_check_state(dump_crash_reason* reason)
 {
     uint32_t magic;
 
     XFLASH_SPI_ENTER();
     xflash_rd_data(DUMP_OFFSET + offsetof(dump_t, header.magic),
                    (uint8_t*)&magic, sizeof(magic));
-
-    return magic == DUMP_MAGIC;
-}
-
-
-bool xfdump_check_crash()
-{
-    // check_state will call SPI_ENTER for us
-    if(!xfdump_check_state())
+    if (magic != DUMP_MAGIC)
         return false;
 
-    dump_crash_reason reason;
-    xflash_rd_data(DUMP_OFFSET + offsetof(dump_t, header.crash_reason),
-                   (uint8_t*)&reason, sizeof(reason));
-    return (reason != dump_crash_reason::manual);
+    if (reason)
+    {
+        xflash_rd_data(DUMP_OFFSET + offsetof(dump_t, header.crash_reason),
+                       (uint8_t*)reason, sizeof(*reason));
+    }
+    return true;
 }
 
 

+ 3 - 2
Firmware/xflash_dump.h

@@ -4,8 +4,6 @@
 #ifdef XFLASH_DUMP
 
 void xfdump_reset();        // reset XFLASH dump state
-bool xfdump_check_state();  // return true if a dump is present
-bool xfdump_check_crash();  // return true if a dump is present and is a crash dump
 void xfdump_dump();         // create a new SRAM memory dump
 
 enum class dump_crash_reason : uint8_t
@@ -15,6 +13,9 @@ enum class dump_crash_reason : uint8_t
     watchdog,
 };
 
+// return true if a dump is present, save type in "reason" if provided
+bool xfdump_check_state(dump_crash_reason* reason = NULL);
+
 // create a new dump containing registers and SRAM, then reset
 void xfdump_full_dump_and_reset(dump_crash_reason crash = dump_crash_reason::manual);