,,
Fork of Application by
mbed-dev/platform/toolchain.h@10:41552d038a69, 2017-01-10 (annotated)
- Committer:
- Zaitsev
- Date:
- Tue Jan 10 20:42:26 2017 +0000
- Revision:
- 10:41552d038a69
USB Serial bi-directional bridge
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Zaitsev | 10:41552d038a69 | 1 | |
Zaitsev | 10:41552d038a69 | 2 | /** \addtogroup platform */ |
Zaitsev | 10:41552d038a69 | 3 | /** @{*/ |
Zaitsev | 10:41552d038a69 | 4 | /* mbed Microcontroller Library |
Zaitsev | 10:41552d038a69 | 5 | * Copyright (c) 2006-2013 ARM Limited |
Zaitsev | 10:41552d038a69 | 6 | * |
Zaitsev | 10:41552d038a69 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Zaitsev | 10:41552d038a69 | 8 | * you may not use this file except in compliance with the License. |
Zaitsev | 10:41552d038a69 | 9 | * You may obtain a copy of the License at |
Zaitsev | 10:41552d038a69 | 10 | * |
Zaitsev | 10:41552d038a69 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Zaitsev | 10:41552d038a69 | 12 | * |
Zaitsev | 10:41552d038a69 | 13 | * Unless required by applicable law or agreed to in writing, software |
Zaitsev | 10:41552d038a69 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
Zaitsev | 10:41552d038a69 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Zaitsev | 10:41552d038a69 | 16 | * See the License for the specific language governing permissions and |
Zaitsev | 10:41552d038a69 | 17 | * limitations under the License. |
Zaitsev | 10:41552d038a69 | 18 | */ |
Zaitsev | 10:41552d038a69 | 19 | #ifndef MBED_TOOLCHAIN_H |
Zaitsev | 10:41552d038a69 | 20 | #define MBED_TOOLCHAIN_H |
Zaitsev | 10:41552d038a69 | 21 | |
Zaitsev | 10:41552d038a69 | 22 | #include "mbed_preprocessor.h" |
Zaitsev | 10:41552d038a69 | 23 | |
Zaitsev | 10:41552d038a69 | 24 | |
Zaitsev | 10:41552d038a69 | 25 | // Warning for unsupported compilers |
Zaitsev | 10:41552d038a69 | 26 | #if !defined(__GNUC__) /* GCC */ \ |
Zaitsev | 10:41552d038a69 | 27 | && !defined(__CC_ARM) /* ARMCC */ \ |
Zaitsev | 10:41552d038a69 | 28 | && !defined(__clang__) /* LLVM/Clang */ \ |
Zaitsev | 10:41552d038a69 | 29 | && !defined(__ICCARM__) /* IAR */ |
Zaitsev | 10:41552d038a69 | 30 | #warning "This compiler is not yet supported." |
Zaitsev | 10:41552d038a69 | 31 | #endif |
Zaitsev | 10:41552d038a69 | 32 | |
Zaitsev | 10:41552d038a69 | 33 | |
Zaitsev | 10:41552d038a69 | 34 | // Attributes |
Zaitsev | 10:41552d038a69 | 35 | |
Zaitsev | 10:41552d038a69 | 36 | /** MBED_PACKED |
Zaitsev | 10:41552d038a69 | 37 | * Pack a structure, preventing any padding from being added between fields. |
Zaitsev | 10:41552d038a69 | 38 | * |
Zaitsev | 10:41552d038a69 | 39 | * @code |
Zaitsev | 10:41552d038a69 | 40 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 41 | * |
Zaitsev | 10:41552d038a69 | 42 | * MBED_PACKED(struct) foo { |
Zaitsev | 10:41552d038a69 | 43 | * char x; |
Zaitsev | 10:41552d038a69 | 44 | * int y; |
Zaitsev | 10:41552d038a69 | 45 | * }; |
Zaitsev | 10:41552d038a69 | 46 | * @endcode |
Zaitsev | 10:41552d038a69 | 47 | */ |
Zaitsev | 10:41552d038a69 | 48 | #ifndef MBED_PACKED |
Zaitsev | 10:41552d038a69 | 49 | #if defined(__ICCARM__) |
Zaitsev | 10:41552d038a69 | 50 | #define MBED_PACKED(struct) __packed struct |
Zaitsev | 10:41552d038a69 | 51 | #else |
Zaitsev | 10:41552d038a69 | 52 | #define MBED_PACKED(struct) struct __attribute__((packed)) |
Zaitsev | 10:41552d038a69 | 53 | #endif |
Zaitsev | 10:41552d038a69 | 54 | #endif |
Zaitsev | 10:41552d038a69 | 55 | |
Zaitsev | 10:41552d038a69 | 56 | /** MBED_ALIGN(N) |
Zaitsev | 10:41552d038a69 | 57 | * Declare a variable to be aligned on an N-byte boundary. |
Zaitsev | 10:41552d038a69 | 58 | * |
Zaitsev | 10:41552d038a69 | 59 | * @note |
Zaitsev | 10:41552d038a69 | 60 | * IAR does not support alignment greater than word size on the stack |
Zaitsev | 10:41552d038a69 | 61 | * |
Zaitsev | 10:41552d038a69 | 62 | * @code |
Zaitsev | 10:41552d038a69 | 63 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 64 | * |
Zaitsev | 10:41552d038a69 | 65 | * MBED_ALIGN(16) char a; |
Zaitsev | 10:41552d038a69 | 66 | * @endcode |
Zaitsev | 10:41552d038a69 | 67 | */ |
Zaitsev | 10:41552d038a69 | 68 | #ifndef MBED_ALIGN |
Zaitsev | 10:41552d038a69 | 69 | #if defined(__ICCARM__) |
Zaitsev | 10:41552d038a69 | 70 | #define MBED_ALIGN(N) _Pragma(MBED_STRINGIFY(data_alignment=N)) |
Zaitsev | 10:41552d038a69 | 71 | #else |
Zaitsev | 10:41552d038a69 | 72 | #define MBED_ALIGN(N) __attribute__((aligned(N))) |
Zaitsev | 10:41552d038a69 | 73 | #endif |
Zaitsev | 10:41552d038a69 | 74 | #endif |
Zaitsev | 10:41552d038a69 | 75 | |
Zaitsev | 10:41552d038a69 | 76 | /** MBED_UNUSED |
Zaitsev | 10:41552d038a69 | 77 | * Declare a function argument to be unused, suppressing compiler warnings |
Zaitsev | 10:41552d038a69 | 78 | * |
Zaitsev | 10:41552d038a69 | 79 | * @code |
Zaitsev | 10:41552d038a69 | 80 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 81 | * |
Zaitsev | 10:41552d038a69 | 82 | * void foo(MBED_UNUSED int arg) { |
Zaitsev | 10:41552d038a69 | 83 | * |
Zaitsev | 10:41552d038a69 | 84 | * } |
Zaitsev | 10:41552d038a69 | 85 | * @endcode |
Zaitsev | 10:41552d038a69 | 86 | */ |
Zaitsev | 10:41552d038a69 | 87 | #ifndef MBED_UNUSED |
Zaitsev | 10:41552d038a69 | 88 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 89 | #define MBED_UNUSED __attribute__((__unused__)) |
Zaitsev | 10:41552d038a69 | 90 | #else |
Zaitsev | 10:41552d038a69 | 91 | #define MBED_UNUSED |
Zaitsev | 10:41552d038a69 | 92 | #endif |
Zaitsev | 10:41552d038a69 | 93 | #endif |
Zaitsev | 10:41552d038a69 | 94 | |
Zaitsev | 10:41552d038a69 | 95 | /** MBED_WEAK |
Zaitsev | 10:41552d038a69 | 96 | * Mark a function as being weak. |
Zaitsev | 10:41552d038a69 | 97 | * |
Zaitsev | 10:41552d038a69 | 98 | * @note |
Zaitsev | 10:41552d038a69 | 99 | * weak functions are not friendly to making code re-usable, as they can only |
Zaitsev | 10:41552d038a69 | 100 | * be overridden once (and if they are multiply overridden the linker will emit |
Zaitsev | 10:41552d038a69 | 101 | * no warning). You should not normally use weak symbols as part of the API to |
Zaitsev | 10:41552d038a69 | 102 | * re-usable modules. |
Zaitsev | 10:41552d038a69 | 103 | * |
Zaitsev | 10:41552d038a69 | 104 | * @code |
Zaitsev | 10:41552d038a69 | 105 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 106 | * |
Zaitsev | 10:41552d038a69 | 107 | * MBED_WEAK void foo() { |
Zaitsev | 10:41552d038a69 | 108 | * // a weak implementation of foo that can be overriden by a definition |
Zaitsev | 10:41552d038a69 | 109 | * // without __weak |
Zaitsev | 10:41552d038a69 | 110 | * } |
Zaitsev | 10:41552d038a69 | 111 | * @endcode |
Zaitsev | 10:41552d038a69 | 112 | */ |
Zaitsev | 10:41552d038a69 | 113 | #ifndef MBED_WEAK |
Zaitsev | 10:41552d038a69 | 114 | #if defined(__ICCARM__) |
Zaitsev | 10:41552d038a69 | 115 | #define MBED_WEAK __weak |
Zaitsev | 10:41552d038a69 | 116 | #else |
Zaitsev | 10:41552d038a69 | 117 | #define MBED_WEAK __attribute__((weak)) |
Zaitsev | 10:41552d038a69 | 118 | #endif |
Zaitsev | 10:41552d038a69 | 119 | #endif |
Zaitsev | 10:41552d038a69 | 120 | |
Zaitsev | 10:41552d038a69 | 121 | /** MBED_PURE |
Zaitsev | 10:41552d038a69 | 122 | * Hint to the compiler that a function depends only on parameters |
Zaitsev | 10:41552d038a69 | 123 | * |
Zaitsev | 10:41552d038a69 | 124 | * @code |
Zaitsev | 10:41552d038a69 | 125 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 126 | * |
Zaitsev | 10:41552d038a69 | 127 | * MBED_PURE int foo(int arg){ |
Zaitsev | 10:41552d038a69 | 128 | * // no access to global variables |
Zaitsev | 10:41552d038a69 | 129 | * } |
Zaitsev | 10:41552d038a69 | 130 | * @endcode |
Zaitsev | 10:41552d038a69 | 131 | */ |
Zaitsev | 10:41552d038a69 | 132 | #ifndef MBED_PURE |
Zaitsev | 10:41552d038a69 | 133 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 134 | #define MBED_PURE __attribute__((const)) |
Zaitsev | 10:41552d038a69 | 135 | #else |
Zaitsev | 10:41552d038a69 | 136 | #define MBED_PURE |
Zaitsev | 10:41552d038a69 | 137 | #endif |
Zaitsev | 10:41552d038a69 | 138 | #endif |
Zaitsev | 10:41552d038a69 | 139 | |
Zaitsev | 10:41552d038a69 | 140 | /** MBED_FORCEINLINE |
Zaitsev | 10:41552d038a69 | 141 | * Declare a function that must always be inlined. Failure to inline |
Zaitsev | 10:41552d038a69 | 142 | * such a function will result in an error. |
Zaitsev | 10:41552d038a69 | 143 | * |
Zaitsev | 10:41552d038a69 | 144 | * @code |
Zaitsev | 10:41552d038a69 | 145 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 146 | * |
Zaitsev | 10:41552d038a69 | 147 | * MBED_FORCEINLINE void foo() { |
Zaitsev | 10:41552d038a69 | 148 | * |
Zaitsev | 10:41552d038a69 | 149 | * } |
Zaitsev | 10:41552d038a69 | 150 | * @endcode |
Zaitsev | 10:41552d038a69 | 151 | */ |
Zaitsev | 10:41552d038a69 | 152 | #ifndef MBED_FORCEINLINE |
Zaitsev | 10:41552d038a69 | 153 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 154 | #define MBED_FORCEINLINE static inline __attribute__((always_inline)) |
Zaitsev | 10:41552d038a69 | 155 | #elif defined(__ICCARM__) |
Zaitsev | 10:41552d038a69 | 156 | #define MBED_FORCEINLINE _Pragma("inline=forced") static |
Zaitsev | 10:41552d038a69 | 157 | #else |
Zaitsev | 10:41552d038a69 | 158 | #define MBED_FORCEINLINE static inline |
Zaitsev | 10:41552d038a69 | 159 | #endif |
Zaitsev | 10:41552d038a69 | 160 | #endif |
Zaitsev | 10:41552d038a69 | 161 | |
Zaitsev | 10:41552d038a69 | 162 | /** MBED_NORETURN |
Zaitsev | 10:41552d038a69 | 163 | * Declare a function that will never return. |
Zaitsev | 10:41552d038a69 | 164 | * |
Zaitsev | 10:41552d038a69 | 165 | * @code |
Zaitsev | 10:41552d038a69 | 166 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 167 | * |
Zaitsev | 10:41552d038a69 | 168 | * MBED_NORETURN void foo() { |
Zaitsev | 10:41552d038a69 | 169 | * // must never return |
Zaitsev | 10:41552d038a69 | 170 | * while (1) {} |
Zaitsev | 10:41552d038a69 | 171 | * } |
Zaitsev | 10:41552d038a69 | 172 | * @endcode |
Zaitsev | 10:41552d038a69 | 173 | */ |
Zaitsev | 10:41552d038a69 | 174 | #ifndef MBED_NORETURN |
Zaitsev | 10:41552d038a69 | 175 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 176 | #define MBED_NORETURN __attribute__((noreturn)) |
Zaitsev | 10:41552d038a69 | 177 | #elif defined(__ICCARM__) |
Zaitsev | 10:41552d038a69 | 178 | #define MBED_NORETURN __noreturn |
Zaitsev | 10:41552d038a69 | 179 | #else |
Zaitsev | 10:41552d038a69 | 180 | #define MBED_NORETURN |
Zaitsev | 10:41552d038a69 | 181 | #endif |
Zaitsev | 10:41552d038a69 | 182 | #endif |
Zaitsev | 10:41552d038a69 | 183 | |
Zaitsev | 10:41552d038a69 | 184 | /** MBED_UNREACHABLE |
Zaitsev | 10:41552d038a69 | 185 | * An unreachable statement. If the statement is reached, |
Zaitsev | 10:41552d038a69 | 186 | * behaviour is undefined. Useful in situations where the compiler |
Zaitsev | 10:41552d038a69 | 187 | * cannot deduce the unreachability of code. |
Zaitsev | 10:41552d038a69 | 188 | * |
Zaitsev | 10:41552d038a69 | 189 | * @code |
Zaitsev | 10:41552d038a69 | 190 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 191 | * |
Zaitsev | 10:41552d038a69 | 192 | * void foo(int arg) { |
Zaitsev | 10:41552d038a69 | 193 | * switch (arg) { |
Zaitsev | 10:41552d038a69 | 194 | * case 1: return 1; |
Zaitsev | 10:41552d038a69 | 195 | * case 2: return 2; |
Zaitsev | 10:41552d038a69 | 196 | * ... |
Zaitsev | 10:41552d038a69 | 197 | * } |
Zaitsev | 10:41552d038a69 | 198 | * MBED_UNREACHABLE; |
Zaitsev | 10:41552d038a69 | 199 | * } |
Zaitsev | 10:41552d038a69 | 200 | * @endcode |
Zaitsev | 10:41552d038a69 | 201 | */ |
Zaitsev | 10:41552d038a69 | 202 | #ifndef MBED_UNREACHABLE |
Zaitsev | 10:41552d038a69 | 203 | #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 204 | #define MBED_UNREACHABLE __builtin_unreachable() |
Zaitsev | 10:41552d038a69 | 205 | #else |
Zaitsev | 10:41552d038a69 | 206 | #define MBED_UNREACHABLE while (1) |
Zaitsev | 10:41552d038a69 | 207 | #endif |
Zaitsev | 10:41552d038a69 | 208 | #endif |
Zaitsev | 10:41552d038a69 | 209 | |
Zaitsev | 10:41552d038a69 | 210 | /** MBED_DEPRECATED("message string") |
Zaitsev | 10:41552d038a69 | 211 | * Mark a function declaration as deprecated, if it used then a warning will be |
Zaitsev | 10:41552d038a69 | 212 | * issued by the compiler possibly including the provided message. Note that not |
Zaitsev | 10:41552d038a69 | 213 | * all compilers are able to display the message. |
Zaitsev | 10:41552d038a69 | 214 | * |
Zaitsev | 10:41552d038a69 | 215 | * @code |
Zaitsev | 10:41552d038a69 | 216 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 217 | * |
Zaitsev | 10:41552d038a69 | 218 | * MBED_DEPRECATED("don't foo any more, bar instead") |
Zaitsev | 10:41552d038a69 | 219 | * void foo(int arg); |
Zaitsev | 10:41552d038a69 | 220 | * @endcode |
Zaitsev | 10:41552d038a69 | 221 | */ |
Zaitsev | 10:41552d038a69 | 222 | #ifndef MBED_DEPRECATED |
Zaitsev | 10:41552d038a69 | 223 | #if defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 224 | #define MBED_DEPRECATED(M) __attribute__((deprecated)) |
Zaitsev | 10:41552d038a69 | 225 | #elif defined(__GNUC__) || defined(__clang__) |
Zaitsev | 10:41552d038a69 | 226 | #define MBED_DEPRECATED(M) __attribute__((deprecated(M))) |
Zaitsev | 10:41552d038a69 | 227 | #else |
Zaitsev | 10:41552d038a69 | 228 | #define MBED_DEPRECATED(M) |
Zaitsev | 10:41552d038a69 | 229 | #endif |
Zaitsev | 10:41552d038a69 | 230 | #endif |
Zaitsev | 10:41552d038a69 | 231 | |
Zaitsev | 10:41552d038a69 | 232 | /** MBED_DEPRECATED_SINCE("version", "message string") |
Zaitsev | 10:41552d038a69 | 233 | * Mark a function declaration as deprecated, noting that the declaration was |
Zaitsev | 10:41552d038a69 | 234 | * deprecated on the specified version. If the function is used then a warning |
Zaitsev | 10:41552d038a69 | 235 | * will be issued by the compiler possibly including the provided message. |
Zaitsev | 10:41552d038a69 | 236 | * Note that not all compilers are able to display this message. |
Zaitsev | 10:41552d038a69 | 237 | * |
Zaitsev | 10:41552d038a69 | 238 | * @code |
Zaitsev | 10:41552d038a69 | 239 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 240 | * |
Zaitsev | 10:41552d038a69 | 241 | * MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead") |
Zaitsev | 10:41552d038a69 | 242 | * void foo(int arg); |
Zaitsev | 10:41552d038a69 | 243 | * @endcode |
Zaitsev | 10:41552d038a69 | 244 | */ |
Zaitsev | 10:41552d038a69 | 245 | #define MBED_DEPRECATED_SINCE(D, M) MBED_DEPRECATED(M " [since " D "]") |
Zaitsev | 10:41552d038a69 | 246 | |
Zaitsev | 10:41552d038a69 | 247 | /** MBED_CALLER_ADDR() |
Zaitsev | 10:41552d038a69 | 248 | * Returns the caller of the current function. |
Zaitsev | 10:41552d038a69 | 249 | * |
Zaitsev | 10:41552d038a69 | 250 | * @note |
Zaitsev | 10:41552d038a69 | 251 | * This macro is only implemented for GCC and ARMCC. |
Zaitsev | 10:41552d038a69 | 252 | * |
Zaitsev | 10:41552d038a69 | 253 | * @code |
Zaitsev | 10:41552d038a69 | 254 | * #include "toolchain.h" |
Zaitsev | 10:41552d038a69 | 255 | * |
Zaitsev | 10:41552d038a69 | 256 | * printf("This function was called from %p", MBED_CALLER_ADDR()); |
Zaitsev | 10:41552d038a69 | 257 | * @endcode |
Zaitsev | 10:41552d038a69 | 258 | * |
Zaitsev | 10:41552d038a69 | 259 | * @return Address of the calling function |
Zaitsev | 10:41552d038a69 | 260 | */ |
Zaitsev | 10:41552d038a69 | 261 | #ifndef MBED_CALLER_ADDR |
Zaitsev | 10:41552d038a69 | 262 | #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 263 | #define MBED_CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0)) |
Zaitsev | 10:41552d038a69 | 264 | #elif defined(__CC_ARM) |
Zaitsev | 10:41552d038a69 | 265 | #define MBED_CALLER_ADDR() __builtin_return_address(0) |
Zaitsev | 10:41552d038a69 | 266 | #else |
Zaitsev | 10:41552d038a69 | 267 | #define MBED_CALLER_ADDR() (NULL) |
Zaitsev | 10:41552d038a69 | 268 | #endif |
Zaitsev | 10:41552d038a69 | 269 | #endif |
Zaitsev | 10:41552d038a69 | 270 | |
Zaitsev | 10:41552d038a69 | 271 | // FILEHANDLE declaration |
Zaitsev | 10:41552d038a69 | 272 | #if defined(TOOLCHAIN_ARM) |
Zaitsev | 10:41552d038a69 | 273 | #include <rt_sys.h> |
Zaitsev | 10:41552d038a69 | 274 | #endif |
Zaitsev | 10:41552d038a69 | 275 | |
Zaitsev | 10:41552d038a69 | 276 | #ifndef FILEHANDLE |
Zaitsev | 10:41552d038a69 | 277 | typedef int FILEHANDLE; |
Zaitsev | 10:41552d038a69 | 278 | #endif |
Zaitsev | 10:41552d038a69 | 279 | |
Zaitsev | 10:41552d038a69 | 280 | // Backwards compatibility |
Zaitsev | 10:41552d038a69 | 281 | #ifndef WEAK |
Zaitsev | 10:41552d038a69 | 282 | #define WEAK MBED_WEAK |
Zaitsev | 10:41552d038a69 | 283 | #endif |
Zaitsev | 10:41552d038a69 | 284 | |
Zaitsev | 10:41552d038a69 | 285 | #ifndef PACKED |
Zaitsev | 10:41552d038a69 | 286 | #define PACKED MBED_PACKED() |
Zaitsev | 10:41552d038a69 | 287 | #endif |
Zaitsev | 10:41552d038a69 | 288 | |
Zaitsev | 10:41552d038a69 | 289 | #ifndef EXTERN |
Zaitsev | 10:41552d038a69 | 290 | #define EXTERN extern |
Zaitsev | 10:41552d038a69 | 291 | #endif |
Zaitsev | 10:41552d038a69 | 292 | |
Zaitsev | 10:41552d038a69 | 293 | #endif |
Zaitsev | 10:41552d038a69 | 294 | |
Zaitsev | 10:41552d038a69 | 295 | /** @}*/ |