rtdebug.h 5.3 KB

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