Skip to content

Commit 17e8b9c

Browse files
committed
Remove mbed_set_error_hook and replace with weak mbed_error_hook implementation
1 parent ba94964 commit 17e8b9c

File tree

2 files changed

+10
-42
lines changed

2 files changed

+10
-42
lines changed

platform/mbed_error.h

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -941,14 +941,14 @@ MBED_NORETURN void error(const char *format, ...) MBED_PRINTF(1, 2);
941941
#define MBED_MAKE_ERROR(module, error_code) MBED_MAKE_SYSTEM_ERROR(module, error_code)
942942

943943
/**
944-
* Callback/Error hook function prototype. Applications needing a callback when an error is reported can use mbed_set_error_hook function
945-
* to register a callback/error hook function using the following prototype. When an error happens in the system error handling
944+
* Callback/Error hook function. If application implementation needs to receive this callback when an error is reported,
945+
* mbed_error_hook function should be overridden with custom implementation. When an error happens in the system error handling
946946
* implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.
947947
* @param error_ctx Error context structure associated with this error.
948948
* @return void
949949
*
950950
*/
951-
typedef void (*mbed_error_hook_t)(const mbed_error_ctx *error_ctx);
951+
void mbed_error_hook(const mbed_error_ctx *error_context);
952952

953953

954954
/**
@@ -1070,28 +1070,6 @@ bool mbed_get_error_in_progress(void);
10701070
*/
10711071
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);
10721072

1073-
/**
1074-
* Registers an application defined error callback with the error handling system.
1075-
* This function will be called with error context info whenever system handles a mbed_error/mbed_warning call
1076-
* NOTE: This function should be implemented for re-entrancy as multiple threads may invoke mbed_error which may cause error hook to be called.
1077-
* @param custom_error_hook mbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
1078-
* @return 0 or MBED_SUCCESS on success.
1079-
* MBED_ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
1080-
*
1081-
* @code
1082-
*
1083-
* mbed_error_status_t my_custom_error_hook(mbed_error_status_t error_status, const mbed_error_ctx *error_ctx) {
1084-
* //Do something with the error_status or error_ctx
1085-
* }
1086-
*
1087-
* mbed_set_error_hook( my_custom_error_hook )
1088-
*
1089-
* @endcode
1090-
* @note The erro hook function implementation should be re-entrant.
1091-
*
1092-
*/
1093-
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t custom_error_hook);
1094-
10951073
/**
10961074
* Reads the first error context information captured.
10971075
* @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.

platform/source/mbed_error.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static int error_count = 0;
5858
static mbed_error_ctx first_error_ctx = {0};
5959

6060
static mbed_error_ctx last_error_ctx = {0};
61-
static mbed_error_hook_t error_hook = NULL;
6261
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);
6362

6463
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
@@ -194,16 +193,19 @@ static mbed_error_status_t handle_error(mbed_error_status_t error_status, unsign
194193
mbed_error_hist_put(&current_error_ctx);
195194
#endif
196195

197-
//Call the error hook if available
198-
if (error_hook != NULL) {
199-
error_hook(&last_error_ctx);
200-
}
196+
//Call the error hook
197+
mbed_error_hook(&last_error_ctx);
201198

202199
core_util_critical_section_exit();
203200

204201
return MBED_SUCCESS;
205202
}
206203

204+
WEAK void mbed_error_hook(const mbed_error_ctx *error_context)
205+
{
206+
//Dont do anything here, let application override this if required.
207+
}
208+
207209
WEAK void mbed_error_reboot_callback(mbed_error_ctx *error_context)
208210
{
209211
//Dont do anything here, let application override this if required.
@@ -322,18 +324,6 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
322324
mbed_halt_system();
323325
}
324326

325-
//Register an application defined callback with error handling
326-
mbed_error_status_t mbed_set_error_hook(mbed_error_hook_t error_hook_in)
327-
{
328-
//register the new hook/callback
329-
if (error_hook_in != NULL) {
330-
error_hook = error_hook_in;
331-
return MBED_SUCCESS;
332-
}
333-
334-
return MBED_ERROR_INVALID_ARGUMENT;
335-
}
336-
337327
//Reset the reboot error context
338328
mbed_error_status_t mbed_reset_reboot_error_info()
339329
{

0 commit comments

Comments
 (0)