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