20
20
#include <inttypes.h>
21
21
22
22
#include "device.h"
23
- #include "platform/mbed_error.h"
24
- #include "platform/mbed_interface.h"
23
+ #include "mbed_error.h"
24
+ #include "mbed_interface.h"
25
+ #include "mbed_crash_data_offsets.h"
25
26
26
27
#ifndef MBED_FAULT_HANDLER_DISABLED
27
28
#include "mbed_fault_handler.h"
28
29
29
30
//Functions Prototypes
30
31
void print_context_info (void );
31
32
32
- //Global for populating the context in exception handler
33
- mbed_fault_context_t mbed_fault_context ;
33
+ #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
34
+ //Global for populating the context in exception handler
35
+ mbed_fault_context_t * mbed_fault_context = (mbed_fault_context_t * )((uint32_t )FAULT_CONTEXT_LOCATION );
36
+ #else
37
+ mbed_fault_context_t fault_context ;
38
+ mbed_fault_context_t * mbed_fault_context = (mbed_fault_context_t * )& fault_context ;
39
+ #endif
34
40
35
41
//This is a handler function called from Fault handler to print the error information out.
36
42
//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.
@@ -69,24 +75,24 @@ void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in)
69
75
mbed_error_printf ("\n\n-- MbedOS Fault Handler --\n\n" );
70
76
71
77
//Now call mbed_error, to log the error and halt the system
72
- mbed_error ( faultStatus , "Fault exception" , mbed_fault_context . PC_reg , NULL , 0 );
78
+ mbed_error ( faultStatus , "Fault exception" , mbed_fault_context -> PC_reg , NULL , 0 );
73
79
74
80
}
75
81
76
82
MBED_NOINLINE void print_context_info (void )
77
83
{
78
84
//Context Regs
79
85
for (int i = 0 ;i < 13 ;i ++ ) {
80
- mbed_error_printf ("\nR%-4d: %08" PRIX32 , i , ((uint32_t * )& mbed_fault_context )[i ]);
86
+ mbed_error_printf ("\nR%-4d: %08" PRIX32 , i , ((uint32_t * )( mbed_fault_context )) [i ]);
81
87
}
82
88
83
89
mbed_error_printf ("\nSP : %08" PRIX32
84
90
"\nLR : %08" PRIX32
85
91
"\nPC : %08" PRIX32
86
92
"\nxPSR : %08" PRIX32
87
93
"\nPSP : %08" PRIX32
88
- "\nMSP : %08" PRIX32 , mbed_fault_context . SP_reg , mbed_fault_context . LR_reg , mbed_fault_context . PC_reg ,
89
- mbed_fault_context . xPSR , mbed_fault_context . PSP , mbed_fault_context . MSP );
94
+ "\nMSP : %08" PRIX32 , mbed_fault_context -> SP_reg , mbed_fault_context -> LR_reg , mbed_fault_context -> PC_reg ,
95
+ mbed_fault_context -> xPSR , mbed_fault_context -> PSP , mbed_fault_context -> MSP );
90
96
91
97
//Capture CPUID to get core/cpu info
92
98
mbed_error_printf ("\nCPUID: %08" PRIX32 , SCB -> CPUID );
@@ -112,12 +118,12 @@ MBED_NOINLINE void print_context_info(void)
112
118
#endif
113
119
114
120
//Print Mode
115
- if (mbed_fault_context . EXC_RETURN & 0x8 ) {
121
+ if (mbed_fault_context -> EXC_RETURN & 0x8 ) {
116
122
mbed_error_printf ("\nMode : Thread" );
117
123
//Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege.
118
124
//Note that the CONTROL register captured still reflects the privilege status of the
119
125
//thread mode eventhough we are in Handler mode by the time we capture it.
120
- if (mbed_fault_context . CONTROL & 0x1 ) {
126
+ if (mbed_fault_context -> CONTROL & 0x1 ) {
121
127
mbed_error_printf ("\nPriv : User" );
122
128
} else {
123
129
mbed_error_printf ("\nPriv : Privileged" );
@@ -127,11 +133,23 @@ MBED_NOINLINE void print_context_info(void)
127
133
mbed_error_printf ("\nPriv : Privileged" );
128
134
}
129
135
//Print Return Stack
130
- if (mbed_fault_context . EXC_RETURN & 0x4 ) {
136
+ if (mbed_fault_context -> EXC_RETURN & 0x4 ) {
131
137
mbed_error_printf ("\nStack: PSP" );
132
138
} else {
133
139
mbed_error_printf ("\nStack: MSP" );
134
140
}
135
141
}
136
142
143
+ mbed_error_status_t mbed_get_reboot_fault_context (mbed_fault_context_t * fault_context )
144
+ {
145
+ mbed_error_status_t status = MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_ITEM_NOT_FOUND );
146
+ #if MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
147
+ if (fault_context == NULL )
148
+ return MBED_MAKE_ERROR (MBED_MODULE_PLATFORM , MBED_ERROR_CODE_INVALID_ARGUMENT );
149
+ memcpy (fault_context , mbed_fault_context , sizeof (mbed_fault_context_t ));
150
+ status = MBED_SUCCESS ;
151
+ #endif
152
+ return status ;
153
+ }
154
+
137
155
#endif //MBED_FAULT_HANDLER_SUPPORT
0 commit comments