Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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