|
43 | 43 | Included Files
|
44 | 44 | ****************************************************************************/
|
45 | 45 | #include "cmsis.h"
|
46 |
| -#include "mbed_crash_data_offsets.h" |
47 |
| -#include "mbed_retarget.h" |
48 |
| -#include "mbed_critical.h" |
49 |
| -#include "mbed_error.h" |
50 |
| -#include "mbed_error_hist.h" |
51 | 46 | #include "mbed_interface.h"
|
52 | 47 | #include "mbed_power_mgmt.h"
|
53 | 48 | #include "mbed_stats.h"
|
54 | 49 | #include "mbed_atomic.h"
|
55 |
| -#include "mbed_fault_handler.h" |
56 | 50 |
|
57 | 51 | #include "rtx_os.h"
|
58 | 52 | #include <inttypes.h>
|
59 | 53 | #include <string.h>
|
60 | 54 |
|
61 |
| -#ifndef NDEBUG |
62 |
| -#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) print_error_report(ctx, error_msg, error_filename, error_line) |
63 |
| -static void print_error_report(const mbed_error_ctx *ctx, const char *, const char *error_filename, int error_line); |
64 |
| -#else |
65 |
| -#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) ((void) 0) |
66 |
| -#endif |
67 |
| - |
68 |
| -extern mbed_fault_context_t *mbed_fault_context; |
69 |
| -static int error_count = 0; |
70 |
| -static mbed_error_ctx first_error_ctx = {0}; |
71 |
| -static mbed_error_ctx last_error_ctx = {0}; |
72 |
| -static mbed_error_hook_t error_hook = NULL; |
73 |
| -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); |
74 |
| - |
75 |
| -static inline const char *name_or_unnamed(const char *name) |
76 |
| -{ |
77 |
| - return name ? name : "<unnamed>"; |
78 |
| -} |
79 |
| - |
80 |
| - |
81 |
| -#ifndef NDEBUG |
82 |
| -#define GET_TARGET_NAME_STR(tgt_name) #tgt_name |
83 |
| -#define GET_TARGET_NAME(tgt_name) GET_TARGET_NAME_STR(tgt_name) |
84 |
| -static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, const char *error_filename, int error_line) |
85 |
| -{ |
86 |
| - int error_code = MBED_GET_ERROR_CODE(ctx->error_status); |
87 |
| - int error_module = MBED_GET_ERROR_MODULE(ctx->error_status); |
88 |
| - |
89 |
| - mbed_error_printf("\n\n++ MbedOS Error Info ++\nError Status: 0x%X Code: %d Module: %d\nError Message: ", ctx->error_status, error_code, error_module); |
90 |
| - |
91 |
| - switch (error_code) { |
92 |
| - //These are errors reported by kernel handled from mbed_rtx_handlers |
93 |
| - case MBED_ERROR_CODE_RTOS_EVENT: |
94 |
| - mbed_error_printf("Kernel Error: 0x%" PRIX32 ", ", ctx->error_value); |
95 |
| - break; |
96 |
| - |
97 |
| - case MBED_ERROR_CODE_RTOS_THREAD_EVENT: |
98 |
| - mbed_error_printf("Thread: 0x%" PRIX32 ", ", ctx->error_value); |
99 |
| - break; |
100 |
| - |
101 |
| - case MBED_ERROR_CODE_RTOS_MUTEX_EVENT: |
102 |
| - mbed_error_printf("Mutex: 0x%" PRIX32 ", ", ctx->error_value); |
103 |
| - break; |
104 |
| - |
105 |
| - case MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT: |
106 |
| - mbed_error_printf("Semaphore: 0x%" PRIX32 ", ", ctx->error_value); |
107 |
| - break; |
108 |
| - |
109 |
| - case MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT: |
110 |
| - mbed_error_printf("MemoryPool: 0x%" PRIX32 ", ", ctx->error_value); |
111 |
| - break; |
112 |
| - |
113 |
| - case MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT: |
114 |
| - mbed_error_printf("EventFlags: 0x%" PRIX32 ", ", ctx->error_value); |
115 |
| - break; |
116 |
| - |
117 |
| - case MBED_ERROR_CODE_RTOS_TIMER_EVENT: |
118 |
| - mbed_error_printf("Timer: 0x%" PRIX32 ", ", ctx->error_value); |
119 |
| - break; |
120 |
| - |
121 |
| - case MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT: |
122 |
| - mbed_error_printf("MessageQueue: 0x%" PRIX32 ", ", ctx->error_value); |
123 |
| - break; |
124 |
| - |
125 |
| - case MBED_ERROR_CODE_ASSERTION_FAILED: |
126 |
| - mbed_error_printf("Assertion failed: "); |
127 |
| - break; |
128 |
| - |
129 |
| - default: |
130 |
| - //Nothing to do here, just print the error info down |
131 |
| - break; |
132 |
| - } |
133 |
| - mbed_error_puts(error_msg); |
134 |
| - mbed_error_printf("\nLocation: 0x%" PRIX32, ctx->error_address); |
135 |
| - |
136 |
| - /* We print the filename passed in, not any filename in the context. This |
137 |
| - * avoids the console print for mbed_error being limited to the presence |
138 |
| - * and length of the filename storage. Note that although the MBED_ERROR |
139 |
| - * macro compiles out filenames unless platform.error-filename-capture-enabled |
140 |
| - * is turned on, MBED_ASSERT always passes filenames, and other direct |
141 |
| - * users of mbed_error() may also choose to. |
142 |
| - */ |
143 |
| - if (error_filename) { |
144 |
| - mbed_error_puts("\nFile: "); |
145 |
| - mbed_error_puts(error_filename); |
146 |
| - mbed_error_printf("+%d", error_line); |
147 |
| - } |
148 |
| - |
149 |
| - mbed_error_printf("\nError Value: 0x%" PRIX32, ctx->error_value); |
150 |
| -#ifdef MBED_CONF_RTOS_PRESENT |
151 |
| - mbed_error_printf("\nCurrent Thread: %s Id: 0x%" PRIX32 " Entry: 0x%" PRIX32 " StackSize: 0x%" PRIX32 " StackMem: 0x%" PRIX32 " SP: 0x%" PRIX32 " ", |
152 |
| - name_or_unnamed(((osRtxThread_t *)ctx->thread_id)->name), |
153 |
| - ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp); |
154 |
| -#endif |
155 |
| - |
156 |
| -#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT) |
157 |
| - mbed_error_printf("\nNext:"); |
158 |
| - print_thread(osRtxInfo.thread.run.next); |
159 |
| - |
160 |
| - mbed_error_printf("\nReady:"); |
161 |
| - print_threads_info(osRtxInfo.thread.ready.thread_list); |
162 |
| - |
163 |
| - mbed_error_printf("\nWait:"); |
164 |
| - print_threads_info(osRtxInfo.thread.wait_list); |
165 |
| - |
166 |
| - mbed_error_printf("\nDelay:"); |
167 |
| - print_threads_info(osRtxInfo.thread.delay_list); |
168 |
| -#endif |
169 |
| -#if !defined(MBED_SYS_STATS_ENABLED) |
170 |
| - mbed_error_printf("\nFor more info, visit: https://mbed.com/s/error?error=0x%08X&tgt=" GET_TARGET_NAME(TARGET_NAME), ctx->error_status); |
171 |
| -#else |
172 |
| - mbed_stats_sys_t sys_stats; |
173 |
| - mbed_stats_sys_get(&sys_stats); |
174 |
| - mbed_error_printf("\nFor more info, visit: https://mbed.com/s/error?error=0x%08X&osver=%" PRId32 "&core=0x%08" PRIX32 "&comp=%d&ver=%" PRIu32 "&tgt=" GET_TARGET_NAME(TARGET_NAME), ctx->error_status, sys_stats.os_version, sys_stats.cpu_id, sys_stats.compiler_id, sys_stats.compiler_version); |
175 |
| -#endif |
176 |
| - mbed_error_printf("\n-- MbedOS Error Info --\n"); |
177 |
| -} |
178 |
| -#endif //ifndef NDEBUG |
179 |
| - |
180 |
| - |
181 |
| - |
182 | 55 |
|
183 | 56 | /****************************************************************************
|
184 | 57 | * Name: up_systemreset
|
@@ -226,100 +99,4 @@ int board_reset(void)
|
226 | 99 | up_systemreset();
|
227 | 100 | return 0;
|
228 | 101 | }
|
229 |
| -//Set an error status with the error handling system |
230 |
| -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) |
231 |
| -{ |
232 |
| - mbed_error_ctx current_error_ctx; |
233 |
| - |
234 |
| - //Error status should always be < 0 |
235 |
| - if (error_status >= 0) { |
236 |
| - //This is a weird situation, someone called mbed_error with invalid error code. |
237 |
| - //We will still handle the situation but change the error code to ERROR_INVALID_ARGUMENT, atleast the context will have info on who called it |
238 |
| - error_status = MBED_ERROR_INVALID_ARGUMENT; |
239 |
| - } |
240 |
| - |
241 |
| - //Clear the context capturing buffer |
242 |
| - memset(¤t_error_ctx, 0, sizeof(mbed_error_ctx)); |
243 |
| - //Capture error information |
244 |
| - current_error_ctx.error_status = error_status; |
245 |
| - current_error_ctx.error_address = (uint32_t)caller; |
246 |
| - current_error_ctx.error_value = error_value; |
247 |
| -#ifdef MBED_CONF_RTOS_PRESENT |
248 |
| - //Capture thread info |
249 |
| - osRtxThread_t *current_thread = osRtxInfo.thread.run.curr; |
250 |
| - current_error_ctx.thread_id = (uint32_t)current_thread; |
251 |
| - current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr; |
252 |
| - current_error_ctx.thread_stack_size = current_thread->stack_size; |
253 |
| - current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem; |
254 |
| - current_error_ctx.thread_current_sp = (uint32_t)¤t_error_ctx; // Address local variable to get a stack pointer |
255 |
| -#endif //MBED_CONF_RTOS_PRESENT |
256 |
| - |
257 |
| -#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED |
258 |
| - //Capture filename/linenumber if provided |
259 |
| - //Index for tracking error_filename |
260 |
| - strncpy(current_error_ctx.error_filename, filename, MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN); |
261 |
| - current_error_ctx.error_line_number = line_number; |
262 |
| -#endif |
263 |
| - |
264 |
| - //Prevent corruption by holding out other callers |
265 |
| - core_util_critical_section_enter(); |
266 |
| - |
267 |
| - //Increment error count |
268 |
| - error_count++; |
269 |
| - |
270 |
| - //Capture the first system error and store it |
271 |
| - if (error_count == 1) { //first error |
272 |
| - memcpy(&first_error_ctx, ¤t_error_ctx, sizeof(mbed_error_ctx)); |
273 |
| - } |
274 |
| - |
275 |
| - //copy this error to last error |
276 |
| - memcpy(&last_error_ctx, ¤t_error_ctx, sizeof(mbed_error_ctx)); |
277 |
| - |
278 |
| -#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED |
279 |
| - //Log the error with error log |
280 |
| - mbed_error_hist_put(¤t_error_ctx); |
281 |
| -#endif |
282 |
| - |
283 |
| - //Call the error hook if available |
284 |
| - if (error_hook != NULL) { |
285 |
| - error_hook(&last_error_ctx); |
286 |
| - } |
287 |
| - |
288 |
| - core_util_critical_section_exit(); |
289 |
| - |
290 |
| - return MBED_SUCCESS; |
291 |
| -} |
292 | 102 |
|
293 |
| -#define CONTAINER_OF(ptr, type, field) \ |
294 |
| - ((type *)(((char *)(ptr)) - offsetof(type, field))) |
295 |
| - |
296 |
| -mbed_error_status_t mbed_error(int error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number) |
297 |
| -{ |
298 |
| - int i; |
299 |
| - uint32_t current_psp; |
300 |
| - //set the error reported |
301 |
| - (void) handle_error(error_status, error_value, filename, line_number, MBED_CALLER_ADDR()); |
302 |
| - |
303 |
| - //On fatal errors print the error context/report |
304 |
| - ERROR_REPORT(&last_error_ctx, error_msg, filename, line_number); |
305 |
| - //mbed_error_printf("\nPSP 0x%x\n", mbed_fault_context->PSP); |
306 |
| - current_psp = mbed_fault_context->PSP; |
307 |
| - mbed_error_printf("dump PSP[0x%x] \n", (unsigned int)current_psp); |
308 |
| - mbed_error_printf("====================== CUT ========================= \n"); |
309 |
| - |
310 |
| - if (current_psp != 0x0) { |
311 |
| - //dump stack contents |
312 |
| - for (i = 0; getreg32(current_psp) != 0xDEADBEEF; i++) { |
313 |
| - if (i % 0x8 == 0) { |
314 |
| - mbed_error_printf("\n"); |
315 |
| - mbed_error_printf("0x%.8x:", (unsigned int)current_psp); |
316 |
| - } |
317 |
| - mbed_error_printf("0x%.8x ", getreg32(current_psp)); |
318 |
| - current_psp += 4; |
319 |
| - } |
320 |
| - // last STACK Pointer |
321 |
| - mbed_error_printf("0x%.8x ", getreg32(current_psp)); |
322 |
| - } |
323 |
| - mbed_error_printf("\n======================FOR ERROR DUMP ========================= \n"); |
324 |
| - while (1); |
325 |
| -} |
0 commit comments