Astyle format mbed_fault_handler.[ch]

pull/10366/head
Kevin Bracey 2019-04-10 16:04:43 +03:00
parent 49928ec143
commit 020f0e580d
2 changed files with 89 additions and 88 deletions

View File

@ -32,82 +32,82 @@
void print_context_info(void); void print_context_info(void);
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
//Global for populating the context in exception handler //Global for populating the context in exception handler
mbed_fault_context_t *const mbed_fault_context=(mbed_fault_context_t *)(FAULT_CONTEXT_LOCATION); mbed_fault_context_t *const mbed_fault_context = (mbed_fault_context_t *)(FAULT_CONTEXT_LOCATION);
#else #else
mbed_fault_context_t fault_context; mbed_fault_context_t fault_context;
mbed_fault_context_t *const mbed_fault_context=(mbed_fault_context_t *)&fault_context; mbed_fault_context_t *const mbed_fault_context = (mbed_fault_context_t *) &fault_context;
#endif #endif
//This is a handler function called from Fault handler to print the error information out. //This is a handler function called from Fault handler to print the error information out.
//This runs in fault context and uses special functions(defined in mbed_rtx_fault_handler.c) to print the information without using C-lib support. //This runs in fault context and uses special functions(defined in mbed_rtx_fault_handler.c) to print the information without using C-lib support.
void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in) void mbed_fault_handler(uint32_t fault_type, void *mbed_fault_context_in)
{ {
mbed_error_status_t faultStatus = MBED_SUCCESS; mbed_error_status_t faultStatus = MBED_SUCCESS;
mbed_error_printf("\n++ MbedOS Fault Handler ++\n\nFaultType: "); mbed_error_printf("\n++ MbedOS Fault Handler ++\n\nFaultType: ");
switch( fault_type ) { switch (fault_type) {
case MEMMANAGE_FAULT_EXCEPTION: case MEMMANAGE_FAULT_EXCEPTION:
mbed_error_printf("MemManageFault"); mbed_error_printf("MemManageFault");
faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION; faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION;
break; break;
case BUS_FAULT_EXCEPTION: case BUS_FAULT_EXCEPTION:
mbed_error_printf("BusFault"); mbed_error_printf("BusFault");
faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION; faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION;
break; break;
case USAGE_FAULT_EXCEPTION: case USAGE_FAULT_EXCEPTION:
mbed_error_printf("UsageFault"); mbed_error_printf("UsageFault");
faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION; faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION;
break; break;
//There is no way we can hit this code without getting an exception, so we have the default treated like hardfault //There is no way we can hit this code without getting an exception, so we have the default treated like hardfault
case HARD_FAULT_EXCEPTION: case HARD_FAULT_EXCEPTION:
default: default:
mbed_error_printf("HardFault"); mbed_error_printf("HardFault");
faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION; faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION;
break; break;
} }
mbed_error_printf("\n\nContext:"); mbed_error_printf("\n\nContext:");
print_context_info(); print_context_info();
mbed_error_printf("\n\n-- MbedOS Fault Handler --\n\n"); mbed_error_printf("\n\n-- MbedOS Fault Handler --\n\n");
//Now call mbed_error, to log the error and halt the system //Now call mbed_error, to log the error and halt the system
mbed_error( faultStatus, "Fault exception", mbed_fault_context->PC_reg, NULL, 0 ); mbed_error(faultStatus, "Fault exception", mbed_fault_context->PC_reg, NULL, 0);
} }
MBED_NOINLINE void print_context_info(void) MBED_NOINLINE void print_context_info(void)
{ {
//Context Regs //Context Regs
for(int i=0;i<13;i++) { for (int i = 0; i < 13; i++) {
mbed_error_printf("\nR%-4d: %08" PRIX32, i, ((uint32_t *)(mbed_fault_context))[i]); mbed_error_printf("\nR%-4d: %08" PRIX32, i, ((uint32_t *)(mbed_fault_context))[i]);
} }
mbed_error_printf("\nSP : %08" PRIX32 mbed_error_printf("\nSP : %08" PRIX32
"\nLR : %08" PRIX32 "\nLR : %08" PRIX32
"\nPC : %08" PRIX32 "\nPC : %08" PRIX32
"\nxPSR : %08" PRIX32 "\nxPSR : %08" PRIX32
"\nPSP : %08" PRIX32 "\nPSP : %08" PRIX32
"\nMSP : %08" PRIX32, mbed_fault_context->SP_reg, mbed_fault_context->LR_reg, mbed_fault_context->PC_reg, "\nMSP : %08" PRIX32, mbed_fault_context->SP_reg, mbed_fault_context->LR_reg, mbed_fault_context->PC_reg,
mbed_fault_context->xPSR, mbed_fault_context->PSP, mbed_fault_context->MSP ); mbed_fault_context->xPSR, mbed_fault_context->PSP, mbed_fault_context->MSP);
//Capture CPUID to get core/cpu info //Capture CPUID to get core/cpu info
mbed_error_printf("\nCPUID: %08" PRIX32, SCB->CPUID); mbed_error_printf("\nCPUID: %08" PRIX32, SCB->CPUID);
#if !defined(TARGET_M0) && !defined(TARGET_M0P) #if !defined(TARGET_M0) && !defined(TARGET_M0P)
//Capture fault information registers to infer the cause of exception //Capture fault information registers to infer the cause of exception
mbed_error_printf("\nHFSR : %08" PRIX32 mbed_error_printf("\nHFSR : %08" PRIX32
"\nMMFSR: %08" PRIX32 "\nMMFSR: %08" PRIX32
"\nBFSR : %08" PRIX32 "\nBFSR : %08" PRIX32
"\nUFSR : %08" PRIX32 "\nUFSR : %08" PRIX32
"\nDFSR : %08" PRIX32 "\nDFSR : %08" PRIX32
"\nAFSR : %08" PRIX32 ////Split/Capture CFSR into MMFSR, BFSR, UFSR "\nAFSR : %08" PRIX32 ////Split/Capture CFSR into MMFSR, BFSR, UFSR
,SCB->HFSR, (0xFF & SCB->CFSR), ((0xFF00 & SCB->CFSR) >> 8), ((0xFFFF0000 & SCB->CFSR) >> 16), SCB->DFSR, SCB->AFSR ); , SCB->HFSR, (0xFF & SCB->CFSR), ((0xFF00 & SCB->CFSR) >> 8), ((0xFFFF0000 & SCB->CFSR) >> 16), SCB->DFSR, SCB->AFSR);
//Print MMFAR only if its valid as indicated by MMFSR //Print MMFAR only if its valid as indicated by MMFSR
if ((0xFF & SCB->CFSR) & 0x80) { if ((0xFF & SCB->CFSR) & 0x80) {
mbed_error_printf("\nMMFAR: %08" PRIX32, SCB->MMFAR); mbed_error_printf("\nMMFAR: %08" PRIX32, SCB->MMFAR);
@ -117,39 +117,40 @@ MBED_NOINLINE void print_context_info(void)
mbed_error_printf("\nBFAR : %08" PRIX32, SCB->BFAR); mbed_error_printf("\nBFAR : %08" PRIX32, SCB->BFAR);
} }
#endif #endif
//Print Mode //Print Mode
if (mbed_fault_context->EXC_RETURN & 0x8) { if (mbed_fault_context->EXC_RETURN & 0x8) {
mbed_error_printf("\nMode : Thread"); mbed_error_printf("\nMode : Thread");
//Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege. //Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege.
//Note that the CONTROL register captured still reflects the privilege status of the //Note that the CONTROL register captured still reflects the privilege status of the
//thread mode eventhough we are in Handler mode by the time we capture it. //thread mode eventhough we are in Handler mode by the time we capture it.
if(mbed_fault_context->CONTROL & 0x1) { if (mbed_fault_context->CONTROL & 0x1) {
mbed_error_printf("\nPriv : User"); mbed_error_printf("\nPriv : User");
} else { } else {
mbed_error_printf("\nPriv : Privileged"); mbed_error_printf("\nPriv : Privileged");
} }
} else { } else {
mbed_error_printf("\nMode : Handler"); mbed_error_printf("\nMode : Handler");
mbed_error_printf("\nPriv : Privileged"); mbed_error_printf("\nPriv : Privileged");
} }
//Print Return Stack //Print Return Stack
if (mbed_fault_context->EXC_RETURN & 0x4) { if (mbed_fault_context->EXC_RETURN & 0x4) {
mbed_error_printf("\nStack: PSP"); mbed_error_printf("\nStack: PSP");
} else { } else {
mbed_error_printf("\nStack: MSP"); mbed_error_printf("\nStack: MSP");
} }
} }
mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t *fault_context) mbed_error_status_t mbed_get_reboot_fault_context(mbed_fault_context_t *fault_context)
{ {
mbed_error_status_t status = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_ITEM_NOT_FOUND); mbed_error_status_t status = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_ITEM_NOT_FOUND);
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
if(fault_context == NULL) if (fault_context == NULL) {
return MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT); return MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT);
}
memcpy(fault_context, mbed_fault_context, sizeof(mbed_fault_context_t)); memcpy(fault_context, mbed_fault_context, sizeof(mbed_fault_context_t));
status = MBED_SUCCESS; status = MBED_SUCCESS;
#endif #endif
return status; return status;
} }

