Mbed OS Reference
Loading...
Searching...
No Matches
mbed_fault_handler.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2006-2018 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef MBED_FAULT_HANDLER_H
19#define MBED_FAULT_HANDLER_H
20
21#include "mbed_toolchain.h"
22#include "mbed_error.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28//Fault context struct
29#ifdef TARGET_CORTEX_M
30//WARNING: DO NOT CHANGE THIS STRUCT WITHOUT MAKING CORRESPONDING CHANGES in except.S files.
31//Offset of these registers are used by fault handler in except.S
32typedef struct {
33 uint32_t R0_reg;
34 uint32_t R1_reg;
35 uint32_t R2_reg;
36 uint32_t R3_reg;
37 uint32_t R4_reg;
38 uint32_t R5_reg;
39 uint32_t R6_reg;
40 uint32_t R7_reg;
41 uint32_t R8_reg;
42 uint32_t R9_reg;
43 uint32_t R10_reg;
44 uint32_t R11_reg;
45 uint32_t R12_reg;
46 uint32_t SP_reg;
47 uint32_t LR_reg;
48 uint32_t PC_reg;
49 uint32_t xPSR;
50 uint32_t PSP;
51 uint32_t MSP;
52 uint32_t EXC_RETURN;
53 uint32_t CONTROL;
55#elif defined TARGET_CORTEX_A
56// This is not currently used, but would be a plausible implementation
57typedef struct {
58 uint32_t R0_reg;
59 uint32_t R1_reg;
60 uint32_t R2_reg;
61 uint32_t R3_reg;
62 uint32_t R4_reg;
63 uint32_t R5_reg;
64 uint32_t R6_reg;
65 uint32_t R7_reg;
66 uint32_t R8_reg;
67 uint32_t R9_reg;
68 uint32_t R10_reg;
69 uint32_t R11_reg;
70 uint32_t R12_reg;
71 uint32_t SP_reg;
72 uint32_t LR_reg;
73 uint32_t PC_reg;
74 uint32_t CPSR;
75 uint32_t SP_usr;
76 uint32_t LR_usr;
78#else
79// Dummy for mbed_crash_data_t
80typedef struct {
82#endif
83
84
85//Fault type definitions
86#ifdef TARGET_CORTEX_M
87//WARNING: DO NOT CHANGE THESE VALUES WITHOUT MAKING CORRESPONDING CHANGES in except.S files.
88#define HARD_FAULT_EXCEPTION (0x10) //Keep some gap between values for any future insertion/expansion
89#define MEMMANAGE_FAULT_EXCEPTION (0x20)
90#define BUS_FAULT_EXCEPTION (0x30)
91#define USAGE_FAULT_EXCEPTION (0x40)
92#endif
93
94//This is a handler function called from Fault handler to print the error information out.
95//This runs in fault context and uses special functions(defined in mbed_fault_handler.c) to print the information without using C-lib support.
96MBED_NORETURN void mbed_fault_handler(uint32_t fault_type, const mbed_fault_context_t *mbed_fault_context_in);
97
98/**
99 * 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.
100 * @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.
101 * @return 0 or MBED_SUCCESS on success.
102 * MBED_ERROR_INVALID_ARGUMENT in case of invalid error_info pointer
103 * MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system
104 *
105 */
106mbed_error_status_t mbed_get_reboot_fault_context(mbed_fault_context_t *fault_context);
107
108#ifdef __cplusplus
109}
110#endif
111
112#endif
int mbed_error_status_t
mbed_error_status_t description
Definition: mbed_error.h:110
#define MBED_NORETURN
MBED_NORETURN Declare a function that will never return.