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 #ifndef _HWLITEOS_SHELL_DMESG_H 33 #define _HWLITEOS_SHELL_DMESG_H 34 #include "los_config.h" 35 #ifdef LOSCFG_SHELL_DMESG 36 37 #ifdef __cplusplus 38 #if __cplusplus 39 extern "C" { 40 #endif /* __cplusplus */ 41 #endif /* __cplusplus */ 42 43 /** 44 * @ingroup dmesg 45 * Defalut dmesg buffer size. 46 */ 47 #define KERNEL_LOG_BUF_SIZE (8 * 1024) 48 49 /** 50 * @ingroup dmesg 51 * Max dmesg buffer size to set. 52 */ 53 #define MAX_KERNEL_LOG_BUF_SIZE (8 * 1024 * 10) 54 55 /** 56 * @ingroup dmesg 57 * @brief Set dmesg buffer. 58 * 59 * @par Description: 60 * This API is used to set dmesg buffer to memory-assigned, or just change the buffer size. 61 * 62 * @attention 63 * <ul> 64 * <li>If the addr is NULL, this function will only change the buffer size.</li> 65 * </ul> 66 * 67 * @param addr [IN] Type #VOID* The addr of memory space to set. 68 * @param size [IN] Type #UINT32 The dmesg buffer size to set, depend on the app user, should be a valid value, 69 * otherwise system will crash, and should not larger than MAX_KERNEL_LOG_BUF_SIZE. 70 * 71 * @retval #LOS_NOK Set dmesg buffer fail. 72 * @retval #LOS_OK Set dmesg buffer success. 73 * @par Dependency: 74 * <ul><li>dmesg.h: the header file that contains the API declaration.</li></ul> 75 * @see LOS_DmesgMemSet 76 */ 77 extern UINT32 LOS_DmesgMemSet(const VOID *addr, UINT32 size); 78 79 /** 80 * @ingroup dmesg 81 * @brief Read log from dmesg buffer. 82 * 83 * @par Description: 84 * This API is used to get log from dmesg buffer in core and copy to the point buffer. 85 * 86 * @attention 87 * <ul> 88 * <li>Length of log been read may be less than the len if log in dmesg buffer is not enough.</li> 89 * </ul> 90 * 91 * @param buf [IN] Type #CHAR* The buffer expected copy to. 92 * @param len [IN] Type #UINT32 The maximum number of bytes that can be accommodated in the buf. 93 * 94 * @retval #-1 Read log from dmesg buffer fail. 95 * @retval #0 Nothing has been read. 96 * @retval #INT32 The length of log has been read. 97 * @par Dependency: 98 * <ul><li>dmesg.h: the header file that contains the API declaration.</li></ul> 99 * @see LOS_DmesgRead 100 */ 101 extern INT32 LOS_DmesgRead(CHAR *buf, UINT32 len); 102 103 /** 104 * @ingroup dmesg 105 * @brief Clear dmesg log. 106 * 107 * @par Description: 108 * This API is used to clear dmesg log. 109 * 110 * @attention None. 111 * 112 * @param None. 113 * 114 * @retval None. 115 * @par Dependency: 116 * <ul><li>dmesg.h: the header file that contains the API declaration.</li></ul> 117 * @see LOS_DmesgClear 118 */ 119 extern VOID LOS_DmesgClear(VOID); 120 121 /** 122 * @ingroup dmesg 123 * @brief Copy log to file. 124 * 125 * @par Description: 126 * This API is used to copy all log from dmesg buffer and write it to the file. 127 * 128 * @attention 129 * <ul> 130 * <li>Files rely on file system, the file system of filename dependent must be already mounted.</li> 131 * </ul> 132 * 133 * @param filename [IN] Type #CHAR* The buffer expected copy to. 134 * 135 * @retval #-1 Copy log to file fail. 136 * @retval #0 Maybe there is no log in the buffer. 137 * @retval #INT32 The length of log has been written to file. 138 * @par Dependency: 139 * <ul><li>dmesg.h: the header file that contains the API declaration.</li></ul> 140 * @see LOS_DmesgToFile 141 */ 142 extern INT32 LOS_DmesgToFile(const CHAR *filename); 143 144 /** 145 * @ingroup dmesg 146 * @brief Set the dmesg level 147 * 148 * @par Description: 149 * This API is used to set the level of log that want to stored in dmesg buffer. 150 * 151 * @attention 152 * <ul> 153 * <li>It would be useless if the level is less than print level.</li> 154 * </ul> 155 * 156 * @param level [IN] Type #UINT32 The level expected to set, range from 0 to 5. 157 * 158 * @retval #1 Set dmesg level fail. 159 * @retval #0 Set dmesg level success. 160 * @par Dependency: 161 * <ul><li>dmesg.h: the header file that contains the API declaration.</li></ul> 162 * @see LOS_DmesgLvSet 163 */ 164 extern UINT32 LOS_DmesgLvSet(UINT32 level); 165 166 #ifdef __cplusplus 167 #if __cplusplus 168 } 169 #endif /* __cplusplus */ 170 #endif /* __cplusplus */ 171 #endif 172 #endif /* _HWLITEOS_SHELL_DMESG_H */ 173