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