mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1
<> 149:156823d33999 2 /** \addtogroup platform */
<> 149:156823d33999 3 /** @{*/
AnnaBridge 178:79309dc6340a 4 /**
AnnaBridge 178:79309dc6340a 5 * \defgroup platform_Assert Assert macros
AnnaBridge 178:79309dc6340a 6 * @{
AnnaBridge 178:79309dc6340a 7 */
<> 149:156823d33999 8 /* mbed Microcontroller Library
<> 149:156823d33999 9 * Copyright (c) 2006-2013 ARM Limited
AnnaBridge 189:f392fc9709a3 10 * SPDX-License-Identifier: Apache-2.0
<> 149:156823d33999 11 *
<> 149:156823d33999 12 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 13 * you may not use this file except in compliance with the License.
<> 149:156823d33999 14 * You may obtain a copy of the License at
<> 149:156823d33999 15 *
<> 149:156823d33999 16 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 17 *
<> 149:156823d33999 18 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 19 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 21 * See the License for the specific language governing permissions and
<> 149:156823d33999 22 * limitations under the License.
<> 149:156823d33999 23 */
<> 149:156823d33999 24 #ifndef MBED_ASSERT_H
<> 149:156823d33999 25 #define MBED_ASSERT_H
<> 149:156823d33999 26
<> 151:5eaa88a5bcc7 27 #include "mbed_preprocessor.h"
AnnaBridge 189:f392fc9709a3 28 #include "mbed_toolchain.h"
<> 151:5eaa88a5bcc7 29
<> 149:156823d33999 30 #ifdef __cplusplus
<> 149:156823d33999 31 extern "C" {
<> 149:156823d33999 32 #endif
<> 149:156823d33999 33
AnnaBridge 188:bcfe06ba3d64 34 /** Internal mbed assert function which is invoked when MBED_ASSERT macro fails.
<> 149:156823d33999 35 * This function is active only if NDEBUG is not defined prior to including this
<> 149:156823d33999 36 * assert header file.
<> 149:156823d33999 37 * In case of MBED_ASSERT failing condition, error() is called with the assertation message.
AnnaBridge 188:bcfe06ba3d64 38 * @param expr Expression to be checked.
<> 149:156823d33999 39 * @param file File where assertation failed.
<> 149:156823d33999 40 * @param line Failing assertation line number.
<> 149:156823d33999 41 */
AnnaBridge 189:f392fc9709a3 42 MBED_NORETURN void mbed_assert_internal(const char *expr, const char *file, int line);
<> 149:156823d33999 43
<> 149:156823d33999 44 #ifdef __cplusplus
<> 149:156823d33999 45 }
<> 149:156823d33999 46 #endif
<> 149:156823d33999 47
AnnaBridge 178:79309dc6340a 48 /** MBED_ASSERT
AnnaBridge 178:79309dc6340a 49 * Declare runtime assertions: results in runtime error if condition is false
AnnaBridge 178:79309dc6340a 50 *
AnnaBridge 178:79309dc6340a 51 * @note
AnnaBridge 178:79309dc6340a 52 * Use of MBED_ASSERT is limited to Debug and Develop builds.
AnnaBridge 178:79309dc6340a 53 *
AnnaBridge 178:79309dc6340a 54 * @code
AnnaBridge 178:79309dc6340a 55 *
AnnaBridge 178:79309dc6340a 56 * int Configure(serial_t *obj) {
AnnaBridge 178:79309dc6340a 57 * MBED_ASSERT(obj);
AnnaBridge 178:79309dc6340a 58 * }
AnnaBridge 178:79309dc6340a 59 * @endcode
AnnaBridge 178:79309dc6340a 60 */
<> 149:156823d33999 61 #ifdef NDEBUG
<> 149:156823d33999 62 #define MBED_ASSERT(expr) ((void)0)
<> 149:156823d33999 63
<> 149:156823d33999 64 #else
<> 149:156823d33999 65 #define MBED_ASSERT(expr) \
<> 149:156823d33999 66 do { \
<> 149:156823d33999 67 if (!(expr)) { \
<> 149:156823d33999 68 mbed_assert_internal(#expr, __FILE__, __LINE__); \
<> 149:156823d33999 69 } \
<> 149:156823d33999 70 } while (0)
<> 149:156823d33999 71 #endif
<> 149:156823d33999 72
<> 151:5eaa88a5bcc7 73
<> 151:5eaa88a5bcc7 74 /** MBED_STATIC_ASSERT
<> 151:5eaa88a5bcc7 75 * Declare compile-time assertions, results in compile-time error if condition is false
<> 151:5eaa88a5bcc7 76 *
<> 151:5eaa88a5bcc7 77 * The assertion acts as a declaration that can be placed at file scope, in a
<> 151:5eaa88a5bcc7 78 * code block (except after a label), or as a member of a C++ class/struct/union.
<> 151:5eaa88a5bcc7 79 *
<> 151:5eaa88a5bcc7 80 * @note
<> 151:5eaa88a5bcc7 81 * Use of MBED_STATIC_ASSERT as a member of a struct/union is limited:
<> 151:5eaa88a5bcc7 82 * - In C++, MBED_STATIC_ASSERT is valid in class/struct/union scope.
<> 151:5eaa88a5bcc7 83 * - In C, MBED_STATIC_ASSERT is not valid in struct/union scope, and
<> 151:5eaa88a5bcc7 84 * MBED_STRUCT_STATIC_ASSERT is provided as an alternative that is valid
<> 151:5eaa88a5bcc7 85 * in C and C++ class/struct/union scope.
<> 151:5eaa88a5bcc7 86 *
<> 151:5eaa88a5bcc7 87 * @code
<> 151:5eaa88a5bcc7 88 * MBED_STATIC_ASSERT(MBED_LIBRARY_VERSION >= 120,
<> 151:5eaa88a5bcc7 89 * "The mbed library must be at least version 120");
<> 151:5eaa88a5bcc7 90 *
<> 151:5eaa88a5bcc7 91 * int main() {
<> 151:5eaa88a5bcc7 92 * MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
<> 151:5eaa88a5bcc7 93 * "An int must be larger than a char");
<> 151:5eaa88a5bcc7 94 * }
<> 151:5eaa88a5bcc7 95 * @endcode
<> 151:5eaa88a5bcc7 96 */
<> 151:5eaa88a5bcc7 97 #if defined(__cplusplus) && (__cplusplus >= 201103L || __cpp_static_assert >= 200410L)
<> 151:5eaa88a5bcc7 98 #define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
<> 151:5eaa88a5bcc7 99 #elif !defined(__cplusplus) && __STDC_VERSION__ >= 201112L
<> 151:5eaa88a5bcc7 100 #define MBED_STATIC_ASSERT(expr, msg) _Static_assert(expr, msg)
<> 151:5eaa88a5bcc7 101 #elif defined(__cplusplus) && defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) \
<> 151:5eaa88a5bcc7 102 && (__GNUC__*100 + __GNUC_MINOR__) > 403L
<> 151:5eaa88a5bcc7 103 #define MBED_STATIC_ASSERT(expr, msg) __extension__ static_assert(expr, msg)
<> 151:5eaa88a5bcc7 104 #elif !defined(__cplusplus) && defined(__GNUC__) && !defined(__CC_ARM) \
<> 151:5eaa88a5bcc7 105 && (__GNUC__*100 + __GNUC_MINOR__) > 406L
<> 151:5eaa88a5bcc7 106 #define MBED_STATIC_ASSERT(expr, msg) __extension__ _Static_assert(expr, msg)
<> 151:5eaa88a5bcc7 107 #elif defined(__ICCARM__)
<> 151:5eaa88a5bcc7 108 #define MBED_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
<> 151:5eaa88a5bcc7 109 #else
<> 151:5eaa88a5bcc7 110 #define MBED_STATIC_ASSERT(expr, msg) \
<> 151:5eaa88a5bcc7 111 enum {MBED_CONCAT(MBED_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])}
<> 151:5eaa88a5bcc7 112 #endif
<> 151:5eaa88a5bcc7 113
<> 151:5eaa88a5bcc7 114 /** MBED_STRUCT_STATIC_ASSERT
<> 151:5eaa88a5bcc7 115 * Declare compile-time assertions, results in compile-time error if condition is false
<> 151:5eaa88a5bcc7 116 *
<> 151:5eaa88a5bcc7 117 * Unlike MBED_STATIC_ASSERT, MBED_STRUCT_STATIC_ASSERT can and must be used
<> 151:5eaa88a5bcc7 118 * as a member of a C/C++ class/struct/union.
<> 151:5eaa88a5bcc7 119 *
<> 151:5eaa88a5bcc7 120 * @code
<> 151:5eaa88a5bcc7 121 * struct thing {
<> 151:5eaa88a5bcc7 122 * MBED_STATIC_ASSERT(2 + 2 == 4,
<> 151:5eaa88a5bcc7 123 * "Hopefully the universe is mathematically consistent");
<> 151:5eaa88a5bcc7 124 * };
<> 151:5eaa88a5bcc7 125 * @endcode
<> 151:5eaa88a5bcc7 126 */
<> 151:5eaa88a5bcc7 127 #define MBED_STRUCT_STATIC_ASSERT(expr, msg) int : (expr) ? 0 : -1
<> 151:5eaa88a5bcc7 128
<> 151:5eaa88a5bcc7 129
<> 149:156823d33999 130 #endif
<> 149:156823d33999 131
AnnaBridge 178:79309dc6340a 132 /**@}*/
AnnaBridge 178:79309dc6340a 133
AnnaBridge 178:79309dc6340a 134 /**@}*/
AnnaBridge 178:79309dc6340a 135