/* ---------------------------------------------------------------------------- * Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved. * Description: Exception handling HeadFile * Author: Huawei LiteOS Team * Create: 2020-06-24 * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior written * permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * --------------------------------------------------------------------------- */ /** * @defgroup los_exc Exception handling * @ingroup kernel */ #ifndef _LOS_EXC_H #define _LOS_EXC_H #include "arch/exception.h" #include "los_typedef.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ /** * @ingroup los_exc * @brief Kernel panic function. * * @par Description: * Stack function that prints kernel panics. * @attention * * @param fmt [IN] Type #CHAR*. It is a variadic argument. * * @retval None. * * @par Dependency: * los_exc.h: the header file that contains the API declaration. * @since Huawei LiteOS V100R001C00 */ /*LOS_Panic(const CHAR *fmt, ...) 是 LiteOS 操作系统中的一个函数,用于触发系统崩溃。 参数说明: fmt 是一个格式化字符串,表示崩溃信息的格式。 ... 是可变参数列表,根据格式化字符串 fmt 的要求,传入相应的参数。 该函数没有返回值。 调用 LOS_Panic 函数会导致系统进入崩溃状态,即系统无法正常继续执行下去。 通常情况下,该函数用于处理严重错误或不可恢复的异常情况, 以防止系统继续执行可能导致更严重问题的代码。 该函数允许通过格式化字符串传递一些额外的信息, 从而提供关于崩溃原因、位置或其他相关信息的描述。这 些信息可能对于调试和排查问题非常有用。 需要注意的是,LOS_Panic 函数应该谨慎使用,仅在必要时使用。 由于该函数触发系统崩溃,会导致系统停止运行并且无法继续恢复, 因此应该避免在正常的业务逻辑中调用该函数,以免造成不必要的系统中断。*/ VOID LOS_Panic(const CHAR *fmt, ...); /** * @ingroup los_exc * @brief Kernel backtrace function. * * @par Description: * Backtrace function that prints task call stack information traced from the running task. * @attention None. * * @param None. * * @retval None. * * @par Dependency: * los_exc.h: the header file that contains the API declaration. * @since Huawei LiteOS V200R005C10 */ /*VOID LOS_BackTrace(VOID) 是 LiteOS 操作系统中的函数,用于获取当前线程的函数调用栈信息。 该函数没有参数,也没有返回值。 调用 LOS_BackTrace 函数会获取当前线程的函数调用栈信息, 包括每个函数的调用地址以及相应的函数名。这些信息对于调试和排查问题非常有用, 可以帮助开发人员了解程序执行时的函数调用流程,定位问题所在。 通常情况下,LOS_BackTrace 函数用于调试目的,在程序出现异常或错误时, 可以通过打印函数调用栈信息来辅助分析问题原因。 这对于定位崩溃、死锁或其他异常情况非常有帮助。 需要注意的是,LOS_BackTrace 函数的实现可能依赖于具体的硬件平台和编译器, 不同的平台和编译器可能会有不同的实现方式和限制。 因此,在使用该函数时需要了解相关的平台和编译器特性,以确保获取到准确的函数调用栈信息。*/ extern VOID LOS_BackTrace(VOID); #define OsBackTrace LOS_BackTrace //宏定义将 OsBackTrace 替换为 LOS_BackTrace,意味着在代码中使用 OsBackTrace 时,实际上是调用 LOS_BackTrace 函数。 /** * @ingroup los_exc * @brief Kernel task backtrace function. * * @par Description: * Backtrace function that prints task call stack information traced from the input task. * @attention * The input taskID should be valid. * * @param taskID [IN] Type #UINT32. Task ID. * * @retval None. * * @par Dependency: * los_exc.h: the header file that contains the API declaration. * @since Huawei LiteOS V100R001C00 */ /*VOID LOS_TaskBackTrace(UINT32 taskID) 是 LiteOS 操作系统中的函数,用于获取指定任务的函数调用栈信息。 参数说明: taskID 是一个无符号整数,表示要获取函数调用栈信息的目标任务的任务ID。 该函数没有返回值。 调用 LOS_TaskBackTrace 函数可以获取指定任务的函数调用栈信息, 包括每个函数的调用地址以及相应的函数名。这些信息对于调试和排查问题非常有用, 可以帮助开发人员了解指定任务执行时的函数调用流程,定位问题所在。 通常情况下,LOS_TaskBackTrace 函数用于调试目的,在特定任务出现异常或错误时, 可以通过打印该任务的函数调用栈信息来辅助分析问题原因。 这对于定位崩溃、死锁或其他异常情况非常有帮助。 需要注意的是,LOS_TaskBackTrace 函数的实现可能依赖于具体的硬件平台和编译器, 不同的平台和编译器可能会有不同的实现方式和限制。 因此,在使用该函数时需要了解相关的平台和编译器特性,以确保获取到准确的函数调用栈信息。 另外,需要确保指定的任务ID是有效的、存在的任务ID, 否则可能导致获取不到正确的函数调用栈信息。*/ extern VOID LOS_TaskBackTrace(UINT32 taskID); #define OsTaskBackTrace LOS_TaskBackTrace //宏定义将 OsTaskBackTrace 替换为 LOS_TaskBackTrace,意味着在代码中使用 OsTaskBackTrace 时,实际上是调用 LOS_TaskBackTrace 函数。 #ifdef LOSCFG_SHELL_EXCINFO_DUMP /** * @ingroup los_exc * @brief Define the type of functions for reading or writing exception information. * * @par Description: * This definition is used to declare the type of functions for reading or writing exception information. * @attention * The first parameter "startAddr" must be left to save the exception information. * * @param startAddr [IN] The storage space address, it uses to save exception information. * @param space [IN] The storage space size, it is also the size of the last parameter "buf". * @param rwFlag [IN] The write-read flag, 0 for writing,1 for reading, other number is to do nothing. * @param buf [IN] The buffer of storing data. * * @retval none. * @par Dependency: * * @since Huawei LiteOS V200R005C10 */ /*这是一个函数指针类型的定义。它定义了一个名为 LogReadWriteFunc 的函数指针类型, 该函数指针指向一个返回类型为 VOID 的函数, 函数参数为 UINTPTR startAddr、UINT32 space、UINT32 rwFlag 和 CHAR *buf。 这种定义方式可以用来声明符合特定函数签名的函数指针类型,以便在代码中使用。*/ typedef VOID (*LogReadWriteFunc)(UINTPTR startAddr, UINT32 space, UINT32 rwFlag, CHAR *buf); /*这是一个宏定义,将 log_read_write_fn 替换为 LogReadWriteFunc。 注释中指出这是一个旧的API,并建议避免使用它。通过这个宏定义, 可以将 log_read_write_fn 在整个代码中替换为 LogReadWriteFunc,以达到简化和统一的目的。*/ #define log_read_write_fn LogReadWriteFunc /* old API since V200R002C00, please avoid use of it */ /** * @ingroup los_exc * @brief Register the function of recording exception information . * * @par Description: * This API is used to register the function of recording exception information, and specify the * location, size and buffer of the exception information recording. * @attention * The first parameter "startAddr" must be left to save the exception information. * * @param startAddr [IN] The storage space address, it uses to save exception information. * @param space [IN] The storage space size, it is also the size of the third parameter "buf". * @param buf [IN] The buffer of storing exception information. The buffer is allocated or * free in user's code. * @param hook [IN] the function for reading or writing exception information. * * @retval none. * @par Dependency: * * @since Huawei LiteOS V200R002C00 */ /*函数 LOS_ExcInfoRegHook 是在 LiteOS 操作系统中的一个函数。它的作用是设置异常信息寄存器的回调钩子函数。 该函数有四个参数: startAddr:异常信息寄存器的起始地址。 space:异常信息寄存器的大小(以字节为单位)。 buf:用于存储异常信息寄存器内容的缓冲区。 hook:回调钩子函数,类型为 LogReadWriteFunc,即函数指针类型。 具体来说,当发生异常时,LiteOS 将会调用 LOS_ExcInfoRegHook 函数, 并将异常信息寄存器的起始地址、大小和缓冲区作为参数传递给它。 然后,在 LOS_ExcInfoRegHook 函数内部, 可以通过回调钩子函数 hook 来处理异常信息寄存器的内容。 这个功能可以用于自定义异常处理和异常信息记录。通过设置回调钩子函数, 可以在异常发生时获取并处理异常信息寄存器的内容, 以便进行进一步的分析或记录。*/ VOID LOS_ExcInfoRegHook(UINTPTR startAddr, UINT32 space, CHAR *buf, LogReadWriteFunc hook); #endif #ifdef __cplusplus #if __cplusplus } #endif /* __cplusplus */ #endif /* __cplusplus */ #endif /* _LOS_EXC_H */