mbed library sources. Supersedes mbed-src. removed serial

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Thu Nov 24 17:03:03 2016 +0000
Revision:
151:5eaa88a5bcc7
Parent:
149:156823d33999
This updates the lib to the mbed lib v130

Who changed what in which revision?

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