rtdebug.h 4.5 KB

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