RTC auf true
rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2006-2018 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | |
kevman | 0:38ceb79fef03 | 17 | #include "rtx_os.h" |
kevman | 0:38ceb79fef03 | 18 | #include "device.h" |
kevman | 0:38ceb79fef03 | 19 | #include "platform/mbed_error.h" |
kevman | 0:38ceb79fef03 | 20 | #include "platform/mbed_interface.h" |
kevman | 0:38ceb79fef03 | 21 | #include "hal/serial_api.h" |
kevman | 0:38ceb79fef03 | 22 | |
kevman | 0:38ceb79fef03 | 23 | #ifndef MBED_FAULT_HANDLER_DISABLED |
kevman | 0:38ceb79fef03 | 24 | #include "mbed_rtx_fault_handler.h" |
kevman | 0:38ceb79fef03 | 25 | |
kevman | 0:38ceb79fef03 | 26 | //Functions Prototypes |
kevman | 0:38ceb79fef03 | 27 | void print_context_info(void); |
kevman | 0:38ceb79fef03 | 28 | |
kevman | 0:38ceb79fef03 | 29 | //Global for populating the context in exception handler |
kevman | 0:38ceb79fef03 | 30 | mbed_fault_context_t mbed_fault_context; |
kevman | 0:38ceb79fef03 | 31 | |
kevman | 0:38ceb79fef03 | 32 | //This is a handler function called from Fault handler to print the error information out. |
kevman | 0:38ceb79fef03 | 33 | //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. |
kevman | 0:38ceb79fef03 | 34 | void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn) |
kevman | 0:38ceb79fef03 | 35 | { |
kevman | 0:38ceb79fef03 | 36 | mbed_error_status_t faultStatus = MBED_SUCCESS; |
kevman | 0:38ceb79fef03 | 37 | |
kevman | 0:38ceb79fef03 | 38 | mbed_error_printf("\n++ MbedOS Fault Handler ++\n\nFaultType: "); |
kevman | 0:38ceb79fef03 | 39 | |
kevman | 0:38ceb79fef03 | 40 | switch( fault_type ) { |
kevman | 0:38ceb79fef03 | 41 | case MEMMANAGE_FAULT_EXCEPTION: |
kevman | 0:38ceb79fef03 | 42 | mbed_error_printf("MemManageFault"); |
kevman | 0:38ceb79fef03 | 43 | faultStatus = MBED_ERROR_MEMMANAGE_EXCEPTION; |
kevman | 0:38ceb79fef03 | 44 | break; |
kevman | 0:38ceb79fef03 | 45 | |
kevman | 0:38ceb79fef03 | 46 | case BUS_FAULT_EXCEPTION: |
kevman | 0:38ceb79fef03 | 47 | mbed_error_printf("BusFault"); |
kevman | 0:38ceb79fef03 | 48 | faultStatus = MBED_ERROR_BUSFAULT_EXCEPTION; |
kevman | 0:38ceb79fef03 | 49 | break; |
kevman | 0:38ceb79fef03 | 50 | |
kevman | 0:38ceb79fef03 | 51 | case USAGE_FAULT_EXCEPTION: |
kevman | 0:38ceb79fef03 | 52 | mbed_error_printf("UsageFault"); |
kevman | 0:38ceb79fef03 | 53 | faultStatus = MBED_ERROR_USAGEFAULT_EXCEPTION; |
kevman | 0:38ceb79fef03 | 54 | break; |
kevman | 0:38ceb79fef03 | 55 | |
kevman | 0:38ceb79fef03 | 56 | //There is no way we can hit this code without getting an exception, so we have the default treated like hardfault |
kevman | 0:38ceb79fef03 | 57 | case HARD_FAULT_EXCEPTION: |
kevman | 0:38ceb79fef03 | 58 | default: |
kevman | 0:38ceb79fef03 | 59 | mbed_error_printf("HardFault"); |
kevman | 0:38ceb79fef03 | 60 | faultStatus = MBED_ERROR_HARDFAULT_EXCEPTION; |
kevman | 0:38ceb79fef03 | 61 | break; |
kevman | 0:38ceb79fef03 | 62 | } |
kevman | 0:38ceb79fef03 | 63 | mbed_error_printf("\n\nContext:"); |
kevman | 0:38ceb79fef03 | 64 | print_context_info(); |
kevman | 0:38ceb79fef03 | 65 | |
kevman | 0:38ceb79fef03 | 66 | mbed_error_printf("\n\n-- MbedOS Fault Handler --\n\n"); |
kevman | 0:38ceb79fef03 | 67 | |
kevman | 0:38ceb79fef03 | 68 | //Now call mbed_error, to log the error and halt the system |
kevman | 0:38ceb79fef03 | 69 | mbed_error( faultStatus, "Fault exception", mbed_fault_context.PC_reg, NULL, 0 ); |
kevman | 0:38ceb79fef03 | 70 | |
kevman | 0:38ceb79fef03 | 71 | } |
kevman | 0:38ceb79fef03 | 72 | |
kevman | 0:38ceb79fef03 | 73 | MBED_NOINLINE void print_context_info(void) |
kevman | 0:38ceb79fef03 | 74 | { |
kevman | 0:38ceb79fef03 | 75 | //Context Regs |
kevman | 0:38ceb79fef03 | 76 | for(int i=0;i<13;i++) { |
kevman | 0:38ceb79fef03 | 77 | mbed_error_printf("\nR%-4d: %08X", i, ((uint32_t *)&mbed_fault_context)[i]); |
kevman | 0:38ceb79fef03 | 78 | } |
kevman | 0:38ceb79fef03 | 79 | |
kevman | 0:38ceb79fef03 | 80 | mbed_error_printf("\nSP : %08X" |
kevman | 0:38ceb79fef03 | 81 | "\nLR : %08X" |
kevman | 0:38ceb79fef03 | 82 | "\nPC : %08X" |
kevman | 0:38ceb79fef03 | 83 | "\nxPSR : %08X" |
kevman | 0:38ceb79fef03 | 84 | "\nPSP : %08X" |
kevman | 0:38ceb79fef03 | 85 | "\nMSP : %08X", mbed_fault_context.SP_reg, mbed_fault_context.LR_reg, mbed_fault_context.PC_reg, |
kevman | 0:38ceb79fef03 | 86 | mbed_fault_context.xPSR, mbed_fault_context.PSP, mbed_fault_context.MSP ); |
kevman | 0:38ceb79fef03 | 87 | |
kevman | 0:38ceb79fef03 | 88 | //Capture CPUID to get core/cpu info |
kevman | 0:38ceb79fef03 | 89 | mbed_error_printf("\nCPUID: %08X", SCB->CPUID); |
kevman | 0:38ceb79fef03 | 90 | |
kevman | 0:38ceb79fef03 | 91 | #if !defined(TARGET_M0) && !defined(TARGET_M0P) |
kevman | 0:38ceb79fef03 | 92 | //Capture fault information registers to infer the cause of exception |
kevman | 0:38ceb79fef03 | 93 | mbed_error_printf("\nHFSR : %08X" |
kevman | 0:38ceb79fef03 | 94 | "\nMMFSR: %08X" |
kevman | 0:38ceb79fef03 | 95 | "\nBFSR : %08X" |
kevman | 0:38ceb79fef03 | 96 | "\nUFSR : %08X" |
kevman | 0:38ceb79fef03 | 97 | "\nDFSR : %08X" |
kevman | 0:38ceb79fef03 | 98 | "\nAFSR : %08X" ////Split/Capture CFSR into MMFSR, BFSR, UFSR |
kevman | 0:38ceb79fef03 | 99 | ,SCB->HFSR, (0xFF & SCB->CFSR), ((0xFF00 & SCB->CFSR) >> 8), ((0xFFFF0000 & SCB->CFSR) >> 16), SCB->DFSR, SCB->AFSR ); |
kevman | 0:38ceb79fef03 | 100 | |
kevman | 0:38ceb79fef03 | 101 | //Print MMFAR only if its valid as indicated by MMFSR |
kevman | 0:38ceb79fef03 | 102 | if ((0xFF & SCB->CFSR) & 0x80) { |
kevman | 0:38ceb79fef03 | 103 | mbed_error_printf("\nMMFAR: %08X",SCB->MMFAR); |
kevman | 0:38ceb79fef03 | 104 | } |
kevman | 0:38ceb79fef03 | 105 | //Print BFAR only if its valid as indicated by BFSR |
kevman | 0:38ceb79fef03 | 106 | if (((0xFF00 & SCB->CFSR) >> 8) & 0x80) { |
kevman | 0:38ceb79fef03 | 107 | mbed_error_printf("\nBFAR : %08X",SCB->BFAR); |
kevman | 0:38ceb79fef03 | 108 | } |
kevman | 0:38ceb79fef03 | 109 | #endif |
kevman | 0:38ceb79fef03 | 110 | |
kevman | 0:38ceb79fef03 | 111 | //Print Mode |
kevman | 0:38ceb79fef03 | 112 | if (mbed_fault_context.EXC_RETURN & 0x8) { |
kevman | 0:38ceb79fef03 | 113 | mbed_error_printf("\nMode : Thread"); |
kevman | 0:38ceb79fef03 | 114 | //Print Priv level in Thread mode - We capture CONTROL reg which reflects the privilege. |
kevman | 0:38ceb79fef03 | 115 | //Note that the CONTROL register captured still reflects the privilege status of the |
kevman | 0:38ceb79fef03 | 116 | //thread mode eventhough we are in Handler mode by the time we capture it. |
kevman | 0:38ceb79fef03 | 117 | if(mbed_fault_context.CONTROL & 0x1) { |
kevman | 0:38ceb79fef03 | 118 | mbed_error_printf("\nPriv : User"); |
kevman | 0:38ceb79fef03 | 119 | } else { |
kevman | 0:38ceb79fef03 | 120 | mbed_error_printf("\nPriv : Privileged"); |
kevman | 0:38ceb79fef03 | 121 | } |
kevman | 0:38ceb79fef03 | 122 | } else { |
kevman | 0:38ceb79fef03 | 123 | mbed_error_printf("\nMode : Handler"); |
kevman | 0:38ceb79fef03 | 124 | mbed_error_printf("\nPriv : Privileged"); |
kevman | 0:38ceb79fef03 | 125 | } |
kevman | 0:38ceb79fef03 | 126 | //Print Return Stack |
kevman | 0:38ceb79fef03 | 127 | if (mbed_fault_context.EXC_RETURN & 0x4) { |
kevman | 0:38ceb79fef03 | 128 | mbed_error_printf("\nStack: PSP"); |
kevman | 0:38ceb79fef03 | 129 | } else { |
kevman | 0:38ceb79fef03 | 130 | mbed_error_printf("\nStack: MSP"); |
kevman | 0:38ceb79fef03 | 131 | } |
kevman | 0:38ceb79fef03 | 132 | } |
kevman | 0:38ceb79fef03 | 133 | |
kevman | 0:38ceb79fef03 | 134 | #endif //MBED_FAULT_HANDLER_SUPPORT |