rtdebug.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * File : rtdebug.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, 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. /* Using this macro to control all kernel debug features. */
  23. #ifdef RT_DEBUG
  24. /* Turn on some of these (set to non-zero) to debug kernel */
  25. #ifndef RT_DEBUG_MEM
  26. #define RT_DEBUG_MEM 0
  27. #endif
  28. #ifndef RT_DEBUG_MEMHEAP
  29. #define RT_DEBUG_MEMHEAP 0
  30. #endif
  31. #ifndef RT_DEBUG_MODULE
  32. #define RT_DEBUG_MODULE 0
  33. #endif
  34. #ifndef RT_DEBUG_SCHEDULER
  35. #define RT_DEBUG_SCHEDULER 0
  36. #endif
  37. #ifndef RT_DEBUG_SLAB
  38. #define RT_DEBUG_SLAB 0
  39. #endif
  40. #ifndef RT_DEBUG_THREAD
  41. #define RT_DEBUG_THREAD 0
  42. #endif
  43. #ifndef RT_DEBUG_TIMER
  44. #define RT_DEBUG_TIMER 0
  45. #endif
  46. #ifndef RT_DEBUG_IRQ
  47. #define RT_DEBUG_IRQ 0
  48. #endif
  49. #ifndef RT_DEBUG_IPC
  50. #define RT_DEBUG_IPC 0
  51. #endif
  52. #ifndef RT_DEBUG_INIT
  53. #define RT_DEBUG_INIT 0
  54. #endif
  55. /* Turn on this to enable context check */
  56. #ifndef RT_DEBUG_CONTEXT_CHECK
  57. #define RT_DEBUG_CONTEXT_CHECK 1
  58. #endif
  59. #define RT_DEBUG_LOG(type, message) \
  60. do \
  61. { \
  62. if (type) \
  63. rt_kprintf message; \
  64. } \
  65. while (0)
  66. #define RT_ASSERT(EX) \
  67. if (!(EX)) \
  68. { \
  69. volatile char dummy = 0; \
  70. rt_kprintf("(%s) assert failed at %s:%d \n", #EX, __FUNCTION__, __LINE__);\
  71. while (dummy == 0); \
  72. }
  73. /* Macro to check current context */
  74. #if RT_DEBUG_CONTEXT_CHECK
  75. #define RT_DEBUG_NOT_IN_INTERRUPT \
  76. do \
  77. { \
  78. rt_base_t level; \
  79. level = rt_hw_interrupt_disable(); \
  80. if (rt_interrupt_get_nest() != 0) \
  81. { \
  82. rt_kprintf("Function[%s] shall not used in ISR\n", __FUNCTION__); \
  83. RT_ASSERT(0) \
  84. } \
  85. rt_hw_interrupt_enable(level); \
  86. } \
  87. while (0)
  88. /* "In thread context" means:
  89. * 1) the scheduler has been started
  90. * 2) not in interrupt context.
  91. */
  92. #define RT_DEBUG_IN_THREAD_CONTEXT \
  93. do \
  94. { \
  95. rt_base_t level; \
  96. level = rt_hw_interrupt_disable(); \
  97. if (rt_thread_self() == RT_NULL) \
  98. { \
  99. rt_kprintf("Function[%s] shall not be used before scheduler start\n", \
  100. __FUNCTION__); \
  101. RT_ASSERT(0) \
  102. } \
  103. RT_DEBUG_NOT_IN_INTERRUPT; \
  104. rt_hw_interrupt_enable(level); \
  105. } \
  106. while (0)
  107. #else
  108. #define RT_DEBUG_NOT_IN_INTERRUPT
  109. #define RT_DEBUG_IN_THREAD_CONTEXT
  110. #endif
  111. #else /* RT_DEBUG */
  112. #define RT_ASSERT(EX)
  113. #define RT_DEBUG_LOG(type, message)
  114. #define RT_DEBUG_NOT_IN_INTERRUPT
  115. #define RT_DEBUG_IN_THREAD_CONTEXT
  116. #endif /* RT_DEBUG */
  117. #endif /* __RTDEBUG_H__ */