CSSE4011_BLE_IMU IMU Seeed Tiny Ble

Dependencies:   BLE_API_Tiny_BLE MPU6050-DMP-Seeed-Tiny-BLE mbed

Committer:
flywind
Date:
Wed Jun 10 12:56:48 2015 +0000
Revision:
2:44bc61abdf33
Parent:
0:f90c3452d779
milestone working one , yaw pitch roll update in BLE sucessfull

Who changed what in which revision?

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