fdebug.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 files is for debug functions
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. #ifndef BSP_COMMON_FT_DEBUG_H
  24. #define BSP_COMMON_FT_DEBUG_H
  25. #include <stdio.h>
  26. #include "sdkconfig.h"
  27. #include "ftypes.h"
  28. typedef enum
  29. {
  30. FT_LOG_NONE, /* No log output */
  31. FT_LOG_ERROR, /* Critical errors, software module can not recover on its own */
  32. FT_LOG_WARN, /* Error conditions from which recovery measures have been taken */
  33. FT_LOG_INFO, /* Information messages which describe normal flow of events */
  34. FT_LOG_DEBUG, /* Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
  35. FT_LOG_VERBOSE /* Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
  36. } ft_log_level_t;
  37. #define LOG_COLOR_BLACK "30"
  38. #define LOG_COLOR_RED "31"
  39. #define LOG_COLOR_GREEN "32"
  40. #define LOG_COLOR_BROWN "33"
  41. #define LOG_COLOR_BLUE "34"
  42. #define LOG_COLOR_PURPLE "35"
  43. #define LOG_COLOR_CYAN "36"
  44. #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
  45. #define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
  46. #define LOG_RESET_COLOR "\033[0m"
  47. #define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
  48. #define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
  49. #define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
  50. #define LOG_COLOR_D LOG_COLOR(LOG_COLOR_CYAN)
  51. #define LOG_COLOR_V LOG_COLOR(LOG_COLOR_PURPLE)
  52. /* select debug log level */
  53. #ifdef CONFIG_LOG_VERBOS
  54. #define LOG_LOCAL_LEVEL FT_LOG_VERBOSE
  55. #endif
  56. #ifdef CONFIG_LOG_ERROR
  57. #define LOG_LOCAL_LEVEL FT_LOG_ERROR
  58. #endif
  59. #ifdef CONFIG_LOG_WARN
  60. #define LOG_LOCAL_LEVEL FT_LOG_WARN
  61. #endif
  62. #ifdef CONFIG_LOG_INFO
  63. #define LOG_LOCAL_LEVEL FT_LOG_INFO
  64. #endif
  65. #ifdef CONFIG_LOG_DEBUG
  66. #define LOG_LOCAL_LEVEL FT_LOG_DEBUG
  67. #endif
  68. #define LOG_FORMAT(letter, format) LOG_COLOR_##letter " %s: " format LOG_RESET_COLOR "\r\n"
  69. #define PORT_KPRINTF printf
  70. #ifndef CONFIG_LOG_EXTRA_INFO
  71. #define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
  72. do \
  73. { \
  74. if (LOG_LOCAL_LEVEL < log_level) \
  75. break; \
  76. PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format), tag, ##__VA_ARGS__); \
  77. } while (0)
  78. #else
  79. #include <string.h>
  80. #define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1):__FILE__)
  81. /* print debug information with source file name and source code line num. */
  82. #define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
  83. do \
  84. { \
  85. if (LOG_LOCAL_LEVEL < log_level) \
  86. break; \
  87. PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format" @%s:%d"), tag, ##__VA_ARGS__, __FILENAME__, __LINE__); \
  88. } while (0)
  89. #endif
  90. #define EARLY_LOGE(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_ERROR, E, ##__VA_ARGS__)
  91. #define EARLY_LOGI(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_INFO, I, ##__VA_ARGS__)
  92. #define EARLY_LOGD(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_DEBUG, D, ##__VA_ARGS__)
  93. #define EARLY_LOGW(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_WARN, W, ##__VA_ARGS__)
  94. #define EARLY_LOGV(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_VERBOSE, W, ##__VA_ARGS__)
  95. /* do not compile log if define CONFIG_LOG_NONE */
  96. #ifndef CONFIG_LOG_NONE
  97. #define FT_DEBUG_PRINT_I(TAG, format, ...) EARLY_LOGI(TAG, format, ##__VA_ARGS__)
  98. #define FT_DEBUG_PRINT_E(TAG, format, ...) EARLY_LOGE(TAG, format, ##__VA_ARGS__)
  99. #define FT_DEBUG_PRINT_D(TAG, format, ...) EARLY_LOGD(TAG, format, ##__VA_ARGS__)
  100. #define FT_DEBUG_PRINT_W(TAG, format, ...) EARLY_LOGW(TAG, format, ##__VA_ARGS__)
  101. #define FT_DEBUG_PRINT_V(TAG, format, ...) EARLY_LOGV(TAG, format, ##__VA_ARGS__)
  102. #else
  103. #define FT_DEBUG_PRINT_I(TAG, format, ...)
  104. #define FT_DEBUG_PRINT_E(TAG, format, ...)
  105. #define FT_DEBUG_PRINT_D(TAG, format, ...)
  106. #define FT_DEBUG_PRINT_W(TAG, format, ...)
  107. #define FT_DEBUG_PRINT_V(TAG, format, ...)
  108. #endif
  109. #define FT_RAW_PRINTF(format, ...) PORT_KPRINTF(format, ##__VA_ARGS__)
  110. void FtDumpHexWord(const u32 *ptr, u32 buflen);
  111. void FtDumpHexByte(const u8 *ptr, u32 buflen);
  112. #endif // !