1 /** 2 ****************************************************************************** 3 * @file tae32f53xx_dbg.h 4 * @author MCD Application Team 5 * @brief The macro definitions for dbg 6 * 7 ============================================================================== 8 ##### How to use ##### 9 ============================================================================== 10 * 11 * If you want to use debug macro, you can use as following steps: 12 * 13 * Step 1: Macros in "tae32f53xx_dbg_conf.h" 14 * a. Define the TAE_USING_DBG to enable the feature 15 * #define TAE_USING_DBG 16 * 17 * b. Define the print interface for dbg 18 * #define TAE_DBG_PRINT(...) printf(__VA_ARGS__) 19 * 20 * c. Other optional macros define, such as TAE_USING_DBG_COLOR 21 * 22 * Step 2: Macros in your C/C++ file 23 * a. Define the debug tag and level for dbg. If you did not define this, 24 default definition will be used. 25 * #define DBG_TAG "TAG" // must be string 26 * #define DBG_LVL DBG_INFO // others DBG_ERROR, DBG_WARNING, DBG_LOG. 27 * DBG_LOG > DBG_INFO > DBG_WARNING > DBG_ERROR 28 * 29 * b. Include this header file 30 * #include "tae32f53xx_dbg.h" // this must after of DBG_LVL, DBG_TAG or other options 31 * 32 * Step 3: LOG_X macro to print out logs in your C/C++ file 33 * PLEASE NOTE: LOG_X is related to the DBG_LVL that defined in Step 2. Using LOG_X 34 * witch higher then DBG_LVL will be ignored. 35 * LOG_D("this is a debug log!"); 36 * LOG_I("this is a info log!") 37 * LOG_W("this is a warning log!") 38 * LOG_E("this is a error log!"); 39 * 40 ****************************************************************************** 41 * @attention 42 * 43 * <h2><center>© Copyright (c) 2020 Tai-Action. 44 * All rights reserved.</center></h2> 45 * 46 * This software is licensed by Tai-Action under BSD 3-Clause license, 47 * the "License"; You may not use this file except in compliance with the 48 * License. You may obtain a copy of the License at: 49 * opensource.org/licenses/BSD-3-Clause 50 * 51 ****************************************************************************** 52 */ 53 54 /* Define to prevent recursive inclusion -------------------------------------*/ 55 #ifndef _TAE32F53XX_DBG_H_ 56 #define _TAE32F53XX_DBG_H_ 57 58 #ifdef __cplusplus 59 extern "C" { 60 #endif /* __cplusplus */ 61 62 /* Includes ------------------------------------------------------------------*/ 63 #include "tae32f53xx_dbg_conf.h" 64 65 66 /** @addtogroup TAE_Utilities 67 * @{ 68 */ 69 70 /** @defgroup TAE_Debug TAE Debug 71 * @brief TAE Debug 72 * @{ 73 */ 74 75 76 /* Exported types ------------------------------------------------------------*/ 77 /* Exported constants --------------------------------------------------------*/ 78 /** @defgroup TAE_Debug_Exported_Constants TAE Debug Exported Constants 79 * @brief TAE Debug Exported Constants 80 * @{ 81 */ 82 83 #ifdef TAE_USING_DBG 84 85 /* DEBUG level */ 86 #define DBG_NONE 0 87 #define DBG_ERROR 1 88 #define DBG_WARNING 2 89 #define DBG_INFO 3 90 #define DBG_LOG 4 91 92 /* The color for terminal (foreground) */ 93 #define BLACK 30 94 #define RED 31 95 #define GREEN 32 96 #define YELLOW 33 97 #define BLUE 34 98 #define PURPLE 35 99 #define CYAN 36 100 #define WHITE 37 101 #define CLEAR_ALL 0 102 103 #ifndef DBG_TAG 104 #define DBG_TAG "DBG" 105 #endif 106 107 #ifndef DBG_LVL 108 #define DBG_LVL DBG_WARNING 109 #endif 110 111 #ifndef TAE_DBG_PRINT 112 #define TAE_DBG_PRINT(fmt, ...) 113 #endif 114 115 #endif /* TAE_USING_DBG */ 116 117 /** 118 * @} 119 */ 120 121 122 /* Exported macro ------------------------------------------------------------*/ 123 /** @defgroup TAE_Debug_Exported_Macros TAE Debug Exported Macros 124 * @brief TAE Debug Exported Macros 125 * @{ 126 */ 127 128 #ifdef TAE_USING_DBG 129 130 #ifdef TAE_USING_DBG_COLOR 131 #define _DBG_COLOR(color) TAE_DBG_PRINT("\033["#color"m") 132 #define _DBG_LOG_HEAD(lvl_name, color) TAE_DBG_PRINT("\033["#color"m[" lvl_name "@" DBG_TAG "] ") 133 #define _DBG_LOG_END() TAE_DBG_PRINT("\033[0m") 134 #else 135 #define _DBG_COLOR(color) 136 #define _DBG_LOG_HEAD(lvl_name, color) TAE_DBG_PRINT("[" lvl_name "@" DBG_TAG "] ") 137 #define _DBG_LOG_END() TAE_DBG_PRINT("") 138 #endif /* TAE_USING_DBG_COLOR */ 139 140 141 #define DBG_LogRaw(...) TAE_DBG_PRINT(__VA_ARGS__) 142 143 #define DBG_Log(lvl_name, color, fmt, ...) \ 144 do { \ 145 _DBG_LOG_HEAD(lvl_name, color); \ 146 TAE_DBG_PRINT(fmt, ##__VA_ARGS__); \ 147 _DBG_COLOR(0); \ 148 } while (0) 149 150 #define DBG_LogLine(lvl_name, color, fmt, ...) \ 151 do { \ 152 _DBG_LOG_HEAD(lvl_name, color); \ 153 TAE_DBG_PRINT(fmt, ##__VA_ARGS__); \ 154 _DBG_COLOR(0); \ 155 _DBG_LOG_END(); \ 156 } while (0) 157 158 #define DBG_Here() \ 159 if ((DBG_LVL) >= DBG_INFO) { \ 160 _DBG_LOG_HEAD("I", 32); \ 161 TAE_DBG_PRINT("Here is %s:%d", __FUNCTION__, \ 162 __LINE__); \ 163 _DBG_COLOR(0); \ 164 _DBG_LOG_END(); \ 165 } 166 167 #define DBG_Enter() \ 168 if ((DBG_LVL) >= DBG_INFO) { \ 169 _DBG_LOG_HEAD("I", 32); \ 170 TAE_DBG_PRINT("Enter function %s", __FUNCTION__); \ 171 _DBG_COLOR(0); \ 172 _DBG_LOG_END(); \ 173 } 174 175 #define DBG_Exit() \ 176 if ((DBG_LVL) >= DBG_INFO) { \ 177 _DBG_LOG_HEAD("I", 32); \ 178 TAE_DBG_PRINT("Exit function %s", __FUNCTION__); \ 179 _DBG_COLOR(0); \ 180 _DBG_LOG_END(); \ 181 } 182 183 #else 184 185 #define DBG_Log(level, fmt, ...) 186 #define DBG_LogLine(lvl_name, color, fmt, ...) 187 #define DBG_LogRaw(...) 188 #define DBG_Here() 189 #define DBG_Enter() 190 #define DBG_Exit() 191 192 #endif /* TAE_USING_DBG */ 193 194 195 #if (DBG_LVL >= DBG_LOG) 196 #define LOG_D(fmt, ...) DBG_LogLine("D", CLEAR_ALL, fmt, ##__VA_ARGS__) 197 #else 198 #define LOG_D(fmt, ...) 199 #endif 200 201 #if (DBG_LVL >= DBG_INFO) 202 #define LOG_I(fmt, ...) DBG_LogLine("I", GREEN, fmt, ##__VA_ARGS__) 203 #else 204 #define LOG_I(fmt, ...) 205 #endif 206 207 #if (DBG_LVL >= DBG_WARNING) 208 #define LOG_W(fmt, ...) DBG_LogLine("W", YELLOW, fmt, ##__VA_ARGS__) 209 #else 210 #define LOG_W(fmt, ...) 211 #endif 212 213 #if (DBG_LVL >= DBG_ERROR) 214 #define LOG_E(fmt, ...) DBG_LogLine("E", RED, fmt, ##__VA_ARGS__) 215 #else 216 #define LOG_E(fmt, ...) 217 #endif 218 219 #define LOG_R(...) DBG_LogRaw(__VA_ARGS__) 220 221 #define LOG_Enter() DBG_Enter() 222 223 #define LOG_Exit() DBG_Exit() 224 225 #define LOG_Here() DBG_Here() 226 227 /** 228 * @} 229 */ 230 231 232 /* Exported functions --------------------------------------------------------*/ 233 /* Private types -------------------------------------------------------------*/ 234 /* Private variables ---------------------------------------------------------*/ 235 /* Private constants ---------------------------------------------------------*/ 236 /* Private macros ------------------------------------------------------------*/ 237 /* Private functions ---------------------------------------------------------*/ 238 239 240 /** 241 * @} 242 */ 243 244 /** 245 * @} 246 */ 247 248 249 #ifdef __cplusplus 250 } 251 #endif /* __cplusplus */ 252 253 254 #endif /* _TAE32F53XX_DBG_H_ */ 255 256 257 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/ 258 259