rtdebug.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. */
  10. #ifndef __RTDEBUG_H__
  11. #define __RTDEBUG_H__
  12. #include <rtconfig.h>
  13. /* Using this macro to control all kernel debug features. */
  14. #ifdef RT_DEBUG
  15. /* Turn on some of these (set to non-zero) to debug kernel */
  16. #ifndef RT_DEBUG_MEM
  17. #define RT_DEBUG_MEM 0
  18. #endif
  19. #ifndef RT_DEBUG_MEMHEAP
  20. #define RT_DEBUG_MEMHEAP 0
  21. #endif
  22. #ifndef RT_DEBUG_MODULE
  23. #define RT_DEBUG_MODULE 0
  24. #endif
  25. #ifndef RT_DEBUG_SCHEDULER
  26. #define RT_DEBUG_SCHEDULER 0
  27. #endif
  28. #ifndef RT_DEBUG_SLAB
  29. #define RT_DEBUG_SLAB 0
  30. #endif
  31. #ifndef RT_DEBUG_THREAD
  32. #define RT_DEBUG_THREAD 0
  33. #endif
  34. #ifndef RT_DEBUG_TIMER
  35. #define RT_DEBUG_TIMER 0
  36. #endif
  37. #ifndef RT_DEBUG_IRQ
  38. #define RT_DEBUG_IRQ 0
  39. #endif
  40. #ifndef RT_DEBUG_IPC
  41. #define RT_DEBUG_IPC 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. volatile char dummy = 0; \
  58. rt_kprintf("(%s) assert failed at %s:%d \n", #EX, __FUNCTION__, __LINE__);\
  59. while (dummy == 0); \
  60. }
  61. /* Macro to check current context */
  62. #if RT_DEBUG_CONTEXT_CHECK
  63. #define RT_DEBUG_NOT_IN_INTERRUPT \
  64. do \
  65. { \
  66. rt_base_t level; \
  67. level = rt_hw_interrupt_disable(); \
  68. if (rt_interrupt_get_nest() != 0) \
  69. { \
  70. rt_kprintf("Function[%s] shall not used in ISR\n", __FUNCTION__); \
  71. RT_ASSERT(0) \
  72. } \
  73. rt_hw_interrupt_enable(level); \
  74. } \
  75. while (0)
  76. #else
  77. #define RT_DEBUG_NOT_IN_INTERRUPT
  78. #endif
  79. #else /* RT_DEBUG */
  80. #define RT_ASSERT(EX)
  81. #define RT_DEBUG_LOG(type, message)
  82. #define RT_DEBUG_NOT_IN_INTERRUPT
  83. #endif /* RT_DEBUG */
  84. #endif /* __RTDEBUG_H__ */