Added an API for user exception handlers

This commit is contained in:
Sakari Kapanen 2017-08-12 00:54:35 +03:00
parent 42ccb47eb3
commit 4838072ecf
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