Skip to content

Replace with weak mbed_error_hook implementation (deprecate the hook function) #12569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion platform/mbed_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
*/
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
* 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
*
*/
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
Expand Down Expand Up @@ -1087,8 +1096,10 @@ MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_status, c
* mbed_set_error_hook( my_custom_error_hook )
*
* @endcode
* @note The erro hook function implementation should be re-entrant.
* @note The error 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);

Expand Down
8 changes: 8 additions & 0 deletions platform/source/mbed_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,20 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
//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();

return MBED_SUCCESS;
}

WEAK void mbed_error_hook(const mbed_error_ctx *error_context)
{
//Dont do anything here, let application override this if required.
}

WEAK void mbed_error_reboot_callback(mbed_error_ctx *error_context)
{
//Dont do anything here, let application override this if required.
Expand Down Expand Up @@ -323,6 +330,7 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
}

//Register an application defined callback with error handling
MBED_DEPRECATED("Use an overridden mbed_error_hook() function instead")
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
{
//register the new hook/callback
Expand Down