panic: user callback for common error handler

This commit is contained in:
Michael Balzer 2018-04-08 14:36:36 +02:00
parent 0f978bcb45
commit daef4b5c11
3 changed files with 96 additions and 48 deletions

View file

@ -511,6 +511,14 @@ config ESP32_PANIC_GDBSTUB
of the crash.
endchoice
config ESP32_PANIC_CALLBACK
bool "Support registration of a user defined callback for the panic handler"
default y
help
Use xt_set_error_handler_callback() to register a custom callback.
The callback is called by the common error handler so catches exceptions,
panics and abort() calls.
config ESP32_DEBUG_OCDAWARE
bool "Make exception and panic handlers JTAG/OCD aware"
default y
@ -518,7 +526,6 @@ config ESP32_DEBUG_OCDAWARE
The FreeRTOS panic and unhandled exception handers can detect a JTAG OCD debugger and
instead of panicking, have the debugger stop on the offending instruction.
config INT_WDT
bool "Interrupt watchdog"
default y

View file

@ -518,6 +518,19 @@ static void commonErrorHandler_dump(XtExcFrame *frame, int core_id)
}
#if CONFIG_ESP32_PANIC_CALLBACK
/*
* Custom error handler callback registration.
*/
xt_error_handler_callback customErrorHandler = NULL;
xt_error_handler_callback xt_set_error_handler_callback(xt_error_handler_callback f)
{
xt_error_handler_callback old = customErrorHandler;
customErrorHandler = f;
return old;
}
#endif //CONFIG_ESP32_PANIC_CALLBACK
/*
We arrive here after a panic or unhandled exception, when no OCD is detected. Dump the registers to the
serial port and either jump to the gdb stub, halt the CPU or reboot.
@ -539,6 +552,14 @@ static __attribute__((noreturn)) void commonErrorHandler(XtExcFrame *frame)
}
#endif //!CONFIG_FREERTOS_UNICORE
#if CONFIG_ESP32_PANIC_CALLBACK
if (customErrorHandler) {
disableAllWdts();
customErrorHandler(frame, core_id, abort_called);
reconfigureAllWdts();
}
#endif
#if CONFIG_ESP32_APPTRACE_ENABLE
disableAllWdts();
#if CONFIG_SYSVIEW_ENABLE

View file

@ -39,6 +39,9 @@ typedef void (*xt_handler)(void *);
/* Typedef for C-callable exception handler function */
typedef void (*xt_exc_handler)(XtExcFrame *);
/* Typedef for C-callable standard error handler callback */
typedef void (*xt_error_handler_callback)(XtExcFrame *, int core_id, bool is_abort);
/*
-------------------------------------------------------------------------------
@ -60,6 +63,23 @@ typedef void (*xt_exc_handler)(XtExcFrame *);
extern xt_exc_handler xt_set_exception_handler(int n, xt_exc_handler f);
/*
-------------------------------------------------------------------------------
Call this function to set a callback for the standard error handler.
The callback will be called by the commonErrorHandler on all errors.
f - Callback function address, NULL to uninstall callback.
The callback will be passed a pointer to the exception frame, which is created
on the stack of the thread that caused the exception, the core id and
a bool to signal if abort() has been called.
The callback is called with watchdogs disabled.
-------------------------------------------------------------------------------
*/
extern xt_error_handler_callback xt_set_error_handler_callback(xt_error_handler_callback f);
/*
-------------------------------------------------------------------------------
Call this function to set a handler for the specified interrupt. The handler