tae32f53xx_dbg.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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>&copy; 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. /* Define to prevent recursive inclusion -------------------------------------*/
  54. #ifndef _TAE32F53XX_DBG_H_
  55. #define _TAE32F53XX_DBG_H_
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif /* __cplusplus */
  59. /* Includes ------------------------------------------------------------------*/
  60. #include "tae32f53xx_dbg_conf.h"
  61. /** @addtogroup TAE_Utilities
  62. * @{
  63. */
  64. /** @defgroup TAE_Debug TAE Debug
  65. * @brief TAE Debug
  66. * @{
  67. */
  68. /* Exported types ------------------------------------------------------------*/
  69. /* Exported constants --------------------------------------------------------*/
  70. /** @defgroup TAE_Debug_Exported_Constants TAE Debug Exported Constants
  71. * @brief TAE Debug Exported Constants
  72. * @{
  73. */
  74. #ifdef TAE_USING_DBG
  75. /* DEBUG level */
  76. #define DBG_NONE 0
  77. #define DBG_ERROR 1
  78. #define DBG_WARNING 2
  79. #define DBG_INFO 3
  80. #define DBG_LOG 4
  81. /* The color for terminal (foreground) */
  82. #define BLACK 30
  83. #define RED 31
  84. #define GREEN 32
  85. #define YELLOW 33
  86. #define BLUE 34
  87. #define PURPLE 35
  88. #define CYAN 36
  89. #define WHITE 37
  90. #define CLEAR_ALL 0
  91. #ifndef DBG_TAG
  92. #define DBG_TAG "DBG"
  93. #endif
  94. #ifndef DBG_LVL
  95. #define DBG_LVL DBG_WARNING
  96. #endif
  97. #ifndef TAE_DBG_PRINT
  98. #define TAE_DBG_PRINT(fmt, ...)
  99. #endif
  100. #endif /* TAE_USING_DBG */
  101. /**
  102. * @}
  103. */
  104. /* Exported macro ------------------------------------------------------------*/
  105. /** @defgroup TAE_Debug_Exported_Macros TAE Debug Exported Macros
  106. * @brief TAE Debug Exported Macros
  107. * @{
  108. */
  109. #ifdef TAE_USING_DBG
  110. #ifdef TAE_USING_DBG_COLOR
  111. #define _DBG_COLOR(color) TAE_DBG_PRINT("\033["#color"m")
  112. #define _DBG_LOG_HEAD(lvl_name, color) TAE_DBG_PRINT("\033["#color"m[" lvl_name "@" DBG_TAG "] ")
  113. #define _DBG_LOG_END() TAE_DBG_PRINT("\033[0m")
  114. #else
  115. #define _DBG_COLOR(color)
  116. #define _DBG_LOG_HEAD(lvl_name, color) TAE_DBG_PRINT("[" lvl_name "@" DBG_TAG "] ")
  117. #define _DBG_LOG_END() TAE_DBG_PRINT("")
  118. #endif /* TAE_USING_DBG_COLOR */
  119. #define DBG_LogRaw(...) TAE_DBG_PRINT(__VA_ARGS__)
  120. #define DBG_Log(lvl_name, color, fmt, ...) \
  121. do { \
  122. _DBG_LOG_HEAD(lvl_name, color); \
  123. TAE_DBG_PRINT(fmt, ##__VA_ARGS__); \
  124. _DBG_COLOR(0); \
  125. } while (0)
  126. #define DBG_LogLine(lvl_name, color, fmt, ...) \
  127. do { \
  128. _DBG_LOG_HEAD(lvl_name, color); \
  129. TAE_DBG_PRINT(fmt, ##__VA_ARGS__); \
  130. _DBG_COLOR(0); \
  131. _DBG_LOG_END(); \
  132. } while (0)
  133. #define DBG_Here() \
  134. if ((DBG_LVL) >= DBG_INFO) { \
  135. _DBG_LOG_HEAD("I", 32); \
  136. TAE_DBG_PRINT("Here is %s:%d", __FUNCTION__, \
  137. __LINE__); \
  138. _DBG_COLOR(0); \
  139. _DBG_LOG_END(); \
  140. }
  141. #define DBG_Enter() \
  142. if ((DBG_LVL) >= DBG_INFO) { \
  143. _DBG_LOG_HEAD("I", 32); \
  144. TAE_DBG_PRINT("Enter function %s", __FUNCTION__); \
  145. _DBG_COLOR(0); \
  146. _DBG_LOG_END(); \
  147. }
  148. #define DBG_Exit() \
  149. if ((DBG_LVL) >= DBG_INFO) { \
  150. _DBG_LOG_HEAD("I", 32); \
  151. TAE_DBG_PRINT("Exit function %s", __FUNCTION__); \
  152. _DBG_COLOR(0); \
  153. _DBG_LOG_END(); \
  154. }
  155. #else
  156. #define DBG_Log(level, fmt, ...)
  157. #define DBG_LogLine(lvl_name, color, fmt, ...)
  158. #define DBG_LogRaw(...)
  159. #define DBG_Here()
  160. #define DBG_Enter()
  161. #define DBG_Exit()
  162. #endif /* TAE_USING_DBG */
  163. #if (DBG_LVL >= DBG_LOG)
  164. #define LOG_D(fmt, ...) DBG_LogLine("D", CLEAR_ALL, fmt, ##__VA_ARGS__)
  165. #else
  166. #define LOG_D(fmt, ...)
  167. #endif
  168. #if (DBG_LVL >= DBG_INFO)
  169. #define LOG_I(fmt, ...) DBG_LogLine("I", GREEN, fmt, ##__VA_ARGS__)
  170. #else
  171. #define LOG_I(fmt, ...)
  172. #endif
  173. #if (DBG_LVL >= DBG_WARNING)
  174. #define LOG_W(fmt, ...) DBG_LogLine("W", YELLOW, fmt, ##__VA_ARGS__)
  175. #else
  176. #define LOG_W(fmt, ...)
  177. #endif
  178. #if (DBG_LVL >= DBG_ERROR)
  179. #define LOG_E(fmt, ...) DBG_LogLine("E", RED, fmt, ##__VA_ARGS__)
  180. #else
  181. #define LOG_E(fmt, ...)
  182. #endif
  183. #define LOG_R(...) DBG_LogRaw(__VA_ARGS__)
  184. #define LOG_Enter() DBG_Enter()
  185. #define LOG_Exit() DBG_Exit()
  186. #define LOG_Here() DBG_Here()
  187. /**
  188. * @}
  189. */
  190. /* Exported functions --------------------------------------------------------*/
  191. /* Private types -------------------------------------------------------------*/
  192. /* Private variables ---------------------------------------------------------*/
  193. /* Private constants ---------------------------------------------------------*/
  194. /* Private macros ------------------------------------------------------------*/
  195. /* Private functions ---------------------------------------------------------*/
  196. /**
  197. * @}
  198. */
  199. /**
  200. * @}
  201. */
  202. #ifdef __cplusplus
  203. }
  204. #endif /* __cplusplus */
  205. #endif /* _TAE32F53XX_DBG_H_ */
  206. /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/