mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 16 16:24:25 2016 +0100
Revision:
147:30b64687e01f
Parent:
144:ef7eb2e8f9f7
This updates the lib to the mbed lib v126

Who changed what in which revision?

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