View File

@ -13,39 +13,39 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MBED_FAULT_HANDLER_H #ifndef MBED_FAULT_HANDLER_H
#define MBED_FAULT_HANDLER_H #define MBED_FAULT_HANDLER_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
//Fault context struct //Fault context struct
//WARNING: DO NOT CHANGE THIS STRUCT WITHOUT MAKING CORRESPONDING CHANGES in except.S files. //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 //Offset of these registers are used by fault handler in except.S
typedef struct { typedef struct {
uint32_t R0_reg; uint32_t R0_reg;
uint32_t R1_reg; uint32_t R1_reg;
uint32_t R2_reg; uint32_t R2_reg;
uint32_t R3_reg; uint32_t R3_reg;
uint32_t R4_reg; uint32_t R4_reg;
uint32_t R5_reg; uint32_t R5_reg;
uint32_t R6_reg; uint32_t R6_reg;
uint32_t R7_reg; uint32_t R7_reg;
uint32_t R8_reg; uint32_t R8_reg;
uint32_t R9_reg; uint32_t R9_reg;
uint32_t R10_reg; uint32_t R10_reg;
uint32_t R11_reg; uint32_t R11_reg;
uint32_t R12_reg; uint32_t R12_reg;
uint32_t SP_reg; uint32_t SP_reg;
uint32_t LR_reg; uint32_t LR_reg;
uint32_t PC_reg; uint32_t PC_reg;
uint32_t xPSR; uint32_t xPSR;
uint32_t PSP; uint32_t PSP;
uint32_t MSP; uint32_t MSP;
uint32_t EXC_RETURN; uint32_t EXC_RETURN;
uint32_t CONTROL; uint32_t CONTROL;
} mbed_fault_context_t; } mbed_fault_context_t;
//Fault type definitions //Fault type definitions
@ -57,20 +57,20 @@ typedef struct {
//This is a handler function called from Fault handler to print the error information out. //This is a handler function called from Fault handler to print the error information out.
//This runs in fault context and uses special functions(defined in mbed_fault_handler.c) to print the information without using C-lib support. //This runs in fault context and uses special functions(defined in mbed_fault_handler.c) to print the information without using C-lib support.
void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in); void mbed_fault_handler(uint32_t fault_type, void *mbed_fault_context_in);
/** /**
* Call this function to retrieve the fault context after a fatal exception which triggered a system reboot. The function retrieves the fault context stored in crash-report ram area which is preserved over reboot. * Call this function to retrieve the fault context after a fatal exception which triggered a system reboot. The function retrieves the fault context stored in crash-report ram area which is preserved over reboot.
* @param fault_context Pointer to mbed_fault_context_t struct allocated by the caller. This is the mbed_fault_context_t info captured as part of the fatal exception which triggered the reboot. * @param fault_context Pointer to mbed_fault_context_t struct allocated by the caller. This is the mbed_fault_context_t info captured as part of the fatal exception which triggered the reboot.
* @return 0 or MBED_SUCCESS on success. * @return 0 or MBED_SUCCESS on success.
* MBED_ERROR_INVALID_ARGUMENT in case of invalid error_info pointer * MBED_ERROR_INVALID_ARGUMENT in case of invalid error_info pointer
* MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by teh system * MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by teh system
* *
*/ */
mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t *fault_context); mbed_error_status_t mbed_get_reboot_fault_context(mbed_fault_context_t *fault_context);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif