1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /** 33 * @defgroup los_printf Printf 34 * @ingroup kernel 35 */ 36 37 #ifndef _LOS_PRINTF_H 38 #define _LOS_PRINTF_H 39 40 #ifdef LOSCFG_LIB_LIBC 41 #include "stdarg.h" 42 #endif 43 #include "los_typedef.h" 44 45 #ifdef __cplusplus 46 #if __cplusplus 47 extern "C" { 48 #endif /* __cplusplus */ 49 #endif /* __cplusplus */ 50 51 extern VOID LOS_LkPrint(INT32 level, const CHAR *func, INT32 line, const CHAR *fmt, ...); 52 53 #define LOS_EMG_LEVEL 0 54 55 #define LOS_COMMON_LEVEL (LOS_EMG_LEVEL + 1) 56 57 #define LOS_ERR_LEVEL (LOS_COMMON_LEVEL + 1) 58 59 #define LOS_WARN_LEVEL (LOS_ERR_LEVEL + 1) 60 61 #define LOS_INFO_LEVEL (LOS_WARN_LEVEL + 1) 62 63 #define LOS_DEBUG_LEVEL (LOS_INFO_LEVEL + 1) 64 65 #define LOS_TRACE_LEVEL (LOS_DEBUG_LEVEL + 1) 66 67 #define PRINT_LEVEL LOS_ERR_LEVEL 68 69 typedef VOID (*pf_OUTPUT)(const CHAR *fmt, ...); 70 71 /** 72 * @ingroup los_printf 73 * @brief Format and print data. 74 * 75 * @par Description: 76 * Print argument(s) according to fmt. 77 * 78 * @attention 79 * <ul> 80 * <li>None</li> 81 * </ul> 82 * 83 * @param fmt [IN] Type char* controls the output as in C printf. 84 * 85 * @retval None 86 * @par Dependency: 87 * <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul> 88 * @see printf 89 */ 90 #ifndef LOSCFG_LIBC_NEWLIB 91 extern void dprintf(const char *fmt, ...); 92 #endif 93 94 #define PRINT_DEBUG(fmt, args...) LOS_LkPrint(LOS_DEBUG_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 95 #define PRINT_INFO(fmt, args...) LOS_LkPrint(LOS_INFO_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 96 #define PRINT_WARN(fmt, args...) LOS_LkPrint(LOS_WARN_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 97 #define PRINT_ERR(fmt, args...) LOS_LkPrint(LOS_ERR_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 98 #define PRINTK(fmt, args...) LOS_LkPrint(LOS_COMMON_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 99 #define PRINT_EMG(fmt, args...) LOS_LkPrint(LOS_EMG_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 100 #define PRINT_RELEASE(fmt, args...) LOS_LkPrint(LOS_COMMON_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 101 #define PRINT_TRACE(fmt, args...) LOS_LkPrint(LOS_TRACE_LEVEL, __FUNCTION__, __LINE__, fmt, ##args) 102 103 typedef enum { 104 NO_OUTPUT = 0, 105 UART_OUTPUT = 1, 106 CONSOLE_OUTPUT = 2, 107 EXC_OUTPUT = 3 108 } OutputType; 109 110 extern VOID OsVprintf(const CHAR *fmt, va_list ap, OutputType type); 111 112 #define UART_WITHOUT_LOCK 0 113 #define UART_WITH_LOCK 1 114 extern VOID UartPuts(const CHAR *s, UINT32 len, BOOL isLock); 115 116 #ifdef __cplusplus 117 #if __cplusplus 118 } 119 #endif /* __cplusplus */ 120 #endif /* __cplusplus */ 121 122 #endif /* _LOS_PRINTF_H */ 123