1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 /** 16 **************************************************************************************** 17 * @file dbg.h 18 * 19 * @brief Declaration of the Debug module environment. 20 * 21 **************************************************************************************** 22 */ 23 #ifndef _DBG_H_ 24 #define _DBG_H_ 25 26 /* 27 * INCLUDE FILES 28 **************************************************************************************** 29 */ 30 #include "plf.h" 31 #include "compiler.h" 32 #include <stdint.h> 33 #include <stdarg.h> 34 35 /** 36 **************************************************************************************** 37 * @defgroup DEBUG DEBUG 38 * @ingroup MACSW 39 * @brief Description of the Debug module. 40 * @{ 41 **************************************************************************************** 42 */ 43 44 /** 45 **************************************************************************************** 46 * @defgroup DBG_PRINT DBG_PRINT 47 * @ingroup DEBUG 48 * @brief Print Debug feature 49 * @{ 50 **************************************************************************************** 51 */ 52 53 /* 54 * DEFINES 55 **************************************************************************************** 56 */ 57 58 #define TRACE(fmt, ...) dbg(fmt, ##__VA_ARGS__) 59 60 /** 61 * @name Debug Print definitions 62 * @{ 63 **************************************************************************************** 64 */ 65 // Possibles values for NX_PRINT 66 #define NX_PRINT_NONE 0 ///< All print macro are discarded 67 #define NX_PRINT_IPC 1 ///< Print are sent to IPC 68 #define NX_PRINT_PRINTF 2 ///< Print are sent to standard printf 69 #define NX_PRINT_PRINTK 3 ///< Print are sent to Linux printk 70 #define NX_PRINT_UART 4 ///< Print are sent to stdio uart 71 72 // Prefix used for module filtering 73 // If you modify any value, modify also DBG_MOD_ macros below 74 #define D_KE "\x80" ///< Prefix for Kernel 75 #define D_DBG "\x81" ///< Prefix for DBG 76 #define D_IPC "\x82" ///< Prefix for IPC 77 #define D_DMA "\x83" ///< Prefix for DMA 78 #define D_MM "\x84" ///< Prefix for LMAC management 79 #define D_TX "\x85" ///< Prefix for Tx path 80 #define D_RX "\x86" ///< Prefix for Rx path 81 #define D_PHY "\x87" ///< Prefix for Modem / RF 82 #define D_UTM "\x88" ///< Prefix for UTM 83 #define D_XX1 "\x89" ///< Prefix unused 84 #define D_XX2 "\x8A" ///< Prefix unused 85 #define D_XX3 "\x8B" ///< Prefix unused 86 #define D_XX4 "\x8C" ///< Prefix unused 87 88 // Prefix used for severity filtering 89 // If you modify any value, modify also DBG_SEV_ macros below 90 #define D_CRT "\x9A" ///< Prefix for critical 91 #define D_ERR "\x9B" ///< Prefix for error 92 #define D_WRN "\x9C" ///< Prefix for warning 93 #define D_INF "\x9D" ///< Prefix for info 94 #define D_VRB "\x9E" ///< Prefix for verbose debug 95 96 /// Module filtering macros, used only by debug module 97 enum dbg_mod_tag 98 { 99 DBG_MOD_IDX_KE = 0, ///< Bit index for Kernel 100 DBG_MOD_IDX_DBG, ///< Bit index for debug 101 DBG_MOD_IDX_IPC, ///< Bit index for IPC 102 DBG_MOD_IDX_DMA, ///< Bit index for DMA 103 DBG_MOD_IDX_MM, ///< Bit index for LMAC management 104 DBG_MOD_IDX_TX, ///< Bit index for Tx path 105 DBG_MOD_IDX_RX, ///< Bit index for Rx path 106 DBG_MOD_IDX_PHY, ///< Bit index for Modem / RF 107 DBG_MOD_IDX_UTM, ///< Bit index for UTM 108 DBG_MOD_IDX_MAX, ///< Number of modules 109 }; 110 111 #define DBG_MOD_MIN 0x80 112 #define DBG_MOD_MAX (DBG_MOD_MIN + DBG_MOD_IDX_MAX) 113 114 #define DBG_MOD_ALL 0xFFFFFFFF 115 116 117 /// Severity filtering macros, used only by debug module 118 enum dbg_sev_tag 119 { 120 DBG_SEV_IDX_NONE = 0, ///< No print allowed 121 DBG_SEV_IDX_CRT, ///< Critical and unspecified allowed only 122 DBG_SEV_IDX_ERR, ///< Error allowed and above 123 DBG_SEV_IDX_WRN, ///< Warning allowed and above 124 DBG_SEV_IDX_INF, ///< Info allowed and above 125 DBG_SEV_IDX_VRB, ///< All allowed 126 DBG_SEV_IDX_MAX, ///< Number of severity levels 127 DBG_SEV_ALL ///< Convenient macro 128 }; 129 130 #define DBG_SEV_MIN 0x9A 131 #define DBG_SEV_MAX 0xA0 132 133 134 #ifdef CFG_DBG 135 void uart_puts(const char* str); 136 void dbg_test_print(const char *fmt, ...); 137 #define dbg(fmt, ...) dbg_test_print(fmt, ## __VA_ARGS__) 138 139 void dbg_print(const char *fmt, ...); 140 #define dbgprint(fmt, ...) dbg_print(fmt, ## __VA_ARGS__) 141 #else 142 #define dbg(fmt, ...) do {} while (0) 143 #endif 144 145 uint32_t dbg_snprintf(char *buffer, uint32_t size, const char *fmt, ...); 146 uint32_t dbg_vsnprintf_offset(char *buffer, uint32_t size, uint32_t offset, const char *fmt, va_list args); 147 148 /** 149 **************************************************************************************** 150 * @brief Execute a pseudo vsnprintf function 151 * 152 * @param[out] buffer Output buffer 153 * @param[in] size Size of the output buffer 154 * @param[in] fmt Format string 155 * @param[in] args Variable list of arguments 156 * 157 * @return Upon successful return, returns the number of characters printed (excluding the 158 * null byte used to end output to strings). If the output was truncated due to the size limit, 159 * then the return value is the number of characters (excluding the terminating 160 * null byte) which would have been written to the final string if enough space had been 161 * available. Thus, a return value of size or more means that the output was truncated. 162 * 163 **************************************************************************************** 164 */ 165 #define dbg_vsnprintf(buffer, size, fmt, args) dbg_vsnprintf_offset(buffer, size, 0, fmt, args) 166 167 168 #define PROF_RTOS_TASK_SET(taskid) 169 #define DBG_CPU_SLEEP_START() 170 #define DBG_CPU_SLEEP_END() 171 172 173 /** 174 ***************************************************************************************** 175 * @brief Declaration of DEBUG environment. 176 * Any module or task will retrieve the DEBUG environment on its own, it is 177 * not passed anymore as a parameter to the function handlers 178 * of the Debug task. If an other module wants to make use of the 179 * environment of debug, it simply needs to include this file and use 180 * the extern global variable. 181 ***************************************************************************************** 182 */ 183 struct debug_env_tag 184 { 185 /// User trace filter (bit set means traces enabled) 186 uint32_t filter_module; 187 /// Severity of filter 188 uint32_t filter_severity; 189 }; 190 191 /// DEBUG module environment declaration. 192 extern struct debug_env_tag dbg_env; 193 194 /** 195 **************************************************************************************** 196 * @brief Initialize the debug module 197 **************************************************************************************** 198 */ 199 void dbg_init(void); 200 201 #ifdef CFG_RTOS 202 #define DBG_MUTEX_ENABLED 0 203 #define DBG_SUSPEND_ENABLED 1 204 #if DBG_MUTEX_ENABLED && DBG_SUSPEND_ENABLED 205 #error "dbg cfg err" 206 #endif 207 208 #if DBG_MUTEX_ENABLED 209 void dbg_rtos_init(void); 210 #endif 211 #endif 212 213 214 /// @} end of group 215 216 #endif // _DBG_H_ 217