13d8536b4Sopenharmony_ci/* 23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 43d8536b4Sopenharmony_ci * 53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met: 73d8536b4Sopenharmony_ci * 83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 93d8536b4Sopenharmony_ci * conditions and the following disclaimer. 103d8536b4Sopenharmony_ci * 113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 123d8536b4Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 133d8536b4Sopenharmony_ci * provided with the distribution. 143d8536b4Sopenharmony_ci * 153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 163d8536b4Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 173d8536b4Sopenharmony_ci * permission. 183d8536b4Sopenharmony_ci * 193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 303d8536b4Sopenharmony_ci */ 313d8536b4Sopenharmony_ci 323d8536b4Sopenharmony_ci/**@defgroup los_debug 333d8536b4Sopenharmony_ci * @ingroup kernel 343d8536b4Sopenharmony_ci */ 353d8536b4Sopenharmony_ci 363d8536b4Sopenharmony_ci#ifndef _LOS_DEBUG_H 373d8536b4Sopenharmony_ci#define _LOS_DEBUG_H 383d8536b4Sopenharmony_ci 393d8536b4Sopenharmony_ci#include "los_config.h" 403d8536b4Sopenharmony_ci#include "los_compiler.h" 413d8536b4Sopenharmony_ci 423d8536b4Sopenharmony_ci#ifdef __cplusplus 433d8536b4Sopenharmony_ci#if __cplusplus 443d8536b4Sopenharmony_ciextern "C" { 453d8536b4Sopenharmony_ci#endif /* __cplusplus */ 463d8536b4Sopenharmony_ci#endif /* __cplusplus */ 473d8536b4Sopenharmony_ci 483d8536b4Sopenharmony_ci#if (LOSCFG_PLATFORM_EXC == 1) 493d8536b4Sopenharmony_cienum MemMangType { 503d8536b4Sopenharmony_ci MEM_MANG_MEMBOX, 513d8536b4Sopenharmony_ci MEM_MANG_MEMORY, 523d8536b4Sopenharmony_ci MEM_MANG_EMPTY 533d8536b4Sopenharmony_ci}; 543d8536b4Sopenharmony_ci 553d8536b4Sopenharmony_citypedef struct { 563d8536b4Sopenharmony_ci UINT32 type; 573d8536b4Sopenharmony_ci UINT32 startAddr; 583d8536b4Sopenharmony_ci UINT32 size; 593d8536b4Sopenharmony_ci VOID *blkAddrArray; 603d8536b4Sopenharmony_ci} MemInfo; 613d8536b4Sopenharmony_ci 623d8536b4Sopenharmony_citypedef struct { 633d8536b4Sopenharmony_ci enum MemMangType type; 643d8536b4Sopenharmony_ci UINT32 startAddr; 653d8536b4Sopenharmony_ci UINT32 size; 663d8536b4Sopenharmony_ci UINT32 free; 673d8536b4Sopenharmony_ci UINT32 blockSize; 683d8536b4Sopenharmony_ci UINT32 errorAddr; 693d8536b4Sopenharmony_ci UINT32 errorLen; 703d8536b4Sopenharmony_ci UINT32 errorOwner; 713d8536b4Sopenharmony_ci} MemInfoCB; 723d8536b4Sopenharmony_ci#endif 733d8536b4Sopenharmony_ci 743d8536b4Sopenharmony_citypedef enum { 753d8536b4Sopenharmony_ci EXC_REBOOT, 763d8536b4Sopenharmony_ci EXC_ASSERT, 773d8536b4Sopenharmony_ci EXC_PANIC, 783d8536b4Sopenharmony_ci EXC_STACKOVERFLOW, 793d8536b4Sopenharmony_ci EXC_INTERRUPT, 803d8536b4Sopenharmony_ci EXC_TYPE_END 813d8536b4Sopenharmony_ci} EXC_TYPE; 823d8536b4Sopenharmony_ci 833d8536b4Sopenharmony_citypedef VOID (*ExcHookFn)(EXC_TYPE excType); 843d8536b4Sopenharmony_ci 853d8536b4Sopenharmony_ciVOID OsExcHookRegister(ExcHookFn excHookFn); 863d8536b4Sopenharmony_ci 873d8536b4Sopenharmony_ciVOID OsDoExcHook(EXC_TYPE excType); 883d8536b4Sopenharmony_ci 893d8536b4Sopenharmony_ci#define LOG_EMG_LEVEL 0 903d8536b4Sopenharmony_ci 913d8536b4Sopenharmony_ci#define LOG_COMMON_LEVEL (LOG_EMG_LEVEL + 1) 923d8536b4Sopenharmony_ci 933d8536b4Sopenharmony_ci#define LOG_ERR_LEVEL (LOG_COMMON_LEVEL + 1) 943d8536b4Sopenharmony_ci 953d8536b4Sopenharmony_ci#define LOG_WARN_LEVEL (LOG_ERR_LEVEL + 1) 963d8536b4Sopenharmony_ci 973d8536b4Sopenharmony_ci#define LOG_INFO_LEVEL (LOG_WARN_LEVEL + 1) 983d8536b4Sopenharmony_ci 993d8536b4Sopenharmony_ci#define LOG_DEBUG_LEVEL (LOG_INFO_LEVEL + 1) 1003d8536b4Sopenharmony_ci 1013d8536b4Sopenharmony_ci#ifndef PRINT_LEVEL 1023d8536b4Sopenharmony_ci#define PRINT_LEVEL LOG_ERR_LEVEL 1033d8536b4Sopenharmony_ci#endif 1043d8536b4Sopenharmony_ci 1053d8536b4Sopenharmony_citypedef enum { 1063d8536b4Sopenharmony_ci LOG_MODULE_KERNEL, 1073d8536b4Sopenharmony_ci LOG_MODULE_FS, 1083d8536b4Sopenharmony_ci LOS_MODULE_OTHERS 1093d8536b4Sopenharmony_ci} LogModuleType; 1103d8536b4Sopenharmony_ci 1113d8536b4Sopenharmony_ci/** 1123d8536b4Sopenharmony_ci * @ingroup los_printf 1133d8536b4Sopenharmony_ci * @brief Format and print data. 1143d8536b4Sopenharmony_ci * 1153d8536b4Sopenharmony_ci * @par Description: 1163d8536b4Sopenharmony_ci * Print argument(s) according to fmt. 1173d8536b4Sopenharmony_ci * 1183d8536b4Sopenharmony_ci * @attention 1193d8536b4Sopenharmony_ci * <ul> 1203d8536b4Sopenharmony_ci * <li>None</li> 1213d8536b4Sopenharmony_ci * </ul> 1223d8536b4Sopenharmony_ci * 1233d8536b4Sopenharmony_ci * @param type [IN] Type LogModuleType indicates the log type. 1243d8536b4Sopenharmony_ci * @param level [IN] Type LogLevel indicates the log level. 1253d8536b4Sopenharmony_ci * @param fmt [IN] Type char* controls the output as in C printf. 1263d8536b4Sopenharmony_ci * 1273d8536b4Sopenharmony_ci * @retval None 1283d8536b4Sopenharmony_ci * @par Dependency: 1293d8536b4Sopenharmony_ci * <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul> 1303d8536b4Sopenharmony_ci * @see LOS_Printf 1313d8536b4Sopenharmony_ci */ 1323d8536b4Sopenharmony_ci#if (LOSCFG_KERNEL_PRINTF == 1) 1333d8536b4Sopenharmony_ciextern INT32 printf(const CHAR *fmt, ...); 1343d8536b4Sopenharmony_ciextern INT32 OsLogLevelCheck(INT32 level); 1353d8536b4Sopenharmony_ci#define LOS_Printf(type, level, fmt, args...) do { \ 1363d8536b4Sopenharmony_ci if (!OsLogLevelCheck(level)) { \ 1373d8536b4Sopenharmony_ci printf(fmt, ##args); \ 1383d8536b4Sopenharmony_ci } \ 1393d8536b4Sopenharmony_ci} while (0) 1403d8536b4Sopenharmony_ci#elif (LOSCFG_KERNEL_PRINTF == 0) 1413d8536b4Sopenharmony_ci#define LOS_Printf(type, level, fmt, args...) 1423d8536b4Sopenharmony_ci#else 1433d8536b4Sopenharmony_ciextern VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...); 1443d8536b4Sopenharmony_ci#define LOS_Printf HalConsoleOutput 1453d8536b4Sopenharmony_ci#endif 1463d8536b4Sopenharmony_ci 1473d8536b4Sopenharmony_ci#define PRINT_DEBUG(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_DEBUG_LEVEL, fmt, ##args) 1483d8536b4Sopenharmony_ci#define PRINT_INFO(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_INFO_LEVEL, fmt, ##args) 1493d8536b4Sopenharmony_ci#define PRINT_WARN(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_WARN_LEVEL, fmt, ##args) 1503d8536b4Sopenharmony_ci#define PRINT_ERR(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_ERR_LEVEL, fmt, ##args) 1513d8536b4Sopenharmony_ci#define PRINTK(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_COMMON_LEVEL, fmt, ##args) 1523d8536b4Sopenharmony_ci#define PRINT_EMG(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_EMG_LEVEL, fmt, ##args) 1533d8536b4Sopenharmony_ci 1543d8536b4Sopenharmony_ci#if PRINT_LEVEL < LOG_ERR_LEVEL 1553d8536b4Sopenharmony_ci#define LOS_ASSERT(judge) 1563d8536b4Sopenharmony_ci#else 1573d8536b4Sopenharmony_ci#define LOS_ASSERT(judge) \ 1583d8536b4Sopenharmony_ci do { \ 1593d8536b4Sopenharmony_ci if ((judge) == 0) { \ 1603d8536b4Sopenharmony_ci OsDoExcHook(EXC_ASSERT); \ 1613d8536b4Sopenharmony_ci (VOID)LOS_IntLock(); \ 1623d8536b4Sopenharmony_ci PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \ 1633d8536b4Sopenharmony_ci while (1) { } \ 1643d8536b4Sopenharmony_ci } \ 1653d8536b4Sopenharmony_ci } while (0) 1663d8536b4Sopenharmony_ci#endif 1673d8536b4Sopenharmony_ci 1683d8536b4Sopenharmony_citypedef VOID (*BACK_TRACE_HOOK)(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP); 1693d8536b4Sopenharmony_ciextern VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook); 1703d8536b4Sopenharmony_ciextern VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP); 1713d8536b4Sopenharmony_ci 1723d8536b4Sopenharmony_ci#ifdef __cplusplus 1733d8536b4Sopenharmony_ci#if __cplusplus 1743d8536b4Sopenharmony_ci} 1753d8536b4Sopenharmony_ci#endif /* __cplusplus */ 1763d8536b4Sopenharmony_ci#endif /* __cplusplus */ 1773d8536b4Sopenharmony_ci 1783d8536b4Sopenharmony_ci#endif /* _LOS_PRINTF_H */ 179