Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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