Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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