|
37 | 37 | #include <inttypes.h>
|
38 | 38 |
|
39 | 39 | #ifndef NDEBUG
|
40 |
| -#define ERROR_REPORT(ctx, error_msg, error_filename, error_line, print_thread_info) print_error_report(ctx, error_msg, error_filename, error_line, print_thread_info) |
41 |
| -static void print_error_report(const mbed_error_ctx *ctx, const char *, const char *error_filename, int error_line, bool print_thread_info); |
| 40 | +#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) print_error_report(ctx, error_msg, error_filename, error_line) |
| 41 | +static void print_error_report(const mbed_error_ctx *ctx, const char *, const char *error_filename, int error_line); |
42 | 42 | #else
|
43 |
| -#define ERROR_REPORT(ctx, error_msg, error_filename, error_line, print_thread_info) ((void) 0) |
| 43 | +#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) ((void) 0) |
44 | 44 | #endif
|
45 | 45 |
|
46 | 46 | static core_util_atomic_flag error_in_progress = CORE_UTIL_ATOMIC_FLAG_INIT;
|
@@ -71,8 +71,8 @@ static unsigned int compute_crc32(const void *data, int datalen)
|
71 | 71 | const unsigned int polynomial = 0x04C11DB7; /* divisor is 32bit */
|
72 | 72 | unsigned int crc = 0; /* CRC value is 32bit */
|
73 | 73 | unsigned char *buf = (unsigned char *)data;//use a temp variable to make code readable and to avoid typecasting issues.
|
74 |
| - |
75 |
| - for (; datalen>0; datalen-- ) { |
| 74 | + |
| 75 | + for (; datalen > 0; datalen--) { |
76 | 76 | unsigned char b = *buf++;
|
77 | 77 | crc ^= (unsigned int)(b << 24); /* move byte into upper 8bit */
|
78 | 78 | for (int i = 0; i < 8; i++) {
|
@@ -115,7 +115,7 @@ WEAK MBED_NORETURN void error(const char *format, ...)
|
115 | 115 | // Prevent recursion if error is called again during store+print attempt
|
116 | 116 | if (!core_util_atomic_flag_test_and_set(&error_in_progress)) {
|
117 | 117 | handle_error(MBED_ERROR_UNKNOWN, 0, NULL, 0, MBED_CALLER_ADDR());
|
118 |
| - ERROR_REPORT(&last_error_ctx, "Fatal Run-time error", NULL, 0, true); |
| 118 | + ERROR_REPORT(&last_error_ctx, "Fatal Run-time error", NULL, 0); |
119 | 119 |
|
120 | 120 | #ifndef NDEBUG
|
121 | 121 | va_list arg;
|
@@ -202,32 +202,34 @@ mbed_error_status_t mbed_error_initialize(void)
|
202 | 202 | {
|
203 | 203 | #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
|
204 | 204 | uint32_t crc_val = 0;
|
205 |
| - |
| 205 | + |
206 | 206 | //Just check if we have valid value for error_status, if error_status is positive(which is not valid), no need to check crc
|
207 | 207 | if (report_error_ctx->error_status < 0) {
|
208 | 208 | crc_val = compute_crc32(report_error_ctx, offsetof(mbed_error_ctx, crc_error_ctx));
|
209 | 209 | //Read report_error_ctx and check if CRC is correct, and with valid status code
|
210 | 210 | if ((report_error_ctx->crc_error_ctx == crc_val) && (report_error_ctx->is_error_processed == 0)) {
|
211 | 211 | is_reboot_error_valid = true;
|
212 |
| -#if MBED_CONF_PLATFORM_REBOOT_CRASH_REPORT_ENABLED && !defined(NDEBUG) |
213 | 212 | //Report the error info
|
214 |
| - mbed_error_printf("\n== Your last reboot was triggered by an error, below is the error information =="); |
215 |
| - ERROR_REPORT(report_error_ctx, "System rebooted due to fatal error", MBED_FILENAME, __LINE__, false); |
216 |
| -#endif |
| 213 | + printf("\n== The system has been rebooted due to a fatal error. ==\n"); |
| 214 | + |
217 | 215 | //Call the mbed_error_reboot_callback, this enables applications to do some handling before we do the handling
|
218 | 216 | mbed_error_reboot_callback(report_error_ctx);
|
219 |
| - |
220 |
| - //Enforce max-reboot only if auto reboot is enabled |
| 217 | + |
| 218 | + //We let the callback reset the error info, so check if its still valid and do the rest only if its still valid. |
| 219 | + if (report_error_ctx->error_reboot_count < 0) { |
| 220 | + |
| 221 | + //Enforce max-reboot only if auto reboot is enabled |
221 | 222 | #if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED
|
222 |
| - if (report_error_ctx->error_reboot_count >= MBED_CONF_PLATFORM_ERROR_REBOOT_MAX) { |
223 |
| - //We have rebooted more than enough, hold the system here. |
224 |
| - mbed_error_printf("\n== Reboot count(=%ld) exceeded maximum, system halting ==\n", report_error_ctx->error_reboot_count); |
225 |
| - mbed_halt_system(); |
226 |
| - } |
| 223 | + if (report_error_ctx->error_reboot_count >= MBED_CONF_PLATFORM_ERROR_REBOOT_MAX) { |
| 224 | + //We have rebooted more than enough, hold the system here. |
| 225 | + printf("\n== Reboot count(=%ld) exceeded maximum, system halting ==\n", report_error_ctx->error_reboot_count); |
| 226 | + mbed_halt_system(); |
| 227 | + } |
227 | 228 | #endif
|
228 |
| - report_error_ctx->is_error_processed = 1;//Set the flag that we already processed this error |
229 |
| - crc_val = compute_crc32(report_error_ctx, offsetof(mbed_error_ctx, crc_error_ctx)); |
230 |
| - report_error_ctx->crc_error_ctx = crc_val; |
| 229 | + report_error_ctx->is_error_processed = 1;//Set the flag that we already processed this error |
| 230 | + crc_val = compute_crc32(report_error_ctx, offsetof(mbed_error_ctx, crc_error_ctx)); |
| 231 | + report_error_ctx->crc_error_ctx = crc_val; |
| 232 | + } |
231 | 233 | }
|
232 | 234 | }
|
233 | 235 | #endif
|
@@ -270,7 +272,7 @@ WEAK MBED_NORETURN mbed_error_status_t mbed_error(mbed_error_status_t error_stat
|
270 | 272 | (void) handle_error(error_status, error_value, filename, line_number, MBED_CALLER_ADDR());
|
271 | 273 |
|
272 | 274 | //On fatal errors print the error context/report
|
273 |
| - ERROR_REPORT(&last_error_ctx, error_msg, filename, line_number, true); |
| 275 | + ERROR_REPORT(&last_error_ctx, error_msg, filename, line_number); |
274 | 276 | }
|
275 | 277 |
|
276 | 278 | #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
|
@@ -447,7 +449,7 @@ static void print_threads_info(const osRtxThread_t *threads)
|
447 | 449 | #endif
|
448 | 450 |
|
449 | 451 | #ifndef NDEBUG
|
450 |
| -static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, const char *error_filename, int error_line, bool print_thread_info) |
| 452 | +static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, const char *error_filename, int error_line) |
451 | 453 | {
|
452 | 454 | int error_code = MBED_GET_ERROR_CODE(ctx->error_status);
|
453 | 455 | int error_module = MBED_GET_ERROR_MODULE(ctx->error_status);
|
@@ -520,19 +522,17 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
|
520 | 522 | #endif
|
521 | 523 |
|
522 | 524 | #if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
|
523 |
| - if (print_thread_info) { |
524 |
| - mbed_error_printf("\nNext:"); |
525 |
| - print_thread(osRtxInfo.thread.run.next); |
| 525 | + mbed_error_printf("\nNext:"); |
| 526 | + print_thread(osRtxInfo.thread.run.next); |
526 | 527 |
|
527 |
| - mbed_error_printf("\nReady:"); |
528 |
| - print_threads_info(osRtxInfo.thread.ready.thread_list); |
| 528 | + mbed_error_printf("\nReady:"); |
| 529 | + print_threads_info(osRtxInfo.thread.ready.thread_list); |
529 | 530 |
|
530 |
| - mbed_error_printf("\nWait:"); |
531 |
| - print_threads_info(osRtxInfo.thread.wait_list); |
| 531 | + mbed_error_printf("\nWait:"); |
| 532 | + print_threads_info(osRtxInfo.thread.wait_list); |
532 | 533 |
|
533 |
| - mbed_error_printf("\nDelay:"); |
534 |
| - print_threads_info(osRtxInfo.thread.delay_list); |
535 |
| - } |
| 534 | + mbed_error_printf("\nDelay:"); |
| 535 | + print_threads_info(osRtxInfo.thread.delay_list); |
536 | 536 | #endif
|
537 | 537 | mbed_error_printf(MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR, ctx->error_status);
|
538 | 538 | mbed_error_printf("\n-- MbedOS Error Info --\n");
|
|
0 commit comments