The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
158:1c57384330a6
Child:
171:3a7713b1edbc
mbed library. Release version 162

Who changed what in which revision?

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