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().
This commit is contained in:
Yuri D'Elia 2021-06-11 19:21:51 +02:00
parent 31f416fd5e
commit 3187b96ca4
3 changed files with 32 additions and 25 deletions

View File

@ -108,7 +108,7 @@
#include "optiboot_xflash.h" #include "optiboot_xflash.h"
#endif //XFLASH #endif //XFLASH
#ifdef EMERGENCY_DUMP #ifdef XFLASH_DUMP
#include "xflash_dump.h" #include "xflash_dump.h"
#endif #endif
@ -1610,8 +1610,17 @@ void setup()
if (tmc2130_home_enabled == 0xff) tmc2130_home_enabled = 0; if (tmc2130_home_enabled == 0xff) tmc2130_home_enabled = 0;
#endif //TMC2130 #endif //TMC2130
#ifdef XFLASH_DUMP
{
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 #ifdef EMERGENCY_DUMP
if(xfdump_check_crash() && eeprom_read_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED) != 1) if(crash_reason != dump_crash_reason::manual &&
eeprom_read_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED) != 1)
{ {
// prevent the prompt to reappear once acknowledged // prevent the prompt to reappear once acknowledged
eeprom_update_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED, 1); eeprom_update_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED, 1);
@ -1621,6 +1630,9 @@ void setup()
"Contact support to submit details.")); "Contact support to submit details."));
} }
#endif #endif
}
}
#endif
#ifdef UVLO_SUPPORT #ifdef UVLO_SUPPORT
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != 0) { //previous print was terminated by UVLO if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != 0) { //previous print was terminated by UVLO

View File

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

View File

@ -4,8 +4,6 @@
#ifdef XFLASH_DUMP #ifdef XFLASH_DUMP
void xfdump_reset(); // reset XFLASH dump state 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 void xfdump_dump(); // create a new SRAM memory dump
enum class dump_crash_reason : uint8_t enum class dump_crash_reason : uint8_t
@ -15,6 +13,9 @@ enum class dump_crash_reason : uint8_t
watchdog, 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 // create a new dump containing registers and SRAM, then reset
void xfdump_full_dump_and_reset(dump_crash_reason crash = dump_crash_reason::manual); void xfdump_full_dump_and_reset(dump_crash_reason crash = dump_crash_reason::manual);