Forked.

Fork of mbed-dev by mbed official

Committer:
Kojto
Date:
Wed Jul 19 17:31:21 2017 +0100
Revision:
169:e3b6fe271b81
Parent:
167:e84263d55307
Child:
170:19eb464bc2be
This updates the lib to the mbed lib v 147

Who changed what in which revision?

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