You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "cmsis_os.h"
  8. #include "main.h"
  9. extern bool g_enable_log;
  10. #define ZLOG_RELEASE(TAG, fmt, ...) \
  11. if (g_enable_log) { \
  12. zlog(TAG "" fmt "\n", ##__VA_ARGS__); \
  13. }
  14. #define ZLOGI(TAG, fmt, ...) \
  15. if (g_enable_log) { \
  16. zlog("%08lu INFO [%-8s] " fmt "\n", HAL_GetTick(), TAG, ##__VA_ARGS__); \
  17. }
  18. #define ZLOGD(TAG, fmt, ...) \
  19. if (g_enable_log) { \
  20. zlog("%08lu DEBU [%-8s] " fmt "\n", HAL_GetTick(), TAG, ##__VA_ARGS__); \
  21. }
  22. #define ZLOGE(TAG, fmt, ...) \
  23. if (g_enable_log) { \
  24. zlog("%08lu ERRO [%-8s] " fmt "\n", HAL_GetTick(), TAG, ##__VA_ARGS__); \
  25. }
  26. #define ZLOGW(TAG, fmt, ...) \
  27. if (g_enable_log) { \
  28. zlog("%08lu WARN [%-8s] " fmt "\n", HAL_GetTick(), TAG, ##__VA_ARGS__); \
  29. }
  30. #define ZASSERT(cond) \
  31. if (!(cond)) { \
  32. while (1) { \
  33. zlog("ASSERT: %s [%s:%d]\n", #cond, __FILE__, __LINE__); \
  34. osDelay(1000); \
  35. } \
  36. }
  37. #define ZASSERT_INFO(cond, info) \
  38. if (!(cond)) { \
  39. while (1) { \
  40. zlog("ASSERT: %s [%s:%d] %s\n", #cond, __FILE__, __LINE__, info); \
  41. osDelay(1000); \
  42. } \
  43. }
  44. #define ZEARLY_ASSERT(cond) \
  45. if (!(cond)) { \
  46. while (1) { \
  47. } \
  48. }
  49. void zlog(const char* fmt, ...);
  50. void zlog_raw(const char* info);
  51. void zlog_init(UART_HandleTypeDef* huart);
  52. void zlog_enable(bool enable);
  53. #ifdef __cplusplus
  54. }
  55. #endif