diff --git a/core/debug_dumps.c b/core/debug_dumps.c index 6300439..0b18f1a 100644 --- a/core/debug_dumps.c +++ b/core/debug_dumps.c @@ -22,6 +22,7 @@ #include "esp/dport_regs.h" #include "espressif/esp_common.h" #include "esplibs/libmain.h" +#include "user_exception.h" /* Forward declarations */ static void IRAM fatal_handler_prelude(void); @@ -33,6 +34,8 @@ static void __attribute__((noinline)) __attribute__((noreturn)) abort_handler_in static IRAM_DATA fatal_exception_handler_fn fatal_exception_handler_inner = standard_fatal_exception_handler_inner; +static void (*user_exception_handler)(void) = NULL; + /* fatal_exception_handler called from any unhandled user exception * * (similar to a hard fault on other processor architectures) @@ -157,6 +160,10 @@ static void IRAM fatal_handler_prelude(void) { } Cache_Read_Disable(); Cache_Read_Enable(0, 0, 1); + + if (user_exception_handler != NULL) { + user_exception_handler(); + } } /* Main part of fatal exception handler, is run from flash to save @@ -230,3 +237,9 @@ static void abort_handler_inner(uint32_t *caller, uint32_t *sp) { dump_heapinfo(); post_crash_reset(); } + +void set_user_exception_handler(void (*fn)(void)) +{ + user_exception_handler = fn; +} + diff --git a/core/include/user_exception.h b/core/include/user_exception.h new file mode 100644 index 0000000..abb027a --- /dev/null +++ b/core/include/user_exception.h @@ -0,0 +1,9 @@ +/* Allows the user to set their own exception handler. */ + +#ifndef _USER_EXCEPTION_H +#define _USER_EXCEPTION_H + +void set_user_exception_handler(void (*fn)(void)); + +#endif +