log.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file log.h
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. /*******************************************************************************
  11. * @file log.h
  12. * @brief Contains all functions support for uart driver
  13. * @version 0.0
  14. * @date 31. Jan. 2018
  15. * @author eagle.han
  16. *
  17. *
  18. *******************************************************************************/
  19. #ifndef ENABLE_LOG_ROM
  20. #ifndef __LOG_H__
  21. #define __LOG_H__
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #ifndef DEBUG_INFO
  26. #include "sdk_config.h"
  27. #endif
  28. #include "uart.h"
  29. void dbg_printf(const char *format, ...);
  30. void dbg_printf_init(void);
  31. void my_dump_byte(uint8_t* pData, int dlen);
  32. #ifndef DEBUG_INFO
  33. #define DEBUG_INFO 0
  34. #endif
  35. typedef void(*std_putc)(char* data, uint16_t size);
  36. #if(DEBUG_INFO == 1)
  37. #define AT_LOG(...)
  38. #define LOG_DEBUG(...)
  39. #define LOG(...) dbg_printf(__VA_ARGS__)
  40. #define LOG_INIT() dbg_printf_init()
  41. #define LOG_DUMP_BYTE(a,b) my_dump_byte(a,b)
  42. #elif(DEBUG_INFO == 2)
  43. #define AT_LOG(...) dbg_printf(__VA_ARGS__)
  44. #define LOG_DEBUG(...) dbg_printf(__VA_ARGS__)
  45. #define LOG(...)
  46. #define LOG_INIT() dbg_printf_init()
  47. #define LOG_DUMP_BYTE(a,b) my_dump_byte(a,b)
  48. #elif(DEBUG_INFO == 3)
  49. #define LOG(...) dbg_printf(__VA_ARGS__)
  50. #define AT_LOG(...) dbg_printf(__VA_ARGS__)
  51. #define LOG_DEBUG(...) dbg_printf(__VA_ARGS__)
  52. #define LOG_INIT() dbg_printf_init()
  53. #define LOG_DUMP_BYTE(a,b) my_dump_byte(a,b)
  54. #else
  55. #define AT_LOG(...)
  56. #define LOG_DEBUG(...)
  57. #define LOG(...)
  58. #define LOG_INIT() //{clk_gate_enable(MOD_UART);clk_reset(MOD_UART);clk_gate_disable(MOD_UART);}
  59. #define LOG_DUMP_BYTE(a,b)
  60. #endif
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif //__LOG_H__
  65. #else
  66. #ifndef __LOG_H
  67. #define __LOG_H
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71. #include "types.h"
  72. #include "uart.h"
  73. #include <stdarg.h>
  74. #include <stdio.h>
  75. #define LOG_LEVEL_NONE 0 //no log output*/
  76. #define LOG_LEVEL_ERROR 1 //only log error*/
  77. #define LOG_LEVEL_DEBUG 2 //output debug info and error info*/
  78. #define LOG_LEVEL_LOG 3 //output all infomation*/
  79. #define LOG_INIT() {HalUartInit(115200,P9,P10,NULL);}
  80. #if 0//DEBUG_FPGA
  81. #define LOG(...) do{;}while(0);
  82. #else
  83. //conditional output
  84. #define LOG(...) {if(s_rom_debug_level == LOG_LEVEL_LOG) log_printf(__VA_ARGS__);}
  85. #define LOG_DEBUG(...) {if(s_rom_debug_level >= LOG_LEVEL_DEBUG) log_printf(__VA_ARGS__);}
  86. #define LOG_ERROR(...) {if(s_rom_debug_level >= LOG_LEVEL_ERROR) log_printf(__VA_ARGS__);}
  87. //tx data anyway
  88. #define PRINT(...) {SWU_TX(); log_printf(__VA_ARGS__);}
  89. #endif
  90. extern volatile uint32_t s_rom_debug_level;
  91. typedef void(*std_putc)(char* data, int size);
  92. void log_vsprintf(std_putc putc, const char *fmt, va_list args);
  93. void log_printf(const char *format, ...);
  94. void log_set_putc(std_putc putc);
  95. void log_clr_putc(std_putc putc);
  96. int log_debug_level(uint8_t level);
  97. uint32_t log_get_debug_level(void);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif
  102. #endif