fdebug.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fdebug.h
  15. * Date: 2021-04-07 09:53:07
  16. * LastEditTime: 2022-02-17 18:04:58
  17. * Description:  This file is for showing debug api.
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. * 1.0 zhugengyu 2022/10/27 rename file name
  23. */
  24. #ifndef FDEBUG_H
  25. #define FDEBUG_H
  26. #include <stdio.h>
  27. #include "sdkconfig.h"
  28. #include "ftypes.h"
  29. #include "fprintk.h"
  30. #ifdef CONFIG_USE_AMP
  31. #include "fsmp.h"
  32. #endif
  33. #include "fcpu_info.h"
  34. #ifdef __cplusplus
  35. extern "C"
  36. {
  37. #endif
  38. typedef enum
  39. {
  40. FT_LOG_NONE, /* No log output */
  41. FT_LOG_ERROR, /* Critical errors, software module can not recover on its own */
  42. FT_LOG_WARN, /* Error conditions from which recovery measures have been taken */
  43. FT_LOG_INFO, /* Information messages which describe normal flow of events */
  44. FT_LOG_DEBUG, /* Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
  45. FT_LOG_VERBOSE /* Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
  46. } ft_log_level_t;
  47. #define LOG_COLOR_BLACK "30"
  48. #define LOG_COLOR_RED "31"
  49. #define LOG_COLOR_GREEN "32"
  50. #define LOG_COLOR_BROWN "33"
  51. #define LOG_COLOR_BLUE "34"
  52. #define LOG_COLOR_PURPLE "35"
  53. #define LOG_COLOR_CYAN "36"
  54. #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
  55. #define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
  56. #define LOG_RESET_COLOR "\033[0m"
  57. #define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
  58. #define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
  59. #define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
  60. #define LOG_COLOR_D LOG_COLOR(LOG_COLOR_CYAN)
  61. #define LOG_COLOR_V LOG_COLOR(LOG_COLOR_PURPLE)
  62. /* select debug log level */
  63. #ifdef CONFIG_LOG_VERBOS
  64. #define LOG_LOCAL_LEVEL FT_LOG_VERBOSE
  65. #endif
  66. #ifdef CONFIG_LOG_ERROR
  67. #define LOG_LOCAL_LEVEL FT_LOG_ERROR
  68. #endif
  69. #ifdef CONFIG_LOG_WARN
  70. #define LOG_LOCAL_LEVEL FT_LOG_WARN
  71. #endif
  72. #ifdef CONFIG_LOG_INFO
  73. #define LOG_LOCAL_LEVEL FT_LOG_INFO
  74. #endif
  75. #ifdef CONFIG_LOG_DEBUG
  76. #define LOG_LOCAL_LEVEL FT_LOG_DEBUG
  77. #endif
  78. #define LOG_FORMAT(letter, format) LOG_COLOR_##letter " %s: " format LOG_RESET_COLOR "\r\n"
  79. #define PORT_KPRINTF f_printk
  80. #if defined(CONFIG_LOG_DISPALY_CORE_NUM)
  81. #define DISPALY_CORE_NUM() \
  82. do {u32 cpu_id; \
  83. GetCpuId(&cpu_id); \
  84. PORT_KPRINTF("cpu%d:", cpu_id); } while(0)
  85. #else
  86. #define DISPALY_CORE_NUM()
  87. #endif
  88. #ifdef CONFIG_USE_AMP
  89. #define LOG_SPIN_LOCK() SpinLock();
  90. #define LOG_SPIN_UNLOCK() SpinUnlock() ;
  91. #else
  92. #define LOG_SPIN_LOCK()
  93. #define LOG_SPIN_UNLOCK()
  94. #endif
  95. #ifndef CONFIG_LOG_EXTRA_INFO
  96. #define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
  97. do \
  98. { \
  99. if (LOG_LOCAL_LEVEL < log_level) \
  100. break; \
  101. LOG_SPIN_LOCK(); \
  102. DISPALY_CORE_NUM(); \
  103. PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format), tag, ##__VA_ARGS__); \
  104. LOG_SPIN_UNLOCK(); \
  105. } while (0)
  106. #else
  107. #include <string.h>
  108. #define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1):__FILE__)
  109. /* print debug information with source file name and source code line num. */
  110. #define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
  111. do \
  112. { \
  113. if (LOG_LOCAL_LEVEL < log_level) \
  114. break; \
  115. DISPALY_CORE_NUM(); \
  116. PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format" @%s:%d"), tag, ##__VA_ARGS__, __FILENAME__, __LINE__); \
  117. } while (0)
  118. #endif
  119. #define EARLY_LOGE(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_ERROR, E, ##__VA_ARGS__)
  120. #define EARLY_LOGI(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_INFO, I, ##__VA_ARGS__)
  121. #define EARLY_LOGD(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_DEBUG, D, ##__VA_ARGS__)
  122. #define EARLY_LOGW(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_WARN, W, ##__VA_ARGS__)
  123. #define EARLY_LOGV(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_VERBOSE, W, ##__VA_ARGS__)
  124. /* do not compile log if define CONFIG_LOG_NONE */
  125. #ifndef CONFIG_LOG_NONE
  126. #define FT_DEBUG_PRINT_I(TAG, format, ...) EARLY_LOGI(TAG, format, ##__VA_ARGS__)
  127. #define FT_DEBUG_PRINT_E(TAG, format, ...) EARLY_LOGE(TAG, format, ##__VA_ARGS__)
  128. #define FT_DEBUG_PRINT_D(TAG, format, ...) EARLY_LOGD(TAG, format, ##__VA_ARGS__)
  129. #define FT_DEBUG_PRINT_W(TAG, format, ...) EARLY_LOGW(TAG, format, ##__VA_ARGS__)
  130. #define FT_DEBUG_PRINT_V(TAG, format, ...) EARLY_LOGV(TAG, format, ##__VA_ARGS__)
  131. #else
  132. #define FT_DEBUG_PRINT_I(TAG, format, ...)
  133. #define FT_DEBUG_PRINT_E(TAG, format, ...)
  134. #define FT_DEBUG_PRINT_D(TAG, format, ...)
  135. #define FT_DEBUG_PRINT_W(TAG, format, ...)
  136. #define FT_DEBUG_PRINT_V(TAG, format, ...)
  137. #endif
  138. #define FT_RAW_PRINTF(format, ...) PORT_KPRINTF(format, ##__VA_ARGS__)
  139. void FtDumpHexWord(const u32 *ptr, u32 buflen);
  140. void FtDumpHexByte(const u8 *ptr, u32 buflen);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif // !