ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file chdebug.h 00029 * @brief Debug macros and structures. 00030 * 00031 * @addtogroup debug 00032 * @{ 00033 */ 00034 00035 #ifndef _CHDEBUG_H_ 00036 #define _CHDEBUG_H_ 00037 00038 /** 00039 * @brief Trace buffer entries. 00040 */ 00041 #ifndef TRACE_BUFFER_SIZE 00042 #define TRACE_BUFFER_SIZE 64 00043 #endif 00044 00045 /** 00046 * @brief Fill value for thread stack area in debug mode. 00047 */ 00048 #ifndef STACK_FILL_VALUE 00049 #define STACK_FILL_VALUE 0x55 00050 #endif 00051 00052 /** 00053 * @brief Fill value for thread area in debug mode. 00054 * @note The chosen default value is 0xFF in order to make evident which 00055 * thread fields were not initialized when inspecting the memory with 00056 * a debugger. A uninitialized field is not an error in itself but it 00057 * better to know it. 00058 */ 00059 #ifndef THREAD_FILL_VALUE 00060 #define THREAD_FILL_VALUE 0xFF 00061 #endif 00062 00063 #if CH_DBG_ENABLE_TRACE || defined(__DOXYGEN__) 00064 /** 00065 * @brief Trace buffer record. 00066 */ 00067 typedef struct { 00068 void *cse_wtobjp; /**< @brief Object where going to 00069 sleep. */ 00070 systime_t cse_time; /**< @brief Time of the switch 00071 event. */ 00072 uint16_t cse_state: 4; /**< @brief Switched out thread 00073 state. */ 00074 uint16_t cse_tid: 12; /**< @brief Switched in thread id. */ 00075 } CtxSwcEvent; 00076 00077 /** 00078 * @brief Trace buffer header. 00079 */ 00080 typedef struct { 00081 unsigned tb_size; /**< @brief Trace buffer size 00082 (entries). */ 00083 CtxSwcEvent *tb_ptr; /**< @brief Pointer to the ring buffer 00084 front. */ 00085 /** @brief Ring buffer.*/ 00086 CtxSwcEvent tb_buffer[TRACE_BUFFER_SIZE]; 00087 } TraceBuffer; 00088 #endif /* CH_DBG_ENABLE_TRACE */ 00089 00090 #define __QUOTE_THIS(p) #p 00091 00092 #if CH_DBG_ENABLE_CHECKS 00093 /** 00094 * @brief Function parameter check. 00095 * @details If the condition check fails then the kernel panics and halts. 00096 * @note The condition is tested only if the @p CH_DBG_ENABLE_CHECKS switch 00097 * is specified in @p chconf.h else the macro does nothing. 00098 * 00099 * @param[in] c the condition to be verified to be true 00100 * @param[in] func the undecorated function name 00101 */ 00102 #define chDbgCheck(c, func) { \ 00103 if (!(c)) \ 00104 chDbgPanic(__QUOTE_THIS(func)"(), line "__QUOTE_THIS(__LINE__)); \ 00105 } 00106 #else /* !CH_DBG_ENABLE_CHECKS */ 00107 #define chDbgCheck(c, func) { \ 00108 (void)(c), (void)__QUOTE_THIS(func)"(), line "__QUOTE_THIS(__LINE__); \ 00109 } 00110 #endif /* !CH_DBG_ENABLE_CHECKS */ 00111 00112 #if CH_DBG_ENABLE_ASSERTS 00113 /** 00114 * @brief Condition assertion. 00115 * @details If the condition check fails then the kernel panics with the 00116 * specified message and halts. 00117 * @note The condition is tested only if the @p CH_DBG_ENABLE_ASSERTS switch 00118 * is specified in @p chconf.h else the macro does nothing. 00119 * @note The convention for the message is the following:<br> 00120 * @<function_name@>(), #@<assert_number@> 00121 * @note The remark string is not currently used except for putting a 00122 * comment in the code about the assertion. 00123 * 00124 * @param[in] c the condition to be verified to be true 00125 * @param[in] m the text message 00126 * @param[in] r a remark string 00127 */ 00128 #define chDbgAssert(c, m, r) { \ 00129 if (!(c)) \ 00130 chDbgPanic(m); \ 00131 } 00132 #else /* !CH_DBG_ENABLE_ASSERTS */ 00133 #define chDbgAssert(c, m, r) {(void)(c);} 00134 #endif /* !CH_DBG_ENABLE_ASSERTS */ 00135 00136 #if !(CH_DBG_ENABLE_ASSERTS || \ 00137 CH_DBG_ENABLE_CHECKS || \ 00138 CH_DBG_ENABLE_STACK_CHECK) 00139 /* When the debug features are disabled this function is replaced by an empty 00140 macro.*/ 00141 #define chDbgPanic(msg) {} 00142 #endif 00143 00144 #if !CH_DBG_ENABLE_TRACE 00145 /* When the trace feature is disabled this function is replaced by an empty 00146 macro.*/ 00147 #define chDbgTrace(otp) {} 00148 #endif 00149 00150 #if !defined(__DOXYGEN__) 00151 #ifdef __cplusplus 00152 extern "C" { 00153 #endif 00154 #if CH_DBG_ENABLE_TRACE 00155 extern TraceBuffer trace_buffer; 00156 void trace_init(void); 00157 void chDbgTrace(Thread *otp); 00158 #endif 00159 #if CH_DBG_ENABLE_ASSERTS || CH_DBG_ENABLE_CHECKS || CH_DBG_ENABLE_STACK_CHECK 00160 extern char *panic_msg; 00161 void chDbgPanic(char *msg); 00162 #endif 00163 #ifdef __cplusplus 00164 } 00165 #endif 00166 #endif /* !defined(__DOXYGEN__) */ 00167 00168 #endif /* _CHDEBUG_H_ */ 00169 00170 /** @} */