hal_log.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef SUNXI_HAL_LOG_H
  2. #define SUNXI_HAL_LOG_H
  3. #ifdef __cplusplus
  4. extern "C"
  5. {
  6. #endif
  7. #include <stdio.h>
  8. //#define CONFIG_KERNEL_FREERTOS
  9. //#define CONFIG_RTTKERNEL
  10. #ifdef CONFIG_KERNEL_FREERTOS
  11. #include <awlog.h>
  12. #define hal_log_err(fmt, ...) pr_err(fmt"\n", ##__VA_ARGS__)
  13. #define hal_log_warn(fmt, ...) pr_warn(fmt"\n", ##__VA_ARGS__)
  14. #define hal_log_info(fmt, ...) pr_info(fmt"\n", ##__VA_ARGS__)
  15. #define hal_log_debug(fmt, ...) pr_debug(fmt"\n", ##__VA_ARGS__)
  16. #elif defined CONFIG_RTTKERNEL
  17. #include <log.h>
  18. #define hal_log_err(fmt, ...) pr_err(fmt"\n", ##__VA_ARGS__)
  19. #define hal_log_warn(fmt, ...) pr_warn(fmt"\n", ##__VA_ARGS__)
  20. #define hal_log_info(fmt, ...) pr_info(fmt"\n", ##__VA_ARGS__)
  21. #define hal_log_debug(fmt, ...) pr_debug(fmt"\n", ##__VA_ARGS__)
  22. #else
  23. int printk(const char *fmt, ...);
  24. #define HAL_XPOSTO(x) "\033[" #x "D\033[" #x "C"
  25. #define HAL_LOG_LAYOUT "%s%s%s: [%s:%04u]: %s%s"
  26. #define HAL_LOG_BACKEND_CALL(log_lv, log_color, log_format, color_off, ...) \
  27. printk(HAL_LOG_LAYOUT log_format "%s""\n\r", \
  28. log_color, log_lv, color_off, __func__, __LINE__, HAL_XPOSTO(30),\
  29. log_color, ##__VA_ARGS__, color_off)
  30. #define HAL_LOG_COLOR(log_lv, log_color, log_format, ...) \
  31. HAL_LOG_BACKEND_CALL(log_lv, log_color, log_format, \
  32. HAL_LOG_COLOR_OFF, ##__VA_ARGS__)
  33. #define HAL_LOG_COLOR_OFF "\033[0m"
  34. #define HAL_LOG_COLOR_RED "\033[1;40;31m"
  35. #define HAL_LOG_COLOR_YELLOW "\033[1;40;33m"
  36. #define HAL_LOG_COLOR_BLUE "\033[1;40;34m"
  37. #define HAL_LOG_COLOR_PURPLE "\033[1;40;35m"
  38. #define HAL_LOG_ERROR_PREFIX "[ERR]"
  39. #define HAL_LOG_WARNING_PREFIX "[WRN]"
  40. #define HAL_LOG_INFO_PREFIX "[INF]"
  41. #define HAL_LOG_DEBUG_PREFIX "[DBG]"
  42. #define hal_log_err(...) \
  43. do { HAL_LOG_COLOR(HAL_LOG_ERROR_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0)
  44. #define hal_log_warn(...) \
  45. do { HAL_LOG_COLOR(HAL_LOG_WARNING_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0)
  46. #define hal_log_info(...) \
  47. do { HAL_LOG_COLOR(HAL_LOG_INFO_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0)
  48. #define hal_log_debug(...) \
  49. do { HAL_LOG_COLOR(HAL_LOG_DEBUG_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0)
  50. #endif
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif