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