log.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file log.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __LOG_H__
  35. #define __LOG_H__
  36. #include "rtthread.h"
  37. #ifndef LOG_ENABLE
  38. #define LOG_ENABLE 1
  39. #endif
  40. #if LOG_ENABLE
  41. #include <stdio.h>
  42. #define LOG_NONE 0
  43. #define LOG_ERROR 10
  44. #define LOG_WARNING 20
  45. #define LOG_INFO 30
  46. #define LOG_DEBUG 40
  47. #ifndef LOG_LEVEL
  48. #define LOG_LEVEL LOG_INFO
  49. #endif
  50. #if LOG_LEVEL >= LOG_INFO
  51. #define log_info(...) rt_kprintf(__VA_ARGS__)
  52. #else
  53. #define log_info(...)
  54. #endif
  55. #if LOG_LEVEL >= LOG_ERROR
  56. #define log_error(...) rt_kprintf(__VA_ARGS__)
  57. #else
  58. #define log_error(...)
  59. #endif
  60. #if LOG_LEVEL >= LOG_WARNING
  61. #define log_warning(...) rt_kprintf(__VA_ARGS__)
  62. #else
  63. #define log_warning(...)
  64. #endif
  65. #if LOG_LEVEL >= LOG_DEBUG
  66. #define log_debug(...) rt_kprintf(__VA_ARGS__)
  67. #else
  68. #define log_debug(...)
  69. #endif
  70. #else /* !LOG_ENABLE */
  71. #define log_info(...)
  72. #define log_warning(...)
  73. #define log_error(...)
  74. #define log_debug(...)
  75. #define log_init()
  76. #endif
  77. #define RECV_BUF_LEN (32)
  78. /////////////////////////////////////////////////////////////////////////////////////////
  79. typedef struct uart_cache
  80. {
  81. rt_sem_t sem;
  82. uint8_t idx;
  83. uint8_t tmp;
  84. uint8_t buf[RECV_BUF_LEN];
  85. } ts_UartCache;
  86. /////////////////////////////////////////////////////////////////////////////////////////
  87. extern ts_UartCache rx_cache;
  88. /////////////////////////////////////////////////////////////////////////////////////////
  89. #define log_func() log_debug("call %s\r\n", __FUNCTION__)
  90. // if((x== y) == z) 则停止
  91. #define log_assert(x, y, z) \
  92. do \
  93. { \
  94. if ((y == x) == z) \
  95. { \
  96. while (1) \
  97. { \
  98. log_error("assert error at %s:%d\n", __FILE__, __LINE__); \
  99. }; \
  100. } \
  101. } while (0)
  102. /////////////////////////////////////////////////////////////////////////////////////////
  103. #define dbg_mem_info() \
  104. do \
  105. { \
  106. uint32_t totle_mem = 0; \
  107. uint32_t used_mem = 0; \
  108. uint32_t max_used = 0; \
  109. rt_memory_info(&totle_mem, &used_mem, &max_used); \
  110. log_debug("meminfo = %d, used mem = %d, max used = %d\n", totle_mem, used_mem, max_used); \
  111. } while (0)
  112. void log_init(void);
  113. int uart_reset(int bandrate);
  114. int uart_transmit_bytes(uint8_t *data, uint32_t len);
  115. void uart_transmit_bytes_dma(uint8_t *data, uint32_t len);
  116. #endif /* __LOG_H__ */