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