debug.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef _DEBUG_H_
  2. #define _DEBUG_H_
  3. #include "asm/cpu.h"
  4. #include "generic/typedef.h"
  5. // -- output terminal color
  6. #define RedBold "\033[31;1m" // 红色加粗
  7. #define RedBoldBlink "\033[31;1;5m" // 红色加粗、闪烁
  8. #define GreenBold "\033[32;1m" // 红色加粗
  9. #define GreenBoldBlink "\033[32;1;5m" // 红色加粗、闪烁
  10. #define YellowBold "\033[33;1m" // 红色加粗
  11. #define YellowBoldBlink "\033[33;1;5m" // 红色加粗、闪烁
  12. #define BlueBold "\033[34;1m" // 蓝色加粗
  13. #define BlueBoldBlink "\033[34;1;5m" // 蓝色加粗、闪烁
  14. #define PurpleBold "\033[35;1m" // 紫色加粗
  15. #define PurpleBoldBlink "\033[35;1;5m" // 紫色加粗、闪烁
  16. #define DGreenBold "\033[36;1m" // 红色加粗
  17. #define DGreenBoldBlink "\033[36;1;5m" // 红色加粗、闪烁
  18. #define WhiteBold "\033[37;1m" // 红色加粗
  19. #define WhiteBoldBlink "\033[37;1;5m" // 红色加粗、闪烁
  20. #define Reset "\033[0;25m" // 颜色复位
  21. #define LOG_ASSERT_ENABLE
  22. void printf_buf(u8 *buf, u32 len);
  23. #define PRINTF(format, ...) printf(format, ## __VA_ARGS__)
  24. #define LOG_VERBOSE v
  25. #define LOG_INFO i
  26. #define LOG_DEBUG d
  27. #define LOG_WARN w
  28. #define LOG_ERROR e
  29. #define LOG_CHAR c
  30. #define _STR(x) #x
  31. #define STR(x) "["_STR(x)"]"
  32. #define _LOG_TAG_CONST_DECLARE(level, name) extern const char log_tag_const_##level##_##name
  33. #define LOG_TAG_CONST_DECLARE(level, name) _LOG_TAG_CONST_DECLARE(level, name)
  34. #define ___LOG_IS_ENABLE(level, name) (log_tag_const_##level##_##name)
  35. #define __LOG_IS_ENABLE(level, name) ___LOG_IS_ENABLE(level, name)
  36. #define _LOG_IS_ENABLE(level) __LOG_IS_ENABLE(level, LOG_TAG_CONST)
  37. #ifdef LOG_TAG_CONST
  38. LOG_TAG_CONST_DECLARE(LOG_VERBOSE, LOG_TAG_CONST);
  39. LOG_TAG_CONST_DECLARE(LOG_INFO, LOG_TAG_CONST);
  40. LOG_TAG_CONST_DECLARE(LOG_DEBUG, LOG_TAG_CONST);
  41. LOG_TAG_CONST_DECLARE(LOG_WARN, LOG_TAG_CONST);
  42. LOG_TAG_CONST_DECLARE(LOG_ERROR, LOG_TAG_CONST);
  43. LOG_TAG_CONST_DECLARE(LOG_CHAR, LOG_TAG_CONST);
  44. #define _LOG_TAG STR(LOG_TAG_CONST)
  45. #define LOG_IS_ENABLE(level) _LOG_IS_ENABLE(level)
  46. #else
  47. #define _LOG_TAG LOG_TAG
  48. #define LOG_IS_ENABLE(x) 1
  49. #endif
  50. #define LOG_BY_MACRO 1
  51. #define LOG_BY_CONST 2
  52. // #define LOG_MODE LOG_BY_MACRO
  53. #define LOG_MODE LOG_BY_CONST
  54. /*
  55. * LOG 通过宏控制
  56. */
  57. #if (LOG_MODE == LOG_BY_MACRO)
  58. #ifdef LOG_INFO_ENABLE
  59. #define log_info(format, ...) PRINTF("[Info] :" _LOG_TAG format "\r\n", ## __VA_ARGS__)
  60. #else
  61. #define log_info(...)
  62. #endif
  63. #ifdef LOG_DEBUG_ENABLE
  64. #define log_debug(format, ...) PRINTF("[Debug] :" _LOG_TAG format "\r\n", ## __VA_ARGS__)
  65. #define log_debug_hexdump(x, y) printf_buf(x, y)
  66. #else
  67. #define log_debug(...)
  68. #define log_debug_hexdump(x, y)
  69. #endif
  70. #ifdef LOG_ERROR_ENABLE
  71. #define log_error(format, ...) PRINTF("<Error> :" _LOG_TAG format "\r\n", ## __VA_ARGS__)
  72. #define log_error_hexdump(x, y) printf_buf(x, y)
  73. #else
  74. #define log_error(...)
  75. #define log_error_hexdump(...)
  76. #endif
  77. #ifdef LOG_DUMP_ENABLE
  78. #define log_info_hexdump(x,y) printf_buf(x,y)
  79. #else
  80. #define log_info_hexdump(...)
  81. #endif
  82. #ifdef LOG_CHAR_ENABLE
  83. #define log_char(x) putchar(x)
  84. #else
  85. #define log_char(x)
  86. #endif
  87. /*
  88. * LOG 通过常量控制
  89. */
  90. #elif (LOG_MODE == LOG_BY_CONST)
  91. #define log_info(format, ...) \
  92. if (LOG_IS_ENABLE(LOG_INFO)) \
  93. log_print(__LOG_INFO,NULL,"[Info]: " _LOG_TAG format "\r\n", ## __VA_ARGS__)
  94. #define log_info_hexdump(x, y) \
  95. if (LOG_IS_ENABLE(LOG_INFO)) \
  96. printf_buf(x, y)
  97. #define log_debug(format, ...) \
  98. if (LOG_IS_ENABLE(LOG_DEBUG)) \
  99. log_print(__LOG_DEBUG,NULL,"[Debug]: " _LOG_TAG format "\r\n", ## __VA_ARGS__)
  100. #define log_debug_hexdump(x, y) \
  101. if (LOG_IS_ENABLE(LOG_DEBUG)) \
  102. printf_buf(x, y)
  103. #define log_error(format, ...) \
  104. if (LOG_IS_ENABLE(LOG_ERROR)) \
  105. log_print(__LOG_ERROR,NULL,"<Error>: " _LOG_TAG format "\r\n", ## __VA_ARGS__)
  106. #define log_error_hexdump(x, y) \
  107. if (LOG_IS_ENABLE(LOG_ERROR)) \
  108. printf_buf(x, y)
  109. #define log_char(x) \
  110. if (LOG_IS_ENABLE(LOG_CHAR)) \
  111. putchar(x)
  112. #endif
  113. #define traceSUPER_MODE() \
  114. /*{int icfg, rets, reti; \
  115. __asm__ volatile("%0 = icfg" : "=r"(icfg)); \
  116. __asm__ volatile("%0 = rets" :"=r"(rets)); \
  117. __asm__ volatile("%0 = reti" :"=r"(reti)); \
  118. ASSERT(icfg & BIT(10), "icfg 0x%x/ rets 0x%x / reti 0x%x", icfg, rets, reti)}*/
  119. void watchdog_close(void);
  120. #endif//__DEBUG_LOG_H_