chdebug.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @file chdebug.h
  17. * @brief Debug support macros and structures.
  18. *
  19. * @addtogroup checks_assertions
  20. * @{
  21. */
  22. #ifndef CHDEBUG_H
  23. #define CHDEBUG_H
  24. /*===========================================================================*/
  25. /* Module constants. */
  26. /*===========================================================================*/
  27. /*===========================================================================*/
  28. /* Module pre-compile time settings. */
  29. /*===========================================================================*/
  30. /**
  31. * @name Debug related settings
  32. * @{
  33. */
  34. /**
  35. * @brief Fill value for thread stack area in debug mode.
  36. */
  37. #if !defined(CH_DBG_STACK_FILL_VALUE) || defined(__DOXYGEN__)
  38. #define CH_DBG_STACK_FILL_VALUE 0x55
  39. #endif
  40. /** @} */
  41. /*===========================================================================*/
  42. /* Derived constants and error checks. */
  43. /*===========================================================================*/
  44. /*===========================================================================*/
  45. /* Module data structures and types. */
  46. /*===========================================================================*/
  47. /*===========================================================================*/
  48. /* Module macros. */
  49. /*===========================================================================*/
  50. #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
  51. #define _dbg_enter_lock() (ch.dbg.lock_cnt = (cnt_t)1)
  52. #define _dbg_leave_lock() (ch.dbg.lock_cnt = (cnt_t)0)
  53. #endif
  54. /* When the state checker feature is disabled then the following functions
  55. are replaced by an empty macro.*/
  56. #if CH_DBG_SYSTEM_STATE_CHECK == FALSE
  57. #define _dbg_enter_lock()
  58. #define _dbg_leave_lock()
  59. #define _dbg_check_disable()
  60. #define _dbg_check_suspend()
  61. #define _dbg_check_enable()
  62. #define _dbg_check_lock()
  63. #define _dbg_check_unlock()
  64. #define _dbg_check_lock_from_isr()
  65. #define _dbg_check_unlock_from_isr()
  66. #define _dbg_check_enter_isr()
  67. #define _dbg_check_leave_isr()
  68. #define chDbgCheckClassI()
  69. #define chDbgCheckClassS()
  70. #endif
  71. /**
  72. * @name Macro Functions
  73. * @{
  74. */
  75. /**
  76. * @brief Function parameters check.
  77. * @details If the condition check fails then the kernel panics and halts.
  78. * @note The condition is tested only if the @p CH_DBG_ENABLE_CHECKS switch
  79. * is specified in @p chconf.h else the macro does nothing.
  80. *
  81. * @param[in] c the condition to be verified to be true
  82. *
  83. * @api
  84. */
  85. #if !defined(chDbgCheck)
  86. #define chDbgCheck(c) do { \
  87. /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
  88. if (CH_DBG_ENABLE_CHECKS != FALSE) { \
  89. if (!(c)) { \
  90. /*lint -restore*/ \
  91. chSysHalt(__func__); \
  92. } \
  93. } \
  94. } while (false)
  95. #endif /* !defined(chDbgCheck) */
  96. /**
  97. * @brief Condition assertion.
  98. * @details If the condition check fails then the kernel panics with a
  99. * message and halts.
  100. * @note The condition is tested only if the @p CH_DBG_ENABLE_ASSERTS switch
  101. * is specified in @p chconf.h else the macro does nothing.
  102. * @note The remark string is not currently used except for putting a
  103. * comment in the code about the assertion.
  104. *
  105. * @param[in] c the condition to be verified to be true
  106. * @param[in] r a remark string
  107. *
  108. * @api
  109. */
  110. #if !defined(chDbgAssert)
  111. #define chDbgAssert(c, r) do { \
  112. /*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
  113. if (CH_DBG_ENABLE_ASSERTS != FALSE) { \
  114. if (!(c)) { \
  115. /*lint -restore*/ \
  116. chSysHalt(__func__); \
  117. } \
  118. } \
  119. } while (false)
  120. #endif /* !defined(chDbgAssert) */
  121. /** @} */
  122. /*===========================================================================*/
  123. /* External declarations. */
  124. /*===========================================================================*/
  125. #ifdef __cplusplus
  126. extern "C" {
  127. #endif
  128. #if CH_DBG_SYSTEM_STATE_CHECK == TRUE
  129. void _dbg_check_disable(void);
  130. void _dbg_check_suspend(void);
  131. void _dbg_check_enable(void);
  132. void _dbg_check_lock(void);
  133. void _dbg_check_unlock(void);
  134. void _dbg_check_lock_from_isr(void);
  135. void _dbg_check_unlock_from_isr(void);
  136. void _dbg_check_enter_isr(void);
  137. void _dbg_check_leave_isr(void);
  138. void chDbgCheckClassI(void);
  139. void chDbgCheckClassS(void);
  140. #endif
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. /*===========================================================================*/
  145. /* Module inline functions. */
  146. /*===========================================================================*/
  147. #endif /* CHDEBUG_H */
  148. /** @} */