/* ----------------------------------------------------------------------------
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved.
* Description: Los_printf HeadFile
* Author: Huawei LiteOS Team
* Create: 2013-01-01
* 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_printf Printf
* @ingroup kernel
*/
#ifndef _LOS_PRINTF_H
#define _LOS_PRINTF_H
#include "stdarg.h"
#include "los_config.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifdef LOSCFG_SHELL_LK
extern void LOS_LkPrint(int level, const char *func, int line, const char *fmt, ...);
#endif
/*LOS_LkPrint 函数接受以下参数:
level:表示打印消息的级别,是一个整数。
func:表示打印消息的函数名,是一个指向字符常量的指针。
line:表示打印消息所在的行号,是一个整数。
fmt:表示打印消息的格式字符串,是一个指向字符常量的指针。
...:表示可变参数列表,用于根据格式字符串打印相应的消息内容。
该函数用于在操作系统中打印消息,可以根据不同的级别和格式打印出不同的信息,用于调试或记录运行时的相关信息。函数的实现可能在其他地方定义。*/
/**
* @ingroup los_printf
* log print level definition, LOS_EMG_LEVEL is set to 0, it means the log is emergency.
*/
#define LOS_EMG_LEVEL 0
/**
* @ingroup los_printf
* log print level definition, LOS_COMMOM_LEVEL is set to 1, it means the log is common.
*/
#define LOS_COMMOM_LEVEL (LOS_EMG_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_ERR_LEVEL is set to 2, it means it is a error log.
*/
#define LOS_ERR_LEVEL (LOS_COMMOM_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_WARN_LEVEL is set to 3, it means it is a warning log.
*/
#define LOS_WARN_LEVEL (LOS_ERR_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_INFO_LEVEL is set to 4, it means the log is an information.
*/
#define LOS_INFO_LEVEL (LOS_WARN_LEVEL + 1)
/**
* @ingroup los_printf
* log print level definition, LOS_DEBUG_LEVEL is set to 5, it means it is a debug log.
*/
#define LOS_DEBUG_LEVEL (LOS_INFO_LEVEL + 1)
/**
* @ingroup los_printf
* The default log print level. PRINT_LEVEL is set to debug log level if
* LOSCFG_SHELL_LK is defined, otherwise PRINT_LEVEL is set to error log level.
* The default log print level means only print the log which its level value
* is lower than or equal to the PRINT_LEVEL.
*/
#ifdef LOSCFG_SHELL_LK
#define PRINT_LEVEL LOS_DEBUG_LEVEL
#else
#define PRINT_LEVEL LOS_ERR_LEVEL
#endif
typedef VOID (*pf_OUTPUT)(const CHAR *fmt, ...);
/*这段代码定义了一个名为 PRINT_LEVEL 的宏以及一个名为 pf_OUTPUT 的函数指针类型。
PRINT_LEVEL 宏根据条件判断是否定义为 LOS_DEBUG_LEVEL 或者 LOS_ERR_LEVEL。
如果宏 LOSCFG_SHELL_LK 被定义,则 PRINT_LEVEL 被定义为 LOS_DEBUG_LEVEL。
否则, PRINT_LEVEL 被定义为 LOS_ERR_LEVEL。
pf_OUTPUT 是一个函数指针类型,指向一个返回值为 VOID 的函数,
该函数接受一个格式化字符串参数 fmt 和可变参数列表 ...。该函数指针类型可以用于声明指向相应函数的指针变量,使得函数的调用可以通过该指针进行。*/
/**
* @ingroup los_printf
* @brief Format and print data.
*
* @par Description:
* Print argument(s) according to fmt.
*
* @attention
* None.
*
* @param fmt [IN] Type char*. It controls the ouput format as in C printf.
*
* @retval None.
* @par Dependency:
*
- los_printf.h: the header file that contains the API declaration.
* @see printf
* @since Huawei LiteOS V100R001C00
*/
extern void dprintf(const char *fmt, ...);
#define diag_printf dprintf
/**
* @ingroup los_printf
* @brief Format and print debug log.
*
* @par Description:
* Define function macros PRINT_DEBUG. The Function can print debug log according to fmt
* when the PRINT_LEVEL is set to LOS_DEBUG_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_DEBUG
#if PRINT_LEVEL < LOS_DEBUG_LEVEL
#define PRINT_DEBUG(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_DEBUG(fmt, ...) LOS_LkPrint(LOS_DEBUG_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_DEBUG(fmt, ...) do { \
(dprintf("[DEBUG] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_DEBUG 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_DEBUG_LEVEL。如果是,则将 PRINT_DEBUG 宏定义为空操作;否则,进入下一层条件编译。
当宏 LOSCFG_SHELL_LK 被定义时,PRINT_DEBUG 宏被定义为调用 LOS_LkPrint 函数,
输出 [DEBUG] 级别的日志信息,其中第一个参数为日志级别 LOS_DEBUG_LEVEL,
第二个参数为当前函数名 __FUNCTION__,第三个参数为当前行号 __LINE__,
第四个参数为格式化字符串 fmt,后面的可变参数列表 ...
用于补充格式化字符串中占位符的值。
否则,PRINT_DEBUG 宏被定义为输出 [DEBUG] 级别的日志信息到控制台。*/
/**
* @ingroup los_printf
* @brief Format and print information log.
*
* @par Description:
* Define function macros PRINT_INFO. The Function can print information log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_INFO_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_INFO
#if PRINT_LEVEL < LOS_INFO_LEVEL
#define PRINT_INFO(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_INFO(fmt, ...) LOS_LkPrint(LOS_INFO_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_INFO(fmt, ...) do { \
(dprintf("[INFO] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_INFO 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_INFO_LEVEL。
如果是,则将 PRINT_INFO 宏定义为空操作;否则,进入下一层条件编译。
当宏 LOSCFG_SHELL_LK 被定义时,PRINT_INFO 宏被定义为调用 LOS_LkPrint 函数,
输出 [INFO] 级别的日志信息,其中第一个参数为日志级别 LOS_INFO_LEVEL,
第二个参数为当前函数名 __FUNCTION__,第三个参数为当前行号 __LINE__,
第四个参数为格式化字符串 fmt,后面的可变参数列表 ... 用于补充格式化字符串中占位符的值。
否则,PRINT_INFO 宏被定义为输出 [INFO] 级别的日志信息到控制台。*/
/**
* @ingroup los_printf
* @brief Format and print warning log.
*
* @par Description:
* Define function macros PRINT_WARN. The Function can print warning log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_WARN_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_WARN
#if PRINT_LEVEL < LOS_WARN_LEVEL
#define PRINT_WARN(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_WARN(fmt, ...) LOS_LkPrint(LOS_WARN_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_WARN(fmt, ...) do { \
(dprintf("[WARN] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_WARN 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_WARN_LEVEL。如果是,则将 PRINT_WARN 宏定义为空操作;否则,进入下一层条件编译。
当宏 LOSCFG_SHELL_LK 被定义时,PRINT_WARN 宏被定义为调用 LOS_LkPrint 函数,
输出 [WARN] 级别的日志信息,其中第一个参数为日志级别 LOS_WARN_LEVEL,
第二个参数为当前函数名 __FUNCTION__,第三个参数为当前行号 __LINE__,
第四个参数为格式化字符串 fmt,后面的可变参数列表 ... 用于补充格式化字符串中占位符的值。
否则,PRINT_WARN 宏被定义为输出 [WARN] 级别的日志信息到控制台。*/
/**
* @ingroup los_printf
* @brief Format and print error log.
*
* @par Description:
* Define function macros PRINT_ERR. The Function can print error log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_ERR_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_ERR
#if PRINT_LEVEL < LOS_ERR_LEVEL
#define PRINT_ERR(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINT_ERR(fmt, ...) LOS_LkPrint(LOS_ERR_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINT_ERR(fmt, ...) do { \
(dprintf("[ERR] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
#endif
/*当宏 PRINT_ERR 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_ERR_LEVEL。如果是,则将 PRINT_ERR 宏定义为空操作;否则,进入下一层条件编译。
当宏 LOSCFG_SHELL_LK 被定义时,PRINT_ERR 宏被定义为调用 LOS_LkPrint 函数,
输出 [ERR] 级别的日志信息,其中第一个参数为日志级别 LOS_ERR_LEVEL
,第二个参数为当前函数名 __FUNCTION__,第三个参数为当前行号 __LINE__,
第四个参数为格式化字符串 fmt,后面的可变参数列表 ... 用于补充格式化字符串中占位符的值。
否则,PRINT_ERR 宏被定义为输出 [ERR] 级别的日志信息到控制台。*/
/**
* @ingroup los_printf
* @brief Format and print common log.
*
* @par Description:
* Define function macros PRINTK. The Function can print common log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_COMMOM_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINTK
#if PRINT_LEVEL < LOS_COMMOM_LEVEL
#define PRINTK(fmt, ...)
#else
#ifdef LOSCFG_SHELL_LK
#define PRINTK(fmt, ...) LOS_LkPrint(LOS_COMMOM_LEVEL, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
#else
#define PRINTK(fmt, ...) dprintf(fmt, ##__VA_ARGS__)
#endif
#endif
#endif
/*这段代码定义了一个名为 PRINTK 的宏。
当宏 PRINTK 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_COMMOM_LEVEL。如果是,则将 PRINTK 宏定义为空操作;否则,进入下一层条件编译。
当宏 LOSCFG_SHELL_LK 被定义时,PRINTK 宏被定义为调用 LOS_LkPrint 函数,
输出 [COMM] 级别的日志信息,其中第一个参数为日志级别 LOS_COMMOM_LEVEL,
第二个参数为当前函数名 __FUNCTION__,第三个参数为当前行号 __LINE__,
第四个参数为格式化字符串 fmt,后面的可变参数列表 ... 用于补充格式化字符串中占位符的值。
否则,PRINTK 宏被定义为输出格式化字符串到控制台。*/
/**
* @ingroup los_printf
* @brief Format and print emergency log.
*
* @par Description:
* Define function macros PRINT_EMG. The Function can print emergency log according to fmt
* when the PRINT_LEVEL is greater than or equal to LOS_EMG_LEVEL.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_EMG
#if PRINT_LEVEL < LOS_EMG_LEVEL
#define PRINT_EMG(fmt, ...)
#else
#define PRINT_EMG(fmt, ...) do { \
(dprintf("[EMG] "), dprintf(fmt, ##__VA_ARGS__)); \
} while (0)
#endif
#endif
/*这段代码定义了一个名为 PRINT_EMG 的宏。
当宏 PRINT_EMG 未被定义时,通过条件编译判断 PRINT_LEVEL 是否小于 LOS_EMG_LEVEL。如果是,则将 PRINT_EMG 宏定义为空操作;否则,进入下一层条件编译。
在 PRINT_LEVEL 大于等于 LOS_EMG_LEVEL 时,PRINT_EMG 宏被定义为输出 [EMG] 级别的日志信息到控制台。*/
/**
* @ingroup los_printf
* @brief Format and print log.
*
* @par Description:
* Define function macros PRINT_RELEASE. The Function can print argument(s) according to fmt.
* It is same with dprintf function.
*
* @attention
* None.
*
* @param fmt [IN] Type: const CHAR *. It controls the ouput format as in C printf.
* @param args [IN] It point to the variable parameters.
*
* @retval None.
* @par Dependency:
* - los_printf.h: the header file that contains the API declaration.
* @see dprintf
* @since Huawei LiteOS V100R001C00
*/
#ifndef PRINT_RELEASE
#define PRINT_RELEASE(fmt, ...) dprintf(fmt, ##__VA_ARGS__)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PRINTF_H */