Skip to content

Commit a769b7d

Browse files
committed
mbed_error.c: Fixed compile errors with non-RTX targets.
1 parent 76353d5 commit a769b7d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

platform/source/mbed_error.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#endif
4141
#include <inttypes.h>
4242

43+
#ifndef MAX
44+
#define MAX(a, b) ((a) > (b) ? (a) : (b))
45+
#endif
46+
4347
#ifndef NDEBUG
4448
#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) print_error_report(ctx, error_msg, error_filename, error_line)
4549
static void print_error_report(const mbed_error_ctx *ctx, const char *, const char *error_filename, int error_line);
@@ -473,6 +477,7 @@ mbed_error_status_t mbed_clear_all_errors(void)
473477
return status;
474478
}
475479

480+
#ifdef MBED_CONF_RTOS_PRESENT
476481
static inline const char *name_or_unnamed(const osRtxThread_t *thread)
477482
{
478483
const char *unnamed = "<unnamed>";
@@ -484,7 +489,9 @@ static inline const char *name_or_unnamed(const osRtxThread_t *thread)
484489
const char *name = thread->name;
485490
return name ? name : unnamed;
486491
}
492+
#endif // MBED_CONF_RTOS_PRESENT
487493

494+
#if MBED_STACK_DUMP_ENABLED
488495
/** Prints stack dump from given stack information.
489496
* The arguments should be given in address raw value to check alignment.
490497
* @param stack_start The address of stack start.
@@ -515,7 +522,6 @@ static void print_stack_dump_core(uint32_t stack_start, uint32_t stack_size, uin
515522

516523
static void print_stack_dump(uint32_t stack_start, uint32_t stack_size, uint32_t stack_sp, const mbed_error_ctx *ctx)
517524
{
518-
#if MBED_STACK_DUMP_ENABLED
519525
if (ctx && mbed_error_is_handler(ctx)) {
520526
// Stack dump extra for handler stack which may have accessed MSP.
521527
mbed_fault_context_t *mfc = (mbed_fault_context_t *)ctx->error_value;
@@ -536,8 +542,8 @@ static void print_stack_dump(uint32_t stack_start, uint32_t stack_size, uint32_t
536542
}
537543

538544
print_stack_dump_core(stack_start, stack_size, stack_sp, "PSP");
539-
#endif // MBED_STACK_DUMP_ENABLED
540545
}
546+
#endif // MBED_STACK_DUMP_ENABLED
541547

542548
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
543549
/* Prints info of a thread(using osRtxThread_t struct)*/
@@ -546,7 +552,9 @@ static void print_thread(const osRtxThread_t *thread)
546552
uint32_t stack_mem = (uint32_t)thread->stack_mem;
547553
mbed_error_printf("\n%s State: 0x%" PRIX8 " Entry: 0x%08" PRIX32 " Stack Size: 0x%08" PRIX32 " Mem: 0x%08" PRIX32 " SP: 0x%08" PRIX32, name_or_unnamed(thread), thread->state, thread->thread_addr, thread->stack_size, stack_mem, thread->sp);
548554

555+
#if MBED_STACK_DUMP_ENABLED
549556
print_stack_dump(stack_mem, thread->stack_size, thread->sp, NULL);
557+
#endif
550558
}
551559

552560
/* Prints thread info from a list */
@@ -628,14 +636,16 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
628636
}
629637

630638
mbed_error_printf("\nError Value: 0x%" PRIX32, ctx->error_value);
631-
bool is_handler = mbed_error_is_handler(ctx);
632639
#ifdef MBED_CONF_RTOS_PRESENT
640+
bool is_handler = mbed_error_is_handler(ctx);
633641
mbed_error_printf("\nCurrent Thread: %s%s Id: 0x%" PRIX32 " Entry: 0x%" PRIX32 " StackSize: 0x%" PRIX32 " StackMem: 0x%" PRIX32 " SP: 0x%" PRIX32 " ",
634642
name_or_unnamed((osRtxThread_t *)ctx->thread_id), is_handler ? " <handler>" : "",
635643
ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
636644
#endif
637645

646+
#if MBED_STACK_DUMP_ENABLED
638647
print_stack_dump(ctx->thread_stack_mem, ctx->thread_stack_size, ctx->thread_current_sp, ctx);
648+
#endif
639649

640650
#if MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO && defined(MBED_CONF_RTOS_PRESENT)
641651
mbed_error_printf("\nNext:");

0 commit comments

Comments
 (0)