Skip to content

Commit 020f0e5

Browse files
committed
Astyle format mbed_fault_handler.[ch]
1 parent 49928ec commit 020f0e5

File tree

2 files changed

+89
-88
lines changed

2 files changed

+89
-88
lines changed

platform/TARGET_CORTEX_M/mbed_fault_handler.c

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -32,82 +32,82 @@
3232
void print_context_info(void);
3333

3434
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
35-
//Global for populating the context in exception handler
36-
mbed_fault_context_t *const mbed_fault_context=(mbed_fault_context_t *)(FAULT_CONTEXT_LOCATION);
35+
//Global for populating the context in exception handler
36+
mbed_fault_context_t *const mbed_fault_context = (mbed_fault_context_t *)(FAULT_CONTEXT_LOCATION);
3737
#else
38-
mbed_fault_context_t fault_context;
39-
mbed_fault_context_t *const mbed_fault_context=(mbed_fault_context_t *)&fault_context;
40-
#endif
38+
mbed_fault_context_t fault_context;
39+
mbed_fault_context_t *const mbed_fault_context = (mbed_fault_context_t *) &fault_context;
40+
#endif
4141

4242
//This is a handler function called from Fault handler to print the error information out.
4343
//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.
44-
void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in)
44+
void mbed_fault_handler(uint32_t fault_type, void *mbed_fault_context_in)
4545
{
4646
mbed_error_status_t faultStatus = MBED_SUCCESS;
47-
47+
4848
mbed_error_printf("\n++ MbedOS Fault Handler ++\n\nFaultType: ");
49-
50-
switch( fault_type ) {
51-
case MEMMANAGE_FAULT_EXCEPTION:
52-
mbed_error_printf("MemManageFault");
53-
faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION;
54-
break;
55-
56-
case BUS_FAULT_EXCEPTION:
57-
mbed_error_printf("BusFault");
58-
faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION;
59-
break;
60-
61-
case USAGE_FAULT_EXCEPTION:
62-
mbed_error_printf("UsageFault");
63-
faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION;
64-
break;
65-
66-
//There is no way we can hit this code without getting an exception, so we have the default treated like hardfault
67-
case HARD_FAULT_EXCEPTION:
68-
default:
69-
mbed_error_printf("HardFault");
70-
faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION;
71-
break;
49+
50+
switch (fault_type) {
51+
case MEMMANAGE_FAULT_EXCEPTION:
52+
mbed_error_printf("MemManageFault");
53+
faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION;
54+
break;
55+
56+
case BUS_FAULT_EXCEPTION:
57+
mbed_error_printf("BusFault");
58+
faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION;
59+
break;
60+
61+
case USAGE_FAULT_EXCEPTION:
62+
mbed_error_printf("UsageFault");
63+
faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION;
64+
break;
65+
66+
//There is no way we can hit this code without getting an exception, so we have the default treated like hardfault
67+
case HARD_FAULT_EXCEPTION:
68+
default:
69+
mbed_error_printf("HardFault");
70+
faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION;
71+
break;
7272
}
7373
mbed_error_printf("\n\nContext:");
7474
print_context_info();
75-
75+
7676
mbed_error_printf("\n\n-- MbedOS Fault Handler --\n\n");
77-
77+
7878
//Now call mbed_error, to log the error and halt the system
79-
mbed_error( faultStatus, "Fault exception", mbed_fault_context->PC_reg, NULL, 0 );
80-
79+
mbed_error(faultStatus, "Fault exception", mbed_fault_context->PC_reg, NULL, 0);
80+
8181
}
8282

8383
MBED_NOINLINE void print_context_info(void)
8484
{
8585
//Context Regs
86-
for(int i=0;i<13;i++) {
87-
mbed_error_printf("\nR%-4d: %08" PRIX32, i, ((uint32_t *)(mbed_fault_context))[i]);
86+
for (int i = 0; i < 13; i++) {
87+
mbed_error_printf("\nR%-4d: %08" PRIX32, i, ((uint32_t *)(mbed_fault_context))[i]);
8888
}
89-
89+
9090
mbed_error_printf("\nSP : %08" PRIX32
9191
"\nLR : %08" PRIX32
9292
"\nPC : %08" PRIX32
9393
"\nxPSR : %08" PRIX32
9494
"\nPSP : %08" PRIX32
95-
"\nMSP : %08" PRIX32, mbed_fault_context->SP_reg, mbed_fault_context->LR_reg, mbed_fault_context->PC_reg,
96-
mbed_fault_context->xPSR, mbed_fault_context->PSP, mbed_fault_context->MSP );
97-
95+
"\nMSP : %08" PRIX32, mbed_fault_context->SP_reg, mbed_fault_context->LR_reg, mbed_fault_context->PC_reg,
96+
mbed_fault_context->xPSR, mbed_fault_context->PSP, mbed_fault_context->MSP);
97+
9898
//Capture CPUID to get core/cpu info
9999
mbed_error_printf("\nCPUID: %08" PRIX32, SCB->CPUID);
100-
100+
101101
#if !defined(TARGET_M0) && !defined(TARGET_M0P)
102102
//Capture fault information registers to infer the cause of exception
103103
mbed_error_printf("\nHFSR : %08" PRIX32
104-
"\nMMFSR: %08" PRIX32
105-
"\nBFSR : %08" PRIX32
106-
"\nUFSR : %08" PRIX32
107-
"\nDFSR : %08" PRIX32
108-
"\nAFSR : %08" PRIX32 ////Split/Capture CFSR into MMFSR, BFSR, UFSR
109-
,SCB->HFSR, (0xFF & SCB->CFSR), ((0xFF00 & SCB->CFSR) >> 8), ((0xFFFF0000 & SCB->CFSR) >> 16), SCB->DFSR, SCB->AFSR );
110-
104+
"\nMMFSR: %08" PRIX32
105+
"\nBFSR : %08" PRIX32
106+
"\nUFSR : %08" PRIX32
107+
"\nDFSR : %08" PRIX32
108+
"\nAFSR : %08" PRIX32 ////Split/Capture CFSR into MMFSR, BFSR, UFSR
109+
, SCB->HFSR, (0xFF & SCB->CFSR), ((0xFF00 & SCB->CFSR) >> 8), ((0xFFFF0000 & SCB->CFSR) >> 16), SCB->DFSR, SCB->AFSR);
110+
111111
//Print MMFAR only if its valid as indicated by MMFSR
112112
if ((0xFF & SCB->CFSR) & 0x80) {
113113
mbed_error_printf("\nMMFAR: %08" PRIX32, SCB->MMFAR);
@@ -117,39 +117,40 @@ MBED_NOINLINE void print_context_info(void)
117117
mbed_error_printf("\nBFAR : %08" PRIX32, SCB->BFAR);
118118
}
119119
#endif
120-
120+
121121
//Print Mode
122122
if (mbed_fault_context->EXC_RETURN & 0x8) {
123123
mbed_error_printf("\nMode : Thread");
124124
//Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege.
125-
//Note that the CONTROL register captured still reflects the privilege status of the
125+
//Note that the CONTROL register captured still reflects the privilege status of the
126126
//thread mode eventhough we are in Handler mode by the time we capture it.
127-
if(mbed_fault_context->CONTROL & 0x1) {
128-
mbed_error_printf("\nPriv : User");
127+
if (mbed_fault_context->CONTROL & 0x1) {
128+
mbed_error_printf("\nPriv : User");
129129
} else {
130-
mbed_error_printf("\nPriv : Privileged");
131-
}
130+
mbed_error_printf("\nPriv : Privileged");
131+
}
132132
} else {
133-
mbed_error_printf("\nMode : Handler");
134-
mbed_error_printf("\nPriv : Privileged");
133+
mbed_error_printf("\nMode : Handler");
134+
mbed_error_printf("\nPriv : Privileged");
135135
}
136136
//Print Return Stack
137137
if (mbed_fault_context->EXC_RETURN & 0x4) {
138-
mbed_error_printf("\nStack: PSP");
138+
mbed_error_printf("\nStack: PSP");
139139
} else {
140-
mbed_error_printf("\nStack: MSP");
140+
mbed_error_printf("\nStack: MSP");
141141
}
142142
}
143143

