Merge pull request #440 from flannelhead/user-exception-handler

Add a hook for a user defined exception handler
This commit is contained in:
Ruslan V. Uss 2017-09-01 14:28:49 +05:00 committed by GitHub
commit d100f42b1f
2 changed files with 22 additions and 0 deletions

View file

@ -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;
}

View file

@ -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