Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
amithy
Date:
Fri Nov 10 01:00:06 2017 +0000
Revision:
639:5aeed2c29513
Parent:
638:c90ae1400bf2
for testing export

Who changed what in which revision?

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