From 530e9d323f86ce86ab465dfd7ae4ffd76f7c2274 Mon Sep 17 00:00:00 2001 From: Senthil Ramakrishnan Date: Mon, 14 May 2018 08:27:17 -0500 Subject: [PATCH] Changed variable names for registers to avoid namespace conflicts and rtos disabled build fixes --- platform/mbed_error.c | 36 +++---------------- platform/mbed_error_report.c | 35 +++++++++++++++--- platform/mbed_error_report.h | 9 +++-- .../TARGET_CORTEX_M/mbed_rtx_fault_handler.c | 3 +- .../TARGET_CORTEX_M/mbed_rtx_fault_handler.h | 32 ++++++++--------- 5 files changed, 59 insertions(+), 56 deletions(-) diff --git a/platform/mbed_error.c b/platform/mbed_error.c index 165144c85e..f9f5a3dffc 100644 --- a/platform/mbed_error.c +++ b/platform/mbed_error.c @@ -15,8 +15,6 @@ */ #include #include -#include "rtx_os.h" -#include "mbed_rtx.h" #include "device.h" #include "platform/mbed_critical.h" #include "platform/mbed_error.h" @@ -34,22 +32,6 @@ static mbed_error_ctx first_error_ctx = {0}; static mbed_error_ctx last_error_ctx = {0}; static MbedErrorHook error_hook = NULL; -//Helper function to get the current SP -static unsigned int get_current_sp() -{ - //If in Handler mode we are always using MSP - if( __get_IPSR() != 0U ) { - return __get_MSP(); - } else { - //Look into CONTROL.SPSEL value - if ((__get_CONTROL() & 2U) == 0U) { - return __get_PSP();//Read PSP - } else { - return __get_MSP();//Read MSP - } - } -} - //Helper function to halt the system static void mbed_halt_system(void) { @@ -124,19 +106,6 @@ MbedErrorStatus handle_error(MbedErrorStatus error_status, const char *error_msg } #endif - //Capture thread info - osRtxThread_t *current_thread = osRtxInfo.thread.run.curr; - current_error_ctx.thread_id = (uint32_t)current_thread; - current_error_ctx.thread_entry_address = (uint32_t)current_thread->thread_addr; - current_error_ctx.thread_stack_size = current_thread->stack_size; - current_error_ctx.thread_stack_mem = (uint32_t)current_thread->stack_mem; - current_error_ctx.thread_current_sp = get_current_sp(); - -#ifndef MBED_CONF_ERROR_LOG_DISABLED - //Log the error with error log - mbed_log_put_error(¤t_error_ctx); -#endif - //Use critsect here, as we don't want processing more than one error at the same time core_util_critical_section_enter(); //Report the error @@ -153,6 +122,11 @@ MbedErrorStatus handle_error(MbedErrorStatus error_status, const char *error_msg //Use critsect here, as we don't want processing more than one error at the same time core_util_critical_section_exit(); +#ifndef MBED_CONF_ERROR_LOG_DISABLED + //Log the error with error log + mbed_log_put_error(¤t_error_ctx); +#endif + //Call the error hook if available if(error_hook != NULL) { error_hook(&last_error_ctx); diff --git a/platform/mbed_error_report.c b/platform/mbed_error_report.c index 0a4257c6e1..c023f27982 100644 --- a/platform/mbed_error_report.c +++ b/platform/mbed_error_report.c @@ -15,8 +15,6 @@ */ #include #include -#include "rtx_os.h" -#include "mbed_rtx.h" #include "hal/serial_api.h" #include "hal/itm_api.h" #include "platform/mbed_error.h" @@ -56,6 +54,22 @@ static void value_to_dec_str(uint32_t value, char *dec_str) } } +//Helper function to get the current SP +static unsigned int get_current_sp() +{ + //If in Handler mode we are always using MSP + if( __get_IPSR() != 0U ) { + return __get_MSP(); + } else { + //Look into CONTROL.SPSEL value + if ((__get_CONTROL() & 2U) == 0U) { + return __get_PSP();//Read PSP + } else { + return __get_MSP();//Read MSP + } + } +} + void mbed_error_init(void) { #if DEVICE_SERIAL && (MBED_CONF_ERROR_REPORT_INTERFACE==DEVICE_SERIAL) @@ -148,6 +162,7 @@ void mbed_error_print(char *fmtstr, uint32_t *values) #endif } +#ifdef MBED_CONF_RTOS_PRESENT /* Prints thread info from a list */ void print_threads_info(osRtxThread_t *threads) { @@ -169,8 +184,9 @@ void print_thread(osRtxThread_t *thread) data[4]=thread->sp; mbed_error_print("\nState: 0x%x EntryFn: 0x%x Stack Size: 0x%x Mem: 0x%x SP: 0x%x", data); } +#endif -void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg) +void mbed_report_error(mbed_error_ctx *error_ctx, char *error_msg) { int error_code = GET_MBED_ERROR_CODE(error_ctx->error_status); int error_entity = GET_MBED_ERROR_MODULE(error_ctx->error_status); @@ -234,10 +250,21 @@ void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg) mbed_error_print("\nFile:%s", &file_name); mbed_error_print("+0x%x", (uint32_t *)&error_ctx->error_line_number); } -#endif +#endif + +#ifdef MBED_CONF_RTOS_PRESENT + //Capture thread info + osRtxThread_t *current_thread = osRtxInfo.thread.run.curr; + error_ctx->thread_id = (uint32_t)current_thread; + error_ctx->thread_entry_address = (uint32_t)current_thread->thread_addr; + error_ctx->thread_stack_size = current_thread->stack_size; + error_ctx->thread_stack_mem = (uint32_t)current_thread->stack_mem; + error_ctx->thread_current_sp = get_current_sp(); + //Take advantage of the fact that the thread info in context struct is consecutively placed mbed_error_print("\nError Value: 0x%x\nCurrent Thread: Id: 0x%x EntryFn: 0x%x StackSize: 0x%x StackMem: 0x%x SP: 0x%x ", (uint32_t *)&error_ctx->error_value); +#endif } mbed_error_print("\n-- MbedOS Error Info --", NULL); diff --git a/platform/mbed_error_report.h b/platform/mbed_error_report.h index b485eab4c4..b933abd820 100644 --- a/platform/mbed_error_report.h +++ b/platform/mbed_error_report.h @@ -27,15 +27,18 @@ extern "C" { #define MBED_CONF_ERROR_REPORT_INTERFACE DEVICE_SERIAL #endif -/* Routine to report the error */ -void mbed_report_error(const mbed_error_ctx *error_ctx, char *error_msg); - +#ifdef MBED_CONF_RTOS_PRESENT +#include "rtx_os.h" /* Prints thread info from a list */ void print_threads_info(osRtxThread_t *threads); /* Prints info of a thread(using osRtxThread_t struct)*/ void print_thread(osRtxThread_t *thread); +#endif +/* Routine to report the error */ +void mbed_report_error(mbed_error_ctx *error_ctx, char *error_msg); + /* Limited print functionality which prints the string out to stdout/uart without using stdlib by directly calling serial-api and also uses less resources diff --git a/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c b/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c index c61f767d68..3dae20ccb0 100644 --- a/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c +++ b/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c @@ -16,7 +16,6 @@ #include "rtx_os.h" #include "device.h" -#include "mbed_rtx.h" #include "platform/mbed_error.h" #include "platform/mbed_error_report.h" @@ -83,7 +82,7 @@ __NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_conte mbed_error_print("\n\n-- MbedOS Fault Handler --\n\n",NULL); //Now call set_error, to log the error and halt the system - set_error( MAKE_ERROR( MODULE_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC, NULL, 0 ); + set_error( MAKE_ERROR( MODULE_UNKNOWN, faultStatus ), "System encountered an unrecoverable fault excaption, halting system.", mbed_fault_context.PC_reg, NULL, 0 ); /* In case we return, just spin here, we have already crashed */ for (;;) { diff --git a/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h b/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h index fa31e7375e..37a0514442 100644 --- a/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h +++ b/rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.h @@ -21,22 +21,22 @@ //WARNING: DO NOT CHANGE THIS STRUCT WITHOUT MAKING CORRESPONDING CHANGES in except.S files. //Offset of these registers are used by fault handler in except.S typedef struct { - uint32_t R0; - uint32_t R1; - uint32_t R2; - uint32_t R3; - uint32_t R4; - uint32_t R5; - uint32_t R6; - uint32_t R7; - uint32_t R8; - uint32_t R9; - uint32_t R10; - uint32_t R11; - uint32_t R12; - uint32_t SP; - uint32_t LR; - uint32_t PC; + uint32_t R0_reg; + uint32_t R1_reg; + uint32_t R2_reg; + uint32_t R3_reg; + uint32_t R4_reg; + uint32_t R5_reg; + uint32_t R6_reg; + uint32_t R7_reg; + uint32_t R8_reg; + uint32_t R9_reg; + uint32_t R10_reg; + uint32_t R11_reg; + uint32_t R12_reg; + uint32_t SP_reg; + uint32_t LR_reg; + uint32_t PC_reg; uint32_t xPSR; uint32_t PSP; uint32_t MSP;