set mbed_set_error_hook() to deprecated

pull/12569/head
Philipp Steiner 2020-03-05 08:49:17 +01:00
parent 17e8b9c756
commit e3917e495a
2 changed files with 54 additions and 3 deletions

View File

@ -940,6 +940,16 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
*/
#define MBED_MAKE_ERROR(module, error_code) MBED_MAKE_SYSTEM_ERROR(module, error_code)
/**
* Callback/Error hook function prototype. Applications needing a callback when an error is reported can use mbed_set_error_hook function
* to register a callback/error hook function using the following prototype. When an error happens in the system error handling
* implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.
* @param error_ctx Error context structure associated with this error.
* @return void
*
*/
typedef void (*mbed_error_hook_t)(const mbed_error_ctx *error_ctx);
/**
* Callback/Error hook function. If application implementation needs to receive this callback when an error is reported,
* mbed_error_hook function should be overridden with custom implementation. When an error happens in the system error handling
@ -950,7 +960,6 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
*/
void mbed_error_hook(const mbed_error_ctx *error_context);
/**
* Callback function for reporting error context during boot up. When MbedOS error handling system detects a fatal error
* it will auto-reboot the system(if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled) after capturing the
@ -1070,6 +1079,30 @@ bool mbed_get_error_in_progress(void);
*/
MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number);
/**
* Registers an application defined error callback with the error handling system.
* This function will be called with error context info whenever system handles a mbed_error/mbed_warning call
* NOTE: This function should be implemented for re-entrancy as multiple threads may invoke mbed_error which may cause error hook to be called.
* @param custom_error_hook mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
* @return 0 or MBED_SUCCESS on success.
* MBED_ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
*
* @code
*
* mbed_error_status_t my_custom_error_hook(mbed_error_status_t error_status, const mbed_error_ctx *error_ctx) {
* //Do something with the error_status or error_ctx
* }
*
* mbed_set_error_hook( my_custom_error_hook )
*
* @endcode
* @note The erro hook function implementation should be re-entrant.
*
* @deprecated You should use an overridden mbed_error_hook() function if you like to catch errors in your application.
* With mbed_set_error_hook() it is not possible to catch errors before your application started.
*/
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t custom_error_hook);
/**
* Reads the first error context information captured.
* @param error_info This is the mbed_error_context info captured as part of the first mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.

View File

@ -58,6 +58,7 @@ static int error_count = 0;
static mbed_error_ctx first_error_ctx = {0};
static mbed_error_ctx last_error_ctx = {0};
static mbed_error_hook_t error_hook = NULL;
static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsigned int error_value, const char *filename, int line_number, void *caller);
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
@ -193,8 +194,12 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
mbed_error_hist_put(&current_error_ctx);
#endif
//Call the error hook
mbed_error_hook(&last_error_ctx);
//Call the error hook if available
if (error_hook != NULL) {
error_hook(&last_error_ctx);
} else {
mbed_error_hook(&last_error_ctx);
}
core_util_critical_section_exit();
@ -324,6 +329,19 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
mbed_halt_system();
}
//Register an application defined callback with error handling
MBED_DEPRECATED("Use an overridden mbed_error_hook() function")
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
{
//register the new hook/callback
if (error_hook_in != NULL) {
error_hook = error_hook_in;
return MBED_SUCCESS;
}
return MBED_ERROR_INVALID_ARGUMENT;
}
//Reset the reboot error context
mbed_error_status_t mbed_reset_reboot_error_info()
{