1 /* ---------------------------------------------------------------------------- 2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. 3 * Description: Exception handling HeadFile 4 * Author: Huawei LiteOS Team 5 * Create: 2020-06-24 6 * Redistribution and use in source and binary forms, with or without modification, 7 * are permitted provided that the following conditions are met: 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 14 * to endorse or promote products derived from this software without specific prior written 15 * permission. 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * --------------------------------------------------------------------------- */ 28 29 /** 30 * @defgroup los_exc Exception handling 31 * @ingroup kernel 32 */ 33 #ifndef _LOS_EXC_H 34 #define _LOS_EXC_H 35 36 #include "arch/exception.h" 37 #include "los_config.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif /* __cplusplus */ 42 43 /** 44 * @ingroup los_exc 45 * @brief Kernel panic function. 46 * 47 * @par Description: 48 * Stack function that prints kernel panics. 49 * @attention 50 * <ul> 51 * <li>After this function is called and stack information is printed, the system will fail to respond.</li> 52 * <li>The input parameter can be NULL.</li> 53 * </ul> 54 * @param fmt [IN] Type #CHAR*. It is a variadic argument. 55 * 56 * @retval None. 57 * 58 * @par Dependency: 59 * los_exc.h: the header file that contains the API declaration. 60 * @since Huawei LiteOS V100R001C00 61 */ 62 VOID LOS_Panic(const CHAR *fmt, ...); 63 64 /** 65 * @ingroup los_exc 66 * @brief System panic function. 67 * 68 * @par Description: 69 * Define function macros LOS_PANIC. The Function can handle system panic and print log. 70 * 71 * @attention 72 * None. 73 * 74 * @param fmt [IN] Type: const CHAR *. It controls the output format as in C printf. 75 * @param args [IN] It point to the variable parameters. 76 * 77 * @retval None. 78 * 79 * @par Dependency: 80 * los_exc.h: the header file that contains the API declaration. 81 * @since Huawei LiteOS 206.1 82 */ 83 #ifndef LOS_PANIC 84 #define LOS_PANIC(fmt, ...) LOS_Panic(fmt, ##__VA_ARGS__) 85 #endif 86 87 /** 88 * @ingroup los_exc 89 * @brief Kernel backtrace function. 90 * 91 * @par Description: 92 * Backtrace function that prints task call stack information traced from the running task. 93 * @attention None. 94 * 95 * @param None. 96 * 97 * @retval None. 98 * 99 * @par Dependency: 100 * los_exc.h: the header file that contains the API declaration. 101 * @since Huawei LiteOS V200R005C10 102 */ 103 extern VOID LOS_BackTrace(VOID); 104 #define OsBackTrace LOS_BackTrace 105 106 /** 107 * @ingroup los_exc 108 * @brief Kernel task backtrace function. 109 * 110 * @par Description: 111 * Backtrace function that prints task call stack information traced from the input task. 112 * @attention 113 * The input taskID should be valid. 114 * 115 * @param taskID [IN] Type #UINT32. Task ID. 116 * 117 * @retval None. 118 * 119 * @par Dependency: 120 * los_exc.h: the header file that contains the API declaration. 121 * @since Huawei LiteOS V100R001C00 122 */ 123 extern VOID LOS_TaskBackTrace(UINT32 taskID); 124 #define OsTaskBackTrace LOS_TaskBackTrace 125 126 #ifdef LOSCFG_SHELL_EXCINFO_DUMP 127 /** 128 * @ingroup los_exc 129 * @brief Define the type of functions for reading or writing exception information. 130 * 131 * @par Description: 132 * This definition is used to declare the type of functions for reading or writing exception information. 133 * @attention 134 * The first parameter "startAddr" must be left to save the exception information. 135 * 136 * @param startAddr [IN] The storage space address, it uses to save exception information. 137 * @param space [IN] The storage space size, it is also the size of the last parameter "buf". 138 * @param rwFlag [IN] The write-read flag, 0 for writing,1 for reading, other number is to do nothing. 139 * @param buf [IN] The buffer of storing data. 140 * 141 * @retval none. 142 * @par Dependency: 143 * <ul><li>los_exc.h: the header file that contains the type definition.</li></ul> 144 * @since Huawei LiteOS V200R005C10 145 */ 146 typedef VOID (*LogReadWriteFunc)(UINTPTR startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf); 147 #define log_read_write_fn LogReadWriteFunc /* old API since V200R002C00, please avoid use of it */ 148 149 /** 150 * @ingroup los_exc 151 * @brief Register the function of recording exception information . 152 * 153 * @par Description: 154 * This API is used to register the function of recording exception information, and specify the 155 * location, size and buffer of the exception information recording. 156 * @attention 157 * The first parameter "startAddr" must be left to save the exception information. 158 * 159 * @param startAddr [IN] The storage space address, it uses to save exception information. 160 * @param space [IN] The storage space size, it is also the size of the third parameter "buf". 161 * @param buf [IN] The buffer of storing exception information. The buffer is allocated or 162 * free in user's code. 163 * @param hook [IN] the function for reading or writing exception information. 164 * 165 * @retval none. 166 * @par Dependency: 167 * <ul><li>los_exc.h: the header file that contains the API declaration.</li></ul> 168 * @since Huawei LiteOS V200R002C00 169 */ 170 VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 space, CHAR *buf, LogReadWriteFunc hook); 171 #endif 172 173 #ifdef __cplusplus 174 } 175 #endif /* __cplusplus */ 176 177 #endif /* _LOS_EXC_H */ 178