The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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