/* * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. * * 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_debug * @ingroup kernel */ #ifndef _LOS_DEBUG_H #define _LOS_DEBUG_H #include "los_compiler.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ #define LOS_EMG_LEVEL 0 #define LOS_COMMOM_LEVEL (LOS_EMG_LEVEL + 1) #define LOS_ERR_LEVEL (LOS_COMMOM_LEVEL + 1) #define LOS_WARN_LEVEL (LOS_ERR_LEVEL + 1) #define LOS_INFO_LEVEL (LOS_WARN_LEVEL + 1) #define LOS_DEBUG_LEVEL (LOS_INFO_LEVEL + 1) #ifndef PRINT_LEVEL #define PRINT_LEVEL LOS_ERR_LEVEL #endif /** *@ingroup los_printf *@brief Format and print data. * * @par Description: * Print argument(s) according to fmt. * * @attention * * *@param fmt [IN] Type char* controls the ouput as in C printf. * *@retval None *@par Dependency: * *@see printf *@since Huawei LiteOS V100R001C00 */ extern int printf(char const *str, ...); #define PRINT printf #if PRINT_LEVEL < LOS_DEBUG_LEVEL #define PRINT_DEBUG(fmt, args...) #else #define PRINT_DEBUG(fmt, args...) do{(PRINT("[DEBUG] "), PRINT(fmt, ##args));}while(0) #endif #if PRINT_LEVEL < LOS_INFO_LEVEL #define PRINT_INFO(fmt, args...) #else #define PRINT_INFO(fmt, args...) do{(PRINT("[INFO] "), PRINT(fmt, ##args));}while(0) #endif #if PRINT_LEVEL < LOS_WARN_LEVEL #define PRINT_WARN(fmt, args...) #else #define PRINT_WARN(fmt, args...) do{(PRINT("[WARN] "), PRINT(fmt, ##args));}while(0) #endif #if PRINT_LEVEL < LOS_ERR_LEVEL #define PRINT_ERR(fmt, args...) #else #define PRINT_ERR(fmt, args...) do{(PRINT("[ERR] "), PRINT(fmt, ##args));}while(0) #endif #if PRINT_LEVEL < LOS_COMMOM_LEVEL #define PRINTK(fmt, args...) #else #define PRINTK(fmt, args...) PRINT(fmt, ##args) #endif #if PRINT_LEVEL < LOS_EMG_LEVEL #define PRINT_EMG(fmt, args...) #else #define PRINT_EMG(fmt, args...) do{(PRINT("[EMG] "), PRINT(fmt, ##args));}while(0) #endif #define PRINT_RELEASE(fmt, args...) PRINT(fmt, ##args) #if PRINT_LEVEL < LOS_ERR_LEVEL #define LOS_ASSERT(judge) #else #define LOS_ASSERT(judge) \ do { \ if ((judge) == 0) { \ (VOID)LOS_IntLock(); \ PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \ while (1) { } \ } \ } while (0) #endif /** * @ingroup los_trace * Task error code: Insufficient memory for trace struct. * * Value: 0x02001400 * * Solution: Decrease the maximum number of tasks. */ #define LOS_ERRNO_TRACE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00) /** * @ingroup los_trace * Task error code: User type is invalid when register new trace. * * Value: 0x02001401 * * Solution: Use valid type to regeister the new trace. */ #define LOS_ERRNO_TRACE_TYPE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01) /** * @ingroup los_trace * Task error code: The callback function is null when register new trace. * * Value: 0x02001402 * * Solution: Use valid callback function to regeister the new trace. */ #define LOS_ERRNO_TRACE_FUNCTION_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02) /** * @ingroup los_trace * Task error code: The filled size is 0 when register new trace. * * Value: 0x02001403 * * Solution: Use valid filled size to regeister the new trace. */ #define LOS_ERRNO_TRACE_MAX_SIZE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x03) /** * @ingroup los_trace * It's the total size of trace buffer. It's in the unit of char */ #define LOS_TRACE_BUFFER_SIZE 1024 /** * @ingroup los_trace * It's the legth of tag, filled by los_trace system */ #define LOS_TRACE_TAG_LENGTH sizeof(UINT32) /** * @ingroup los_trace * Stands for the trace type can be registered. */ typedef enum enTraceType { LOS_TRACE_SWITCH = 0, /**< trace for task switch, 0 is reserved for taskswitch */ LOS_TRACE_INTERRUPT = 1, /**< trace for Interrrupt, 1 is reserved for interrupt */ LOS_TRACE_TYPE_NUM = 10, /**< num for the register type, user can use 2~ LOS_TRACE_TYPE_NUM-1 */ } TRACE_TYPE_E; /** * @ingroup los_trace * struct to store the task switch infomation */ typedef struct tagTraceTaskSwitch { UINT8 ucSrcTaskId; /**< source taskid */ UINT8 ucDestTaskId; /**< destination taskid */ UINT32 uwSwitchTick; /**< Time at which the task switch happens */ } TRACE_TASKSWITCH_S; /** * @ingroup los_trace * struct to store the interrupt infomation */ typedef struct tagTraceInterrupt { UINT8 ucIRQEntryExit; /**< 1 stands for that the trace is happend before interrupt function */ /**< 0 stands for that the trace is after before interrupt function */ UINT16 usIRQNo; /**< IRQ number which trigger the interrupt */ UINT32 uwTick; /**< Time at which the the trace is called */ } TRACE_INTERRUPT_S; /** * @ingroup los_trace * union struct to store the interrupt and task switch infomation */ typedef struct tagTrace { union { TRACE_TASKSWITCH_S stTraceTask; /**< It used for trace the task */ TRACE_INTERRUPT_S stTraceInterrupt; /**< It used for trace the interrrupt */ }; } TRACE_S; /** * @ingroup los_trace * Main struct to store the interrupt and task swithc infomation */ typedef struct tagTraceBuffer { UINT16 usTracePos; UINT16 usTraceWrapPos; UINT8 ucBuffer[LOS_TRACE_BUFFER_SIZE]; } TRACE_BUFFER_S; /** * @ingroup los_trace * Struct to store the trace infomaion for each trace type */ typedef struct tagTraceInfo { TRACE_TYPE_E eType; /**< trace type, selected from TRACE_TYPE_E */ UINT16 (*pfnHook)(UINT8 *outBuffer, VOID *pInfo); /**< callback function for the specific trace type. * This function is used to store the infomation * which want to be traced */ } TRACE_INFO_S; /** * @ingroup los_trace * @brief Intialize the trace when the system startup. * * @par Description: * This API is used to intilize the trace for system level. * @attention * * * @param None. * * @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initilize. * @retval #LOS_OK 0x00000000: The intialization is successful. * @par Dependency: * * @see LOS_TraceInit */ extern UINT32 LOS_TraceInit(VOID); /** * @ingroup los_trace * @brief main trace function is called by user to logger the information. * * @par Description: * This API is used to trace the infomation. * @attention * * * @param traceType [IN] TRACE_TYPE_E. Type of trace information. * @param traceInfo [IN] VOID*. It's a input buffer to store trace infomation * * @retval NONE. * * @par Dependency: * * @see LOS_Trace */ extern VOID LOS_Trace(TRACE_TYPE_E traceType, VOID *traceInfo); /** * @ingroup los_trace * @brief register the hook for specific trace type. * * @par Description: * This API is used to register the hook for specific trace type. * @attention * * * @param traceType [IN] TRACE_TYPE_E. Type of trace information. * @param hook [IN] UINT16 (*)(UINT8*, VOID*). It's an callback function to store the useful trace * information * @param size [IN] UINT16. The maximum size the trace will use for the specific trace type. * * @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initilize. * @retval #LOS_ERRNO_TRACE_TYPE_INVALID 0x02001401: The trace type is invalid. Valid type is from * LOS_TRACE_TYPE_NUM-1 * @retval #LOS_ERRNO_TRACE_FUNCTION_NULL 0x02001402: The input callback function is NULL * @retval #LOS_ERRNO_TRACE_MAX_SIZE_INVALID 0x02001403: The information maxmum size is 0 to store. * @retval #LOS_OK 0x00000000: The registeration is successful. * * @par Dependency: * * @see LOS_TraceUserReg */ extern UINT32 LOS_TraceUserReg(TRACE_TYPE_E traceType, UINT16 (*hook)(UINT8 *, VOID *), UINT16 size); #ifdef __cplusplus #if __cplusplus } #endif /* __cplusplus */ #endif /* __cplusplus */ #endif /* _LOS_PRINTF_H */