rtdebug.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * File : rtdebug.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #ifndef __RTDEBUG_H__
  21. #define __RTDEBUG_H__
  22. #include <rtconfig.h>
  23. /* settings depend check */
  24. #ifdef RT_USING_POSIX
  25. #if !defined(RT_USING_DFS) || !defined(RT_USING_DFS_DEVFS)
  26. #error "POSIX poll/select, stdin need file system(RT_USING_DFS) and device file system(RT_USING_DFS_DEVFS)"
  27. #endif
  28. #if defined(RT_USING_LWIP) && !defined(SAL_USING_POSIX)
  29. #error "POSIX poll/select, stdin need file BSD socket API(SAL_USING_POSIX)"
  30. #endif
  31. #if !defined(RT_USING_LIBC)
  32. #error "POSIX layer need standard C library(RT_USING_LIBC)"
  33. #endif
  34. #endif
  35. #ifdef RT_USING_POSIX_TERMIOS
  36. #if !defined(RT_USING_POSIX)
  37. #error "termios need POSIX layer(RT_USING_POSIX)"
  38. #endif
  39. #endif
  40. /* Using this macro to control all kernel debug features. */
  41. #ifdef RT_DEBUG
  42. /* Turn on some of these (set to non-zero) to debug kernel */
  43. #ifndef RT_DEBUG_MEM
  44. #define RT_DEBUG_MEM 0
  45. #endif
  46. #ifndef RT_DEBUG_MEMHEAP
  47. #define RT_DEBUG_MEMHEAP 0
  48. #endif
  49. #ifndef RT_DEBUG_MODULE
  50. #define RT_DEBUG_MODULE 0
  51. #endif
  52. #ifndef RT_DEBUG_SCHEDULER
  53. #define RT_DEBUG_SCHEDULER 0
  54. #endif
  55. #ifndef RT_DEBUG_SLAB
  56. #define RT_DEBUG_SLAB 0
  57. #endif
  58. #ifndef RT_DEBUG_THREAD
  59. #define RT_DEBUG_THREAD 0
  60. #endif
  61. #ifndef RT_DEBUG_TIMER
  62. #define RT_DEBUG_TIMER 0
  63. #endif
  64. #ifndef RT_DEBUG_IRQ
  65. #define RT_DEBUG_IRQ 0
  66. #endif
  67. #ifndef RT_DEBUG_IPC
  68. #define RT_DEBUG_IPC 0
  69. #endif
  70. #ifndef RT_DEBUG_INIT
  71. #define RT_DEBUG_INIT 0
  72. #endif
  73. /* Turn on this to enable context check */
  74. #ifndef RT_DEBUG_CONTEXT_CHECK
  75. #define RT_DEBUG_CONTEXT_CHECK 1
  76. #endif
  77. #define RT_DEBUG_LOG(type, message) \
  78. do \
  79. { \
  80. if (type) \
  81. rt_kprintf message; \
  82. } \
  83. while (0)
  84. #define RT_ASSERT(EX) \
  85. if (!(EX)) \
  86. { \
  87. rt_assert_handler(#EX, __FUNCTION__, __LINE__); \
  88. }
  89. /* Macro to check current context */
  90. #if RT_DEBUG_CONTEXT_CHECK
  91. #define RT_DEBUG_NOT_IN_INTERRUPT \
  92. do \
  93. { \
  94. rt_base_t level; \
  95. level = rt_hw_interrupt_disable(); \
  96. if (rt_interrupt_get_nest() != 0) \
  97. { \
  98. rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__); \
  99. RT_ASSERT(0) \
  100. } \
  101. rt_hw_interrupt_enable(level); \
  102. } \
  103. while (0)
  104. /* "In thread context" means:
  105. * 1) the scheduler has been started
  106. * 2) not in interrupt context.
  107. */
  108. #define RT_DEBUG_IN_THREAD_CONTEXT \
  109. do \
  110. { \
  111. rt_base_t level; \
  112. level = rt_hw_interrupt_disable(); \
  113. if (rt_thread_self() == RT_NULL) \
  114. { \
  115. rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
  116. __FUNCTION__); \
  117. RT_ASSERT(0) \
  118. } \
  119. RT_DEBUG_NOT_IN_INTERRUPT; \
  120. rt_hw_interrupt_enable(level); \
  121. } \
  122. while (0)
  123. #else
  124. #define RT_DEBUG_NOT_IN_INTERRUPT
  125. #define RT_DEBUG_IN_THREAD_CONTEXT
  126. #endif
  127. #else /* RT_DEBUG */
  128. #define RT_ASSERT(EX)
  129. #define RT_DEBUG_LOG(type, message)
  130. #define RT_DEBUG_NOT_IN_INTERRUPT
  131. #define RT_DEBUG_IN_THREAD_CONTEXT
  132. #endif /* RT_DEBUG */
  133. #endif /* __RTDEBUG_H__ */