Fork of nRF51822 by
common/assertion.h@362:6fa0d4d555f6, 2015-07-02 (annotated)
- Committer:
- rgrover1
- Date:
- Thu Jul 02 09:08:44 2015 +0100
- Revision:
- 362:6fa0d4d555f6
- Parent:
- 361:d2405f5a4853
- Child:
- 370:295f76db798e
Synchronized with git rev 2716309c
Author: Rohit Grover
Release 0.4.0
=============
This is a major release which introduces the GATT Client functionality. It
aligns with release 0.4.0 of BLE_API.
Enhancements
~~~~~~~~~~~~
* Introduce GattClient. This includes functionality for service-discovery,
connections, and attribute-reads and writes. You'll find a demo program for
LEDBlinker on the mbed.org Bluetooth team page to use the new APIs. Some of
the GATT client functionality hasn't been implemented yet, but the APIs have
been added.
* We've added an implementation for the abstract base class for
SecurityManager. All security related APIs have been moved into that.
* There has been a major cleanup of APIs under BLE. APIs have now been
categorized as belonging to Gap, GattServer, GattClient, or SecurityManager.
There are accessors to get references for Gap, GattServer, GattClient, and
SecurityManager. A former call to ble.setAddress(...) is now expected to be
achieved with ble.gap().setAddress(...).
* We've cleaned up our APIs, and this has resulted in dropping some APIs like
BLE::reset().
* We've also dropped GattServer::initializeGattDatabase(). THis was added at
some point to support controllers where a commit point was needed to
indicate when the application had finished constructing the GATT database.
This API would get called internally before Gap::startAdvertising(). We now
expect the underlying port to do the equivalent of initializeGattDatabase()
implicitly upon Gap::startAdvertising().
* We've added a version of Gap::disconnect() which takes a connection handle.
The previous API (which did not take a connection handle) has been
deprecated; it will still work for situations where there's only a single
active connection. We hold on to that API to allow existing code to migrate
to the new API.
Bugfixes
~~~~~~~~
* None.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:eff01767de02 | 1 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 2 | /*! |
bogdanm | 0:eff01767de02 | 3 | @file assertion.h |
bogdanm | 0:eff01767de02 | 4 | @author hathach (tinyusb.org) |
bogdanm | 0:eff01767de02 | 5 | |
bogdanm | 0:eff01767de02 | 6 | @section LICENSE |
bogdanm | 0:eff01767de02 | 7 | |
bogdanm | 0:eff01767de02 | 8 | Software License Agreement (BSD License) |
bogdanm | 0:eff01767de02 | 9 | |
bogdanm | 0:eff01767de02 | 10 | Copyright (c) 2013, K. Townsend (microBuilder.eu) |
bogdanm | 0:eff01767de02 | 11 | All rights reserved. |
bogdanm | 0:eff01767de02 | 12 | |
bogdanm | 0:eff01767de02 | 13 | Redistribution and use in source and binary forms, with or without |
bogdanm | 0:eff01767de02 | 14 | modification, are permitted provided that the following conditions are met: |
bogdanm | 0:eff01767de02 | 15 | 1. Redistributions of source code must retain the above copyright |
bogdanm | 0:eff01767de02 | 16 | notice, this list of conditions and the following disclaimer. |
bogdanm | 0:eff01767de02 | 17 | 2. Redistributions in binary form must reproduce the above copyright |
bogdanm | 0:eff01767de02 | 18 | notice, this list of conditions and the following disclaimer in the |
bogdanm | 0:eff01767de02 | 19 | documentation and/or other materials provided with the distribution. |
bogdanm | 0:eff01767de02 | 20 | 3. Neither the name of the copyright holders nor the |
bogdanm | 0:eff01767de02 | 21 | names of its contributors may be used to endorse or promote products |
bogdanm | 0:eff01767de02 | 22 | derived from this software without specific prior written permission. |
bogdanm | 0:eff01767de02 | 23 | |
bogdanm | 0:eff01767de02 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
bogdanm | 0:eff01767de02 | 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
bogdanm | 0:eff01767de02 | 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 0:eff01767de02 | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY |
bogdanm | 0:eff01767de02 | 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
bogdanm | 0:eff01767de02 | 29 | INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
bogdanm | 0:eff01767de02 | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND |
bogdanm | 0:eff01767de02 | 31 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bogdanm | 0:eff01767de02 | 32 | INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS |
bogdanm | 0:eff01767de02 | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 0:eff01767de02 | 34 | */ |
bogdanm | 0:eff01767de02 | 35 | /**************************************************************************/ |
bogdanm | 0:eff01767de02 | 36 | |
bogdanm | 0:eff01767de02 | 37 | /** \file |
bogdanm | 0:eff01767de02 | 38 | * \brief TBD |
bogdanm | 0:eff01767de02 | 39 | * |
bogdanm | 0:eff01767de02 | 40 | * \note TBD |
bogdanm | 0:eff01767de02 | 41 | */ |
bogdanm | 0:eff01767de02 | 42 | |
bogdanm | 0:eff01767de02 | 43 | /** \ingroup TBD |
bogdanm | 0:eff01767de02 | 44 | * \defgroup TBD |
bogdanm | 0:eff01767de02 | 45 | * \brief TBD |
bogdanm | 0:eff01767de02 | 46 | * |
bogdanm | 0:eff01767de02 | 47 | * @{ |
bogdanm | 0:eff01767de02 | 48 | */ |
bogdanm | 0:eff01767de02 | 49 | |
bogdanm | 0:eff01767de02 | 50 | #ifndef _ASSERTION_H_ |
bogdanm | 0:eff01767de02 | 51 | #define _ASSERTION_H_ |
bogdanm | 0:eff01767de02 | 52 | |
bogdanm | 0:eff01767de02 | 53 | #include "projectconfig.h" |
bogdanm | 0:eff01767de02 | 54 | |
bogdanm | 0:eff01767de02 | 55 | #ifdef __cplusplus |
bogdanm | 0:eff01767de02 | 56 | extern "C" |
bogdanm | 0:eff01767de02 | 57 | { |
bogdanm | 0:eff01767de02 | 58 | #endif |
bogdanm | 0:eff01767de02 | 59 | |
bogdanm | 0:eff01767de02 | 60 | static inline void debugger_breakpoint(void) ATTR_ALWAYS_INLINE; |
bogdanm | 0:eff01767de02 | 61 | static inline void debugger_breakpoint(void) |
bogdanm | 0:eff01767de02 | 62 | { |
bogdanm | 0:eff01767de02 | 63 | #ifndef _TEST_ |
bogdanm | 0:eff01767de02 | 64 | __asm("BKPT #0\n"); |
bogdanm | 0:eff01767de02 | 65 | #endif |
bogdanm | 0:eff01767de02 | 66 | } |
bogdanm | 0:eff01767de02 | 67 | |
bogdanm | 0:eff01767de02 | 68 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 69 | // Compile-time Assert |
bogdanm | 0:eff01767de02 | 70 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 71 | #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ |
bogdanm | 0:eff01767de02 | 72 | #define _ASSERT_COUNTER __COUNTER__ |
bogdanm | 0:eff01767de02 | 73 | #else |
bogdanm | 0:eff01767de02 | 74 | #define _ASSERT_COUNTER __LINE__ |
bogdanm | 0:eff01767de02 | 75 | #endif |
bogdanm | 0:eff01767de02 | 76 | |
bogdanm | 0:eff01767de02 | 77 | #define ASSERT_STATIC(const_expr, message) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) } |
bogdanm | 0:eff01767de02 | 78 | |
bogdanm | 0:eff01767de02 | 79 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 80 | // Assert Helper |
bogdanm | 0:eff01767de02 | 81 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 82 | //#ifndef _TEST_ |
rgrover1 | 362:6fa0d4d555f6 | 83 | // #define ASSERT_MESSAGE(format, ...) _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 84 | //#else |
rgrover1 | 362:6fa0d4d555f6 | 85 | // #define ASSERT_MESSAGE(format, ...) _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 86 | //#endif |
bogdanm | 0:eff01767de02 | 87 | |
bogdanm | 0:eff01767de02 | 88 | #if CFG_DEBUG == 3 |
bogdanm | 0:eff01767de02 | 89 | #define ASSERT_MESSAGE(format, ...) debugger_breakpoint() |
bogdanm | 0:eff01767de02 | 90 | #elif CFG_DEBUG == 2 |
bogdanm | 0:eff01767de02 | 91 | #define ASSERT_MESSAGE(format, ...) printf("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __PRETTY_FUNCTION__, __LINE__, __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 92 | #else |
bogdanm | 0:eff01767de02 | 93 | #define ASSERT_MESSAGE(format, ...) |
bogdanm | 0:eff01767de02 | 94 | #endif |
bogdanm | 0:eff01767de02 | 95 | |
bogdanm | 0:eff01767de02 | 96 | #define ASSERT_ERROR_HANDLER(x, para) \ |
bogdanm | 0:eff01767de02 | 97 | return (x) |
bogdanm | 0:eff01767de02 | 98 | |
bogdanm | 0:eff01767de02 | 99 | #define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \ |
bogdanm | 0:eff01767de02 | 100 | do{\ |
bogdanm | 0:eff01767de02 | 101 | setup_statement;\ |
bogdanm | 0:eff01767de02 | 102 | if (!(condition)) {\ |
bogdanm | 0:eff01767de02 | 103 | ASSERT_MESSAGE(format, __VA_ARGS__);\ |
bogdanm | 0:eff01767de02 | 104 | error_handler(error, handler_para);\ |
bogdanm | 0:eff01767de02 | 105 | }\ |
bogdanm | 0:eff01767de02 | 106 | }while(0) |
bogdanm | 0:eff01767de02 | 107 | |
bogdanm | 0:eff01767de02 | 108 | #define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 109 | |
bogdanm | 0:eff01767de02 | 110 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 111 | // error_t Status Assert TODO use ASSERT_DEFINE |
bogdanm | 0:eff01767de02 | 112 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 113 | #define ASSERT_STATUS_MESSAGE(sts, message) \ |
bogdanm | 0:eff01767de02 | 114 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
bogdanm | 0:eff01767de02 | 115 | ERROR_NONE == status, status, "%s: %s", ErrorStr[status], message) |
bogdanm | 0:eff01767de02 | 116 | |
bogdanm | 0:eff01767de02 | 117 | #define ASSERT_STATUS(sts) \ |
bogdanm | 0:eff01767de02 | 118 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
bogdanm | 0:eff01767de02 | 119 | ERROR_NONE == status, status, "error = %d", status) |
bogdanm | 0:eff01767de02 | 120 | |
bogdanm | 0:eff01767de02 | 121 | #define ASSERT_STATUS_RET_VOID(sts) \ |
bogdanm | 0:eff01767de02 | 122 | ASSERT_DEFINE(error_t status = (error_t)(sts),\ |
bogdanm | 0:eff01767de02 | 123 | ERROR_NONE == status, (void) 0, "error = %d", status) |
bogdanm | 0:eff01767de02 | 124 | |
bogdanm | 0:eff01767de02 | 125 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 126 | // Logical Assert |
bogdanm | 0:eff01767de02 | 127 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 128 | #define ASSERT(...) ASSERT_TRUE(__VA_ARGS__) |
bogdanm | 0:eff01767de02 | 129 | #define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false") |
bogdanm | 0:eff01767de02 | 130 | #define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true") |
bogdanm | 0:eff01767de02 | 131 | |
bogdanm | 0:eff01767de02 | 132 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 133 | // Pointer Assert |
bogdanm | 0:eff01767de02 | 134 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 135 | #define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) |
bogdanm | 0:eff01767de02 | 136 | #define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") |
bogdanm | 0:eff01767de02 | 137 | #define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL") |
bogdanm | 0:eff01767de02 | 138 | |
bogdanm | 0:eff01767de02 | 139 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 140 | // Integral Assert |
bogdanm | 0:eff01767de02 | 141 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 142 | #define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \ |
bogdanm | 0:eff01767de02 | 143 | ASSERT_DEFINE(\ |
bogdanm | 0:eff01767de02 | 144 | uint32_t exp = (expected); uint32_t act = (actual),\ |
bogdanm | 0:eff01767de02 | 145 | exp==act,\ |
bogdanm | 0:eff01767de02 | 146 | error,\ |
bogdanm | 0:eff01767de02 | 147 | "expected " type_format ", actual " type_format, exp, act) |
bogdanm | 0:eff01767de02 | 148 | |
bogdanm | 0:eff01767de02 | 149 | #define ASSERT_XXX_WITHIN(type_format, lower, upper, actual, error) \ |
bogdanm | 0:eff01767de02 | 150 | ASSERT_DEFINE(\ |
bogdanm | 0:eff01767de02 | 151 | uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\ |
bogdanm | 0:eff01767de02 | 152 | (low <= act) && (act <= up),\ |
bogdanm | 0:eff01767de02 | 153 | error,\ |
bogdanm | 0:eff01767de02 | 154 | "expected within " type_format " - " type_format ", actual " type_format, low, up, act) |
bogdanm | 0:eff01767de02 | 155 | |
bogdanm | 0:eff01767de02 | 156 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 157 | // Integer Assert |
bogdanm | 0:eff01767de02 | 158 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 159 | #define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__) |
bogdanm | 0:eff01767de02 | 160 | #define ASSERT_INT_EQUAL(...) ASSERT_XXX_EQUAL("%d", __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 161 | #define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 162 | |
bogdanm | 0:eff01767de02 | 163 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 164 | // Hex Assert |
bogdanm | 0:eff01767de02 | 165 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 166 | #define ASSERT_HEX(...) ASSERT_HEX_EQUAL(__VA_ARGS__) |
bogdanm | 0:eff01767de02 | 167 | #define ASSERT_HEX_EQUAL(...) ASSERT_XXX_EQUAL("0x%x", __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 168 | #define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__) |
bogdanm | 0:eff01767de02 | 169 | |
bogdanm | 0:eff01767de02 | 170 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 171 | // Bin Assert |
bogdanm | 0:eff01767de02 | 172 | //--------------------------------------------------------------------+ |
bogdanm | 0:eff01767de02 | 173 | #define BIN8_PRINTF_PATTERN "%d%d%d%d%d%d%d%d" |
bogdanm | 0:eff01767de02 | 174 | #define BIN8_PRINTF_CONVERT(byte) \ |
bogdanm | 0:eff01767de02 | 175 | ((byte) & 0x80 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 176 | ((byte) & 0x40 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 177 | ((byte) & 0x20 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 178 | ((byte) & 0x10 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 179 | ((byte) & 0x08 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 180 | ((byte) & 0x04 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 181 | ((byte) & 0x02 ? 1 : 0), \ |
bogdanm | 0:eff01767de02 | 182 | ((byte) & 0x01 ? 1 : 0) |
bogdanm | 0:eff01767de02 | 183 | |
bogdanm | 0:eff01767de02 | 184 | #define ASSERT_BIN8(...) ASSERT_BIN8_EQUAL(__VA_ARGS__) |
bogdanm | 0:eff01767de02 | 185 | #define ASSERT_BIN8_EQUAL(expected, actual, error)\ |
bogdanm | 0:eff01767de02 | 186 | ASSERT_DEFINE(\ |
bogdanm | 0:eff01767de02 | 187 | uint8_t exp = (expected); uint8_t act = (actual),\ |
bogdanm | 0:eff01767de02 | 188 | exp==act,\ |
bogdanm | 0:eff01767de02 | 189 | error,\ |
bogdanm | 0:eff01767de02 | 190 | "expected " BIN8_PRINTF_PATTERN ", actual " BIN8_PRINTF_PATTERN, BIN8_PRINTF_CONVERT(exp), BIN8_PRINTF_CONVERT(act) ) |
bogdanm | 0:eff01767de02 | 191 | |
bogdanm | 0:eff01767de02 | 192 | #ifdef __cplusplus |
bogdanm | 0:eff01767de02 | 193 | } |
bogdanm | 0:eff01767de02 | 194 | #endif |
bogdanm | 0:eff01767de02 | 195 | |
bogdanm | 0:eff01767de02 | 196 | #endif /* _ASSERTION_H_ */ |
bogdanm | 0:eff01767de02 | 197 | |
rgrover1 | 345:dfde56236c36 | 198 | /** @} */ |