Yutaka Yoshida
/
BLE_WallbotBLE_Challenge_byYUTAKA3
6/22 上下往復完成版
Fork of BLE_WallbotBLE_Challenge_byYUTAKA3 by
nRF51822/common/assertion.h@0:76dfa9657d9d, 2014-11-12 (annotated)
- Committer:
- jksoft
- Date:
- Wed Nov 12 02:40:34 2014 +0000
- Revision:
- 0:76dfa9657d9d
????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 2 | /*! |
jksoft | 0:76dfa9657d9d | 3 | @file assertion.h |
jksoft | 0:76dfa9657d9d | 4 | @author hathach (tinyusb.org) |
jksoft | 0:76dfa9657d9d | 5 | |
jksoft | 0:76dfa9657d9d | 6 | @section LICENSE |
jksoft | 0:76dfa9657d9d | 7 | |
jksoft | 0:76dfa9657d9d | 8 | Software License Agreement (BSD License) |
jksoft | 0:76dfa9657d9d | 9 | |
jksoft | 0:76dfa9657d9d | 10 | Copyright (c) 2013, K. Townsend (microBuilder.eu) |
jksoft | 0:76dfa9657d9d | 11 | All rights reserved. |
jksoft | 0:76dfa9657d9d | 12 | |
jksoft | 0:76dfa9657d9d | 13 | Redistribution and use in source and binary forms, with or without |
jksoft | 0:76dfa9657d9d | 14 | modification, are permitted provided that the following conditions are met: |
jksoft | 0:76dfa9657d9d | 15 | 1. Redistributions of source code must retain the above copyright |
jksoft | 0:76dfa9657d9d | 16 | notice, this list of conditions and the following disclaimer. |
jksoft | 0:76dfa9657d9d | 17 | 2. Redistributions in binary form must reproduce the above copyright |
jksoft | 0:76dfa9657d9d | 18 | notice, this list of conditions and the following disclaimer in the |
jksoft | 0:76dfa9657d9d | 19 | documentation and/or other materials provided with the distribution. |
jksoft | 0:76dfa9657d9d | 20 | 3. Neither the name of the copyright holders nor the |
jksoft | 0:76dfa9657d9d | 21 | names of its contributors may be used to endorse or promote products |
jksoft | 0:76dfa9657d9d | 22 | derived from this software without specific prior written permission. |
jksoft | 0:76dfa9657d9d | 23 | |
jksoft | 0:76dfa9657d9d | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
jksoft | 0:76dfa9657d9d | 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
jksoft | 0:76dfa9657d9d | 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
jksoft | 0:76dfa9657d9d | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
jksoft | 0:76dfa9657d9d | 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
jksoft | 0:76dfa9657d9d | 29 | INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
jksoft | 0:76dfa9657d9d | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND |
jksoft | 0:76dfa9657d9d | 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
jksoft | 0:76dfa9657d9d | 32 | INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS |
jksoft | 0:76dfa9657d9d | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
jksoft | 0:76dfa9657d9d | 34 | */ |
jksoft | 0:76dfa9657d9d | 35 | /**************************************************************************/ |
jksoft | 0:76dfa9657d9d | 36 | |
jksoft | 0:76dfa9657d9d | 37 | /** \file |
jksoft | 0:76dfa9657d9d | 38 | * \brief TBD |
jksoft | 0:76dfa9657d9d | 39 | * |
jksoft | 0:76dfa9657d9d | 40 | * \note TBD |
jksoft | 0:76dfa9657d9d | 41 | */ |
jksoft | 0:76dfa9657d9d | 42 | |
jksoft | 0:76dfa9657d9d | 43 | /** \ingroup TBD |
jksoft | 0:76dfa9657d9d | 44 | * \defgroup TBD |
jksoft | 0:76dfa9657d9d | 45 | * \brief TBD |
jksoft | 0:76dfa9657d9d | 46 | * |
jksoft | 0:76dfa9657d9d | 47 | * @{ |
jksoft | 0:76dfa9657d9d | 48 | */ |
jksoft | 0:76dfa9657d9d | 49 | |
jksoft | 0:76dfa9657d9d | 50 | #ifndef _ASSERTION_H_ |
jksoft | 0:76dfa9657d9d | 51 | #define _ASSERTION_H_ |
jksoft | 0:76dfa9657d9d | 52 | |
jksoft | 0:76dfa9657d9d | 53 | #include "projectconfig.h" |
jksoft | 0:76dfa9657d9d | 54 | |
jksoft | 0:76dfa9657d9d | 55 | #ifdef __cplusplus |
jksoft | 0:76dfa9657d9d | 56 | extern "C" |
jksoft | 0:76dfa9657d9d | 57 | { |
jksoft | 0:76dfa9657d9d | 58 | #endif |
jksoft | 0:76dfa9657d9d | 59 | |
jksoft | 0:76dfa9657d9d | 60 | static inline void debugger_breakpoint(void) ATTR_ALWAYS_INLINE; |
jksoft | 0:76dfa9657d9d | 61 | static inline void debugger_breakpoint(void) |
jksoft | 0:76dfa9657d9d | 62 | { |
jksoft | 0:76dfa9657d9d | 63 | #ifndef _TEST_ |
jksoft | 0:76dfa9657d9d | 64 | __asm("BKPT #0\n"); |
jksoft | 0:76dfa9657d9d | 65 | #endif |
jksoft | 0:76dfa9657d9d | 66 | } |
jksoft | 0:76dfa9657d9d | 67 | |
jksoft | 0:76dfa9657d9d | 68 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 69 | // Compile-time Assert |
jksoft | 0:76dfa9657d9d | 70 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 71 | #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ |
jksoft | 0:76dfa9657d9d | 72 | #define _ASSERT_COUNTER __COUNTER__ |
jksoft | 0:76dfa9657d9d | 73 | #else |
jksoft | 0:76dfa9657d9d | 74 | #define _ASSERT_COUNTER __LINE__ |
jksoft | 0:76dfa9657d9d | 75 | #endif |
jksoft | 0:76dfa9657d9d | 76 | |
jksoft | 0:76dfa9657d9d | 77 | #define ASSERT_STATIC(const_expr, message) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) } |
jksoft | 0:76dfa9657d9d | 78 | |
jksoft | 0:76dfa9657d9d | 79 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 80 | // Assert Helper |
jksoft | 0:76dfa9657d9d | 81 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 82 | //#ifndef _TEST_ |
jksoft | 0:76dfa9657d9d | 83 | // #define ASSERT_MESSAGE(format, ...)\ |
jksoft | 0:76dfa9657d9d | 84 | // _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 85 | //#else |
jksoft | 0:76dfa9657d9d | 86 | // #define ASSERT_MESSAGE(format, ...)\ |
jksoft | 0:76dfa9657d9d | 87 | // _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 88 | //#endif |
jksoft | 0:76dfa9657d9d | 89 | |
jksoft | 0:76dfa9657d9d | 90 | #if CFG_DEBUG == 3 |
jksoft | 0:76dfa9657d9d | 91 | #define ASSERT_MESSAGE(format, ...) debugger_breakpoint() |
jksoft | 0:76dfa9657d9d | 92 | #elif CFG_DEBUG == 2 |
jksoft | 0:76dfa9657d9d | 93 | #define ASSERT_MESSAGE(format, ...) printf("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 94 | #else |
jksoft | 0:76dfa9657d9d | 95 | #define ASSERT_MESSAGE(format, ...) |
jksoft | 0:76dfa9657d9d | 96 | #endif |
jksoft | 0:76dfa9657d9d | 97 | |
jksoft | 0:76dfa9657d9d | 98 | #define ASSERT_ERROR_HANDLER(x, para) \ |
jksoft | 0:76dfa9657d9d | 99 | return (x) |
jksoft | 0:76dfa9657d9d | 100 | |
jksoft | 0:76dfa9657d9d | 101 | #define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \ |
jksoft | 0:76dfa9657d9d | 102 | do{\ |
jksoft | 0:76dfa9657d9d | 103 | setup_statement;\ |
jksoft | 0:76dfa9657d9d | 104 | if (!(condition)) {\ |
jksoft | 0:76dfa9657d9d | 105 | ASSERT_MESSAGE(format, __VA_ARGS__);\ |
jksoft | 0:76dfa9657d9d | 106 | error_handler(error, handler_para);\ |
jksoft | 0:76dfa9657d9d | 107 | }\ |
jksoft | 0:76dfa9657d9d | 108 | }while(0) |
jksoft | 0:76dfa9657d9d | 109 | |
jksoft | 0:76dfa9657d9d | 110 | #define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 111 | |
jksoft | 0:76dfa9657d9d | 112 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 113 | // error_t Status Assert TODO use ASSERT_DEFINE |
jksoft | 0:76dfa9657d9d | 114 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 115 | #define ASSERT_STATUS_MESSAGE(sts, message) \ |
jksoft | 0:76dfa9657d9d | 116 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
jksoft | 0:76dfa9657d9d | 117 | ERROR_NONE == status, status, "%s: %s", ErrorStr[status], message) |
jksoft | 0:76dfa9657d9d | 118 | |
jksoft | 0:76dfa9657d9d | 119 | #define ASSERT_STATUS(sts) \ |
jksoft | 0:76dfa9657d9d | 120 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
jksoft | 0:76dfa9657d9d | 121 | ERROR_NONE == status, status, "error = %d", status) |
jksoft | 0:76dfa9657d9d | 122 | |
jksoft | 0:76dfa9657d9d | 123 | #define ASSERT_STATUS_RET_VOID(sts) \ |
jksoft | 0:76dfa9657d9d | 124 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
jksoft | 0:76dfa9657d9d | 125 | ERROR_NONE == status, (void) 0, "error = %d", status) |
jksoft | 0:76dfa9657d9d | 126 | |
jksoft | 0:76dfa9657d9d | 127 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 128 | // Logical Assert |
jksoft | 0:76dfa9657d9d | 129 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 130 | #define ASSERT(...) ASSERT_TRUE(__VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 131 | #define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false") |
jksoft | 0:76dfa9657d9d | 132 | #define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true") |
jksoft | 0:76dfa9657d9d | 133 | |
jksoft | 0:76dfa9657d9d | 134 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 135 | // Pointer Assert |
jksoft | 0:76dfa9657d9d | 136 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 137 | #define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 138 | #define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") |
jksoft | 0:76dfa9657d9d | 139 | #define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL") |
jksoft | 0:76dfa9657d9d | 140 | |
jksoft | 0:76dfa9657d9d | 141 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 142 | // Integral Assert |
jksoft | 0:76dfa9657d9d | 143 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 144 | #define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \ |
jksoft | 0:76dfa9657d9d | 145 | ASSERT_DEFINE(\ |
jksoft | 0:76dfa9657d9d | 146 | uint32_t exp = (expected); uint32_t act = (actual),\ |
jksoft | 0:76dfa9657d9d | 147 | exp==act,\ |
jksoft | 0:76dfa9657d9d | 148 | error,\ |
jksoft | 0:76dfa9657d9d | 149 | "expected " type_format ", actual " type_format, exp, act) |
jksoft | 0:76dfa9657d9d | 150 | |
jksoft | 0:76dfa9657d9d | 151 | #define ASSERT_XXX_WITHIN(type_format, lower, upper, actual, error) \ |
jksoft | 0:76dfa9657d9d | 152 | ASSERT_DEFINE(\ |
jksoft | 0:76dfa9657d9d | 153 | uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\ |
jksoft | 0:76dfa9657d9d | 154 | (low <= act) && (act <= up),\ |
jksoft | 0:76dfa9657d9d | 155 | error,\ |
jksoft | 0:76dfa9657d9d | 156 | "expected within " type_format " - " type_format ", actual " type_format, low, up, act) |
jksoft | 0:76dfa9657d9d | 157 | |
jksoft | 0:76dfa9657d9d | 158 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 159 | // Integer Assert |
jksoft | 0:76dfa9657d9d | 160 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 161 | #define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 162 | #define ASSERT_INT_EQUAL(...) ASSERT_XXX_EQUAL("%d", __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 163 | #define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 164 | |
jksoft | 0:76dfa9657d9d | 165 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 166 | // Hex Assert |
jksoft | 0:76dfa9657d9d | 167 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 168 | #define ASSERT_HEX(...) ASSERT_HEX_EQUAL(__VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 169 | #define ASSERT_HEX_EQUAL(...) ASSERT_XXX_EQUAL("0x%x", __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 170 | #define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 171 | |
jksoft | 0:76dfa9657d9d | 172 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 173 | // Bin Assert |
jksoft | 0:76dfa9657d9d | 174 | //--------------------------------------------------------------------+ |
jksoft | 0:76dfa9657d9d | 175 | #define BIN8_PRINTF_PATTERN "%d%d%d%d%d%d%d%d" |
jksoft | 0:76dfa9657d9d | 176 | #define BIN8_PRINTF_CONVERT(byte) \ |
jksoft | 0:76dfa9657d9d | 177 | ((byte) & 0x80 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 178 | ((byte) & 0x40 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 179 | ((byte) & 0x20 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 180 | ((byte) & 0x10 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 181 | ((byte) & 0x08 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 182 | ((byte) & 0x04 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 183 | ((byte) & 0x02 ? 1 : 0), \ |
jksoft | 0:76dfa9657d9d | 184 | ((byte) & 0x01 ? 1 : 0) |
jksoft | 0:76dfa9657d9d | 185 | |
jksoft | 0:76dfa9657d9d | 186 | #define ASSERT_BIN8(...) ASSERT_BIN8_EQUAL(__VA_ARGS__) |
jksoft | 0:76dfa9657d9d | 187 | #define ASSERT_BIN8_EQUAL(expected, actual, error)\ |
jksoft | 0:76dfa9657d9d | 188 | ASSERT_DEFINE(\ |
jksoft | 0:76dfa9657d9d | 189 | uint8_t exp = (expected); uint8_t act = (actual),\ |
jksoft | 0:76dfa9657d9d | 190 | exp==act,\ |
jksoft | 0:76dfa9657d9d | 191 | error,\ |
jksoft | 0:76dfa9657d9d | 192 | "expected " BIN8_PRINTF_PATTERN ", actual " BIN8_PRINTF_PATTERN, BIN8_PRINTF_CONVERT(exp), BIN8_PRINTF_CONVERT(act) ) |
jksoft | 0:76dfa9657d9d | 193 | |
jksoft | 0:76dfa9657d9d | 194 | #ifdef __cplusplus |
jksoft | 0:76dfa9657d9d | 195 | } |
jksoft | 0:76dfa9657d9d | 196 | #endif |
jksoft | 0:76dfa9657d9d | 197 | |
jksoft | 0:76dfa9657d9d | 198 | #endif /* _ASSERTION_H_ */ |
jksoft | 0:76dfa9657d9d | 199 | |
jksoft | 0:76dfa9657d9d | 200 | /** @} */ |