144-
mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t *fault_context)
144+
mbed_error_status_t mbed_get_reboot_fault_context(mbed_fault_context_t *fault_context)
145145
{
146146
mbed_error_status_t status = MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_ITEM_NOT_FOUND);
147147
#if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
148-
if(fault_context == NULL)
148+
if (fault_context == NULL) {
149149
return MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INVALID_ARGUMENT);
150+
}
150151
memcpy(fault_context, mbed_fault_context, sizeof(mbed_fault_context_t));
151152
status = MBED_SUCCESS;
152-
#endif
153+
#endif
153154
return status;
154155
}
155156

platform/TARGET_CORTEX_M/mbed_fault_handler.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,39 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
16+
1717
#ifndef MBED_FAULT_HANDLER_H
1818
#define MBED_FAULT_HANDLER_H
1919

2020
#ifdef __cplusplus
2121
extern "C" {
22-
#endif
22+
#endif
2323

2424
//Fault context struct
2525
//WARNING: DO NOT CHANGE THIS STRUCT WITHOUT MAKING CORRESPONDING CHANGES in except.S files.
2626
//Offset of these registers are used by fault handler in except.S
2727
typedef struct {
28-
uint32_t R0_reg;
29-
uint32_t R1_reg;
30-
uint32_t R2_reg;
31-
uint32_t R3_reg;
32-
uint32_t R4_reg;
33-
uint32_t R5_reg;
34-
uint32_t R6_reg;
35-
uint32_t R7_reg;
36-
uint32_t R8_reg;
37-
uint32_t R9_reg;
38-
uint32_t R10_reg;
39-
uint32_t R11_reg;
40-
uint32_t R12_reg;
41-
uint32_t SP_reg;
42-
uint32_t LR_reg;
43-
uint32_t PC_reg;
44-
uint32_t xPSR;
45-
uint32_t PSP;
46-
uint32_t MSP;
47-
uint32_t EXC_RETURN;
48-
uint32_t CONTROL;
28+
uint32_t R0_reg;
29+
uint32_t R1_reg;
30+
uint32_t R2_reg;
31+
uint32_t R3_reg;
32+
uint32_t R4_reg;
33+
uint32_t R5_reg;
34+
uint32_t R6_reg;
35+
uint32_t R7_reg;
36+
uint32_t R8_reg;
37+
uint32_t R9_reg;
38+
uint32_t R10_reg;
39+
uint32_t R11_reg;
40+
uint32_t R12_reg;
41+
uint32_t SP_reg;
42+
uint32_t LR_reg;
43+
uint32_t PC_reg;
44+
uint32_t xPSR;
45+
uint32_t PSP;
46+
uint32_t MSP;
47+
uint32_t EXC_RETURN;
48+
uint32_t CONTROL;
4949
} mbed_fault_context_t;
5050

5151
//Fault type definitions
@@ -57,20 +57,20 @@ typedef struct {
5757

5858
//This is a handler function called from Fault handler to print the error information out.
5959
//This runs in fault context and uses special functions(defined in mbed_fault_handler.c) to print the information without using C-lib support.
60-
void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in);
60+
void mbed_fault_handler(uint32_t fault_type, void *mbed_fault_context_in);
6161

6262
/**
6363
* 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.
6464
* @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.
6565
* @return 0 or MBED_SUCCESS on success.
6666
* MBED_ERROR_INVALID_ARGUMENT in case of invalid error_info pointer
67-
* MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by teh system
67+
* MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by teh system
6868
*
6969
*/
70-
mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t *fault_context);
70+
mbed_error_status_t mbed_get_reboot_fault_context(mbed_fault_context_t *fault_context);
7171

7272
#ifdef __cplusplus
7373
}
74-
#endif
74+
#endif
7575

7676
#endif

0 commit comments

Comments
 (0)