1 /* 2 * Copyright 2019 NXP 3 * 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef __EXCEPTION_HANDLING_H__ 9 #define __EXCEPTION_HANDLING_H__ 10 11 #include "fsl_debug_console.h" 12 13 /*! @addtogroup Exception */ 14 /*! @{ */ 15 16 /*! @file */ 17 18 /******************************************************************************* 19 * Configurations 20 ******************************************************************************/ 21 22 /*! @brief Enable or disable exception handling log (1 - enable, 0 - disable) */ 23 #ifndef EXCEPTION_HANDLING_LOG_ENABLE 24 #define EXCEPTION_HANDLING_LOG_ENABLE (0U) 25 #endif 26 27 /******************************************************************************* 28 * Definitions 29 ******************************************************************************/ 30 31 /*! @brief exception stack data structure. */ 32 typedef struct _exception_stack_data_t 33 { 34 /* Software save */ 35 uint32_t IPSR; 36 uint32_t SP; 37 /* Hardware save */ 38 uint32_t R0; 39 uint32_t R1; 40 uint32_t R2; 41 uint32_t R3; 42 uint32_t R12; 43 uint32_t LR; 44 uint32_t PC; 45 uint32_t xPSR; 46 } exception_stack_data_t; 47 48 /*! @brief scb data structure. */ 49 typedef struct _scb_data_text 50 { 51 uint16_t type; /*!< scb register address type, 32 means uint32_t type address, 8 means uint8_t type address */ 52 uint16_t offset; /*!< scb register address offset */ 53 char *str; /*!< string buffer pointer to scb register description string */ 54 } scb_data_text_t; 55 56 #if (defined(EXCEPTION_HANDLING_LOG_ENABLE) && (EXCEPTION_HANDLING_LOG_ENABLE == 1U)) 57 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING) 58 #define EXCEPTION_PRINTF DbgConsole_BlockingPrintf 59 #else 60 #define EXCEPTION_PRINTF DbgConsole_Printf 61 #endif 62 #else 63 #define EXCEPTION_PRINTF \ 64 do \ 65 { \ 66 } while (0) 67 #endif 68 69 /******************************************************************************* 70 * API 71 ******************************************************************************/ 72 73 #if defined(__cplusplus) 74 extern "C" { 75 #endif /* __cplusplus */ 76 77 /*! 78 * @brief Exception data print function. 79 * 80 * This function should be called at first place in the ISR where the R0-R3, R12, LR, PC and xPSR 81 * have been saved in the stack by ARM, 82 * so that the SP and IPSR could be saved right after them. By default, exception handling module will 83 * overwrite the following ISR as the reference: 84 * NMI_Handler, HardFault_Handler, MemManage_Handler, BusFault_Handler, UsageFault_Handler. 85 * The users can refer to these ISRs to have their owner ISRs to output the stack frame information. 86 * 87 * At last, all the stack frame information would be output from UART instance initialized in the debug 88 * console if EXCEPTION_HANDLING_LOG_ENABLE is set to 1. 89 * USB CDC could not be supported. 90 * SWO is not supported yet. 91 * If no UART instance is initialized because debug console is not enabled or there is no HW UART instance available, 92 * the users need to route EXCEPTION_PRINTF to an available IO function to output the stack frame information. 93 * This function should NOT be called in the task context. 94 * 95 * @note For MCUXpresso IDE, make sure unselect Include semihost Hardfault handler feature on SDK import wizard, 96 * otherwise HardFault_Handler function of semihost_hardfault.c project will be used on MCUXpresso project. 97 * Make sure __SEMIHOST_HARDFAULT_DISABLE Macro is defined in if want to use HardFault_Handler function 98 * in exception_handling.c. 99 * 100 * @retval No return vaule. 101 */ 102 void EXCEPTION_DataPrint(void); 103 104 #if defined(__cplusplus) 105 } 106 #endif /* __cplusplus */ 107 108 /*! @}*/ 109 110 #endif /* __EXCEPTION_HANDLING_H__ */ 111