Wallbot_CaaS
Dependencies: MPU6050 mbed PID
Fork of BLE_MPU6050_test6_challenge_sb by
assertion.h
00001 /**************************************************************************/ 00002 /*! 00003 @file assertion.h 00004 @author hathach (tinyusb.org) 00005 00006 @section LICENSE 00007 00008 Software License Agreement (BSD License) 00009 00010 Copyright (c) 2013, K. Townsend (microBuilder.eu) 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 1. Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 3. Neither the name of the copyright holders nor the 00021 names of its contributors may be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 00025 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00028 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND 00031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 /**************************************************************************/ 00036 00037 /** \file 00038 * \brief TBD 00039 * 00040 * \note TBD 00041 */ 00042 00043 /** \ingroup TBD 00044 * \defgroup TBD 00045 * \brief TBD 00046 * 00047 * @{ 00048 */ 00049 00050 #ifndef _ASSERTION_H_ 00051 #define _ASSERTION_H_ 00052 00053 #include "projectconfig.h" 00054 00055 #ifdef __cplusplus 00056 extern "C" 00057 { 00058 #endif 00059 00060 static inline void debugger_breakpoint(void) ATTR_ALWAYS_INLINE; 00061 static inline void debugger_breakpoint(void) 00062 { 00063 #ifndef _TEST_ 00064 __asm("BKPT #0\n"); 00065 #endif 00066 } 00067 00068 //--------------------------------------------------------------------+ 00069 // Compile-time Assert 00070 //--------------------------------------------------------------------+ 00071 #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ 00072 #define _ASSERT_COUNTER __COUNTER__ 00073 #else 00074 #define _ASSERT_COUNTER __LINE__ 00075 #endif 00076 00077 #define ASSERT_STATIC(const_expr, message) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) } 00078 00079 //--------------------------------------------------------------------+ 00080 // Assert Helper 00081 //--------------------------------------------------------------------+ 00082 //#ifndef _TEST_ 00083 // #define ASSERT_MESSAGE(format, ...)\ 00084 // _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) 00085 //#else 00086 // #define ASSERT_MESSAGE(format, ...)\ 00087 // _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__) 00088 //#endif 00089 00090 #if CFG_DEBUG == 3 00091 #define ASSERT_MESSAGE(format, ...) debugger_breakpoint() 00092 #elif CFG_DEBUG == 2 00093 #define ASSERT_MESSAGE(format, ...) printf("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) 00094 #else 00095 #define ASSERT_MESSAGE(format, ...) 00096 #endif 00097 00098 #define ASSERT_ERROR_HANDLER(x, para) \ 00099 return (x) 00100 00101 #define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \ 00102 do{\ 00103 setup_statement;\ 00104 if (!(condition)) {\ 00105 ASSERT_MESSAGE(format, __VA_ARGS__);\ 00106 error_handler(error, handler_para);\ 00107 }\ 00108 }while(0) 00109 00110 #define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__) 00111 00112 //--------------------------------------------------------------------+ 00113 // error_t Status Assert TODO use ASSERT_DEFINE 00114 //--------------------------------------------------------------------+ 00115 #define ASSERT_STATUS_MESSAGE(sts, message) \ 00116 ASSERT_DEFINE(error_t status = (error_t)(sts),\ 00117 ERROR_NONE == status, status, "%s: %s", ErrorStr[status], message) 00118 00119 #define ASSERT_STATUS(sts) \ 00120 ASSERT_DEFINE(error_t status = (error_t)(sts),\ 00121 ERROR_NONE == status, status, "error = %d", status) 00122 00123 #define ASSERT_STATUS_RET_VOID(sts) \ 00124 ASSERT_DEFINE(error_t status = (error_t)(sts),\ 00125 ERROR_NONE == status, (void) 0, "error = %d", status) 00126 00127 //--------------------------------------------------------------------+ 00128 // Logical Assert 00129 //--------------------------------------------------------------------+ 00130 #define ASSERT(...) ASSERT_TRUE(__VA_ARGS__) 00131 #define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false") 00132 #define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true") 00133 00134 //--------------------------------------------------------------------+ 00135 // Pointer Assert 00136 //--------------------------------------------------------------------+ 00137 #define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) 00138 #define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") 00139 #define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL") 00140 00141 //--------------------------------------------------------------------+ 00142 // Integral Assert 00143 //--------------------------------------------------------------------+ 00144 #define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \ 00145 ASSERT_DEFINE(\ 00146 uint32_t exp = (expected); uint32_t act = (actual),\ 00147 exp==act,\ 00148 error,\ 00149 "expected " type_format ", actual " type_format, exp, act) 00150 00151 #define ASSERT_XXX_WITHIN(type_format, lower, upper, actual, error) \ 00152 ASSERT_DEFINE(\ 00153 uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\ 00154 (low <= act) && (act <= up),\ 00155 error,\ 00156 "expected within " type_format " - " type_format ", actual " type_format, low, up, act) 00157 00158 //--------------------------------------------------------------------+ 00159 // Integer Assert 00160 //--------------------------------------------------------------------+ 00161 #define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__) 00162 #define ASSERT_INT_EQUAL(...) ASSERT_XXX_EQUAL("%d", __VA_ARGS__) 00163 #define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__) 00164 00165 //--------------------------------------------------------------------+ 00166 // Hex Assert 00167 //--------------------------------------------------------------------+ 00168 #define ASSERT_HEX(...) ASSERT_HEX_EQUAL(__VA_ARGS__) 00169 #define ASSERT_HEX_EQUAL(...) ASSERT_XXX_EQUAL("0x%x", __VA_ARGS__) 00170 #define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__) 00171 00172 //--------------------------------------------------------------------+ 00173 // Bin Assert 00174 //--------------------------------------------------------------------+ 00175 #define BIN8_PRINTF_PATTERN "%d%d%d%d%d%d%d%d" 00176 #define BIN8_PRINTF_CONVERT(byte) \ 00177 ((byte) & 0x80 ? 1 : 0), \ 00178 ((byte) & 0x40 ? 1 : 0), \ 00179 ((byte) & 0x20 ? 1 : 0), \ 00180 ((byte) & 0x10 ? 1 : 0), \ 00181 ((byte) & 0x08 ? 1 : 0), \ 00182 ((byte) & 0x04 ? 1 : 0), \ 00183 ((byte) & 0x02 ? 1 : 0), \ 00184 ((byte) & 0x01 ? 1 : 0) 00185 00186 #define ASSERT_BIN8(...) ASSERT_BIN8_EQUAL(__VA_ARGS__) 00187 #define ASSERT_BIN8_EQUAL(expected, actual, error)\ 00188 ASSERT_DEFINE(\ 00189 uint8_t exp = (expected); uint8_t act = (actual),\ 00190 exp==act,\ 00191 error,\ 00192 "expected " BIN8_PRINTF_PATTERN ", actual " BIN8_PRINTF_PATTERN, BIN8_PRINTF_CONVERT(exp), BIN8_PRINTF_CONVERT(act) ) 00193 00194 #ifdef __cplusplus 00195 } 00196 #endif 00197 00198 #endif /* _ASSERTION_H_ */ 00199 00200 /** @} */
Generated on Tue Jul 12 2022 18:33:09 by 1.7.2