Skip to content

Commit

Permalink
Add the ability to be called back when the device is about to reset
Browse files Browse the repository at this point in the history
Caveats:
- You have to be very careful in your callback.
- On Adafruit Huzzah, I only actually get called for Exceptions and Soft
   WDT resets.
  • Loading branch information
Carl Pacey committed Nov 13, 2015
1 parent 81e3ebe commit baa13f8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cores/esp8266/core_esp8266_postmortem.c
Expand Up @@ -37,6 +37,11 @@ static void uart1_write_char_d(char c);
static void print_stack(uint32_t start, uint32_t end);
//static void print_pcs(uint32_t start, uint32_t end);

extern void __custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) {
}

extern void custom_crash_callback( struct rst_info * rst_info, uint32_t stack, uint32_t stack_end ) __attribute__ ((weak, alias("__custom_crash_callback")));

void __wrap_system_restart_local() {
register uint32_t sp asm("a1");

Expand Down Expand Up @@ -92,6 +97,9 @@ void __wrap_system_restart_local() {

// print_pcs(sp + offset, stack_end);
print_stack(sp + offset, stack_end);

custom_crash_callback( &rst_info, sp + offset, stack_end );

delayMicroseconds(10000);
__real_system_restart_local();
}
Expand Down

0 comments on commit baa13f8

Please sign in to comment.