rtdebug.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #ifndef __RTDEBUG_H__
  10. #define __RTDEBUG_H__
  11. #include <rtconfig.h>
  12. /* settings depend check */
  13. #ifdef RT_USING_POSIX
  14. #if !defined(RT_USING_DFS) || !defined(RT_USING_DFS_DEVFS)
  15. #error "POSIX poll/select, stdin need file system(RT_USING_DFS) and device file system(RT_USING_DFS_DEVFS)"
  16. #endif
  17. #endif /* RT_USING_POSIX */
  18. /* Using this macro to control all kernel debug features. */
  19. #ifdef RT_DEBUG
  20. /* Turn on some of these (set to non-zero) to debug kernel */
  21. #ifndef RT_DEBUG_MEM
  22. #define RT_DEBUG_MEM 0
  23. #endif
  24. #ifndef RT_DEBUG_MEMHEAP
  25. #define RT_DEBUG_MEMHEAP 0
  26. #endif
  27. #ifndef RT_DEBUG_MODULE
  28. #define RT_DEBUG_MODULE 0
  29. #endif
  30. #ifndef RT_DEBUG_SCHEDULER
  31. #define RT_DEBUG_SCHEDULER 0
  32. #endif
  33. #ifndef RT_DEBUG_SLAB
  34. #define RT_DEBUG_SLAB 0
  35. #endif
  36. #ifndef RT_DEBUG_THREAD
  37. #define RT_DEBUG_THREAD 0
  38. #endif
  39. #ifndef RT_DEBUG_TIMER
  40. #define RT_DEBUG_TIMER 0
  41. #endif
  42. #ifndef RT_DEBUG_IRQ
  43. #define RT_DEBUG_IRQ 0
  44. #endif
  45. #ifndef RT_DEBUG_IPC
  46. #define RT_DEBUG_IPC 0
  47. #endif
  48. #ifndef RT_DEBUG_INIT
  49. #define RT_DEBUG_INIT 0
  50. #endif
  51. /* Turn on this to enable context check */
  52. #ifndef RT_DEBUG_CONTEXT_CHECK
  53. #define RT_DEBUG_CONTEXT_CHECK 1
  54. #endif
  55. #define RT_DEBUG_LOG(type, message) \
  56. do \
  57. { \
  58. if (type) \
  59. rt_kprintf message; \
  60. } \
  61. while (0)
  62. #define RT_ASSERT(EX) \
  63. if (!(EX)) \
  64. { \
  65. rt_assert_handler(#EX, __FUNCTION__, __LINE__); \
  66. }
  67. /* Macro to check current context */
  68. #if RT_DEBUG_CONTEXT_CHECK
  69. #define RT_DEBUG_NOT_IN_INTERRUPT \
  70. do \
  71. { \
  72. rt_base_t level; \
  73. level = rt_hw_interrupt_disable(); \
  74. if (rt_interrupt_get_nest() != 0) \
  75. { \
  76. rt_kprintf("Function[%s] shall not be used in ISR\n", __FUNCTION__); \
  77. RT_ASSERT(0) \
  78. } \
  79. rt_hw_interrupt_enable(level); \
  80. } \
  81. while (0)
  82. /* "In thread context" means:
  83. * 1) the scheduler has been started
  84. * 2) not in interrupt context.
  85. */
  86. #define RT_DEBUG_IN_THREAD_CONTEXT \
  87. do \
  88. { \
  89. rt_base_t level; \
  90. level = rt_hw_interrupt_disable(); \
  91. if (rt_thread_self() == RT_NULL) \
  92. { \
  93. rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
  94. __FUNCTION__); \
  95. RT_ASSERT(0) \
  96. } \
  97. RT_DEBUG_NOT_IN_INTERRUPT; \
  98. rt_hw_interrupt_enable(level); \
  99. } \
  100. while (0)
  101. #else
  102. #define RT_DEBUG_NOT_IN_INTERRUPT
  103. #define RT_DEBUG_IN_THREAD_CONTEXT
  104. #endif
  105. #else /* RT_DEBUG */
  106. #define RT_ASSERT(EX)
  107. #define RT_DEBUG_LOG(type, message)
  108. #define RT_DEBUG_NOT_IN_INTERRUPT
  109. #define RT_DEBUG_IN_THREAD_CONTEXT
  110. #endif /* RT_DEBUG */
  111. #endif /* __RTDEBUG_H__ */