Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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