RTC auf true
platform/mbed_toolchain.h@0:38ceb79fef03, 2018-11-28 (annotated)
- Committer:
- kevman
- Date:
- Wed Nov 28 15:10:15 2018 +0000
- Revision:
- 0:38ceb79fef03
RTC modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | |
kevman | 0:38ceb79fef03 | 2 | /** \addtogroup platform */ |
kevman | 0:38ceb79fef03 | 3 | /** @{*/ |
kevman | 0:38ceb79fef03 | 4 | /** |
kevman | 0:38ceb79fef03 | 5 | * \defgroup platform_toolchain Toolchain functions |
kevman | 0:38ceb79fef03 | 6 | * @{ |
kevman | 0:38ceb79fef03 | 7 | */ |
kevman | 0:38ceb79fef03 | 8 | |
kevman | 0:38ceb79fef03 | 9 | /* mbed Microcontroller Library |
kevman | 0:38ceb79fef03 | 10 | * Copyright (c) 2006-2013 ARM Limited |
kevman | 0:38ceb79fef03 | 11 | * |
kevman | 0:38ceb79fef03 | 12 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 13 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 14 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 15 | * |
kevman | 0:38ceb79fef03 | 16 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 17 | * |
kevman | 0:38ceb79fef03 | 18 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 19 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 21 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 22 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 23 | */ |
kevman | 0:38ceb79fef03 | 24 | #ifndef MBED_TOOLCHAIN_H |
kevman | 0:38ceb79fef03 | 25 | #define MBED_TOOLCHAIN_H |
kevman | 0:38ceb79fef03 | 26 | |
kevman | 0:38ceb79fef03 | 27 | #include "mbed_preprocessor.h" |
kevman | 0:38ceb79fef03 | 28 | |
kevman | 0:38ceb79fef03 | 29 | |
kevman | 0:38ceb79fef03 | 30 | // Warning for unsupported compilers |
kevman | 0:38ceb79fef03 | 31 | #if !defined(__GNUC__) /* GCC */ \ |
kevman | 0:38ceb79fef03 | 32 | && !defined(__CC_ARM) /* ARMCC */ \ |
kevman | 0:38ceb79fef03 | 33 | && !defined(__clang__) /* LLVM/Clang */ \ |
kevman | 0:38ceb79fef03 | 34 | && !defined(__ICCARM__) /* IAR */ |
kevman | 0:38ceb79fef03 | 35 | #warning "This compiler is not yet supported." |
kevman | 0:38ceb79fef03 | 36 | #endif |
kevman | 0:38ceb79fef03 | 37 | |
kevman | 0:38ceb79fef03 | 38 | |
kevman | 0:38ceb79fef03 | 39 | // Attributes |
kevman | 0:38ceb79fef03 | 40 | |
kevman | 0:38ceb79fef03 | 41 | /** MBED_PACKED |
kevman | 0:38ceb79fef03 | 42 | * Pack a structure, preventing any padding from being added between fields. |
kevman | 0:38ceb79fef03 | 43 | * |
kevman | 0:38ceb79fef03 | 44 | * @code |
kevman | 0:38ceb79fef03 | 45 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 46 | * |
kevman | 0:38ceb79fef03 | 47 | * MBED_PACKED(struct) foo { |
kevman | 0:38ceb79fef03 | 48 | * char x; |
kevman | 0:38ceb79fef03 | 49 | * int y; |
kevman | 0:38ceb79fef03 | 50 | * }; |
kevman | 0:38ceb79fef03 | 51 | * @endcode |
kevman | 0:38ceb79fef03 | 52 | */ |
kevman | 0:38ceb79fef03 | 53 | #ifndef MBED_PACKED |
kevman | 0:38ceb79fef03 | 54 | #if defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 55 | #define MBED_PACKED(struct) __packed struct |
kevman | 0:38ceb79fef03 | 56 | #else |
kevman | 0:38ceb79fef03 | 57 | #define MBED_PACKED(struct) struct __attribute__((packed)) |
kevman | 0:38ceb79fef03 | 58 | #endif |
kevman | 0:38ceb79fef03 | 59 | #endif |
kevman | 0:38ceb79fef03 | 60 | |
kevman | 0:38ceb79fef03 | 61 | /** MBED_ALIGN(N) |
kevman | 0:38ceb79fef03 | 62 | * Declare a variable to be aligned on an N-byte boundary. |
kevman | 0:38ceb79fef03 | 63 | * |
kevman | 0:38ceb79fef03 | 64 | * @note |
kevman | 0:38ceb79fef03 | 65 | * IAR does not support alignment greater than word size on the stack |
kevman | 0:38ceb79fef03 | 66 | * |
kevman | 0:38ceb79fef03 | 67 | * @code |
kevman | 0:38ceb79fef03 | 68 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 69 | * |
kevman | 0:38ceb79fef03 | 70 | * MBED_ALIGN(16) char a; |
kevman | 0:38ceb79fef03 | 71 | * @endcode |
kevman | 0:38ceb79fef03 | 72 | */ |
kevman | 0:38ceb79fef03 | 73 | #ifndef MBED_ALIGN |
kevman | 0:38ceb79fef03 | 74 | #if defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 75 | #define MBED_ALIGN(N) _Pragma(MBED_STRINGIFY(data_alignment=N)) |
kevman | 0:38ceb79fef03 | 76 | #else |
kevman | 0:38ceb79fef03 | 77 | #define MBED_ALIGN(N) __attribute__((aligned(N))) |
kevman | 0:38ceb79fef03 | 78 | #endif |
kevman | 0:38ceb79fef03 | 79 | #endif |
kevman | 0:38ceb79fef03 | 80 | |
kevman | 0:38ceb79fef03 | 81 | /** MBED_UNUSED |
kevman | 0:38ceb79fef03 | 82 | * Declare a function argument to be unused, suppressing compiler warnings |
kevman | 0:38ceb79fef03 | 83 | * |
kevman | 0:38ceb79fef03 | 84 | * @code |
kevman | 0:38ceb79fef03 | 85 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 86 | * |
kevman | 0:38ceb79fef03 | 87 | * void foo(MBED_UNUSED int arg) { |
kevman | 0:38ceb79fef03 | 88 | * |
kevman | 0:38ceb79fef03 | 89 | * } |
kevman | 0:38ceb79fef03 | 90 | * @endcode |
kevman | 0:38ceb79fef03 | 91 | */ |
kevman | 0:38ceb79fef03 | 92 | #ifndef MBED_UNUSED |
kevman | 0:38ceb79fef03 | 93 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 94 | #define MBED_UNUSED __attribute__((__unused__)) |
kevman | 0:38ceb79fef03 | 95 | #else |
kevman | 0:38ceb79fef03 | 96 | #define MBED_UNUSED |
kevman | 0:38ceb79fef03 | 97 | #endif |
kevman | 0:38ceb79fef03 | 98 | #endif |
kevman | 0:38ceb79fef03 | 99 | |
kevman | 0:38ceb79fef03 | 100 | /** MBED_USED |
kevman | 0:38ceb79fef03 | 101 | * Inform the compiler that a static variable is to be retained in the object file, even if it is unreferenced. |
kevman | 0:38ceb79fef03 | 102 | * |
kevman | 0:38ceb79fef03 | 103 | * @code |
kevman | 0:38ceb79fef03 | 104 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 105 | * |
kevman | 0:38ceb79fef03 | 106 | * MBED_USED int foo; |
kevman | 0:38ceb79fef03 | 107 | * |
kevman | 0:38ceb79fef03 | 108 | * @endcode |
kevman | 0:38ceb79fef03 | 109 | */ |
kevman | 0:38ceb79fef03 | 110 | #ifndef MBED_USED |
kevman | 0:38ceb79fef03 | 111 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 112 | #define MBED_USED __attribute__((used)) |
kevman | 0:38ceb79fef03 | 113 | #elif defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 114 | #define MBED_USED __root |
kevman | 0:38ceb79fef03 | 115 | #else |
kevman | 0:38ceb79fef03 | 116 | #define MBED_USED |
kevman | 0:38ceb79fef03 | 117 | #endif |
kevman | 0:38ceb79fef03 | 118 | #endif |
kevman | 0:38ceb79fef03 | 119 | |
kevman | 0:38ceb79fef03 | 120 | /** MBED_WEAK |
kevman | 0:38ceb79fef03 | 121 | * Mark a function as being weak. |
kevman | 0:38ceb79fef03 | 122 | * |
kevman | 0:38ceb79fef03 | 123 | * @note |
kevman | 0:38ceb79fef03 | 124 | * Functions should only be marked as weak in the source file. The header file |
kevman | 0:38ceb79fef03 | 125 | * should contain a regular function declaration to insure the function is emitted. |
kevman | 0:38ceb79fef03 | 126 | * A function marked weak will not be emitted if an alternative non-weak |
kevman | 0:38ceb79fef03 | 127 | * implementation is defined. |
kevman | 0:38ceb79fef03 | 128 | * |
kevman | 0:38ceb79fef03 | 129 | * @note |
kevman | 0:38ceb79fef03 | 130 | * Weak functions are not friendly to making code re-usable, as they can only |
kevman | 0:38ceb79fef03 | 131 | * be overridden once (and if they are multiply overridden the linker will emit |
kevman | 0:38ceb79fef03 | 132 | * no warning). You should not normally use weak symbols as part of the API to |
kevman | 0:38ceb79fef03 | 133 | * re-usable modules. |
kevman | 0:38ceb79fef03 | 134 | * |
kevman | 0:38ceb79fef03 | 135 | * @code |
kevman | 0:38ceb79fef03 | 136 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 137 | * |
kevman | 0:38ceb79fef03 | 138 | * MBED_WEAK void foo() { |
kevman | 0:38ceb79fef03 | 139 | * // a weak implementation of foo that can be overriden by a definition |
kevman | 0:38ceb79fef03 | 140 | * // without __weak |
kevman | 0:38ceb79fef03 | 141 | * } |
kevman | 0:38ceb79fef03 | 142 | * @endcode |
kevman | 0:38ceb79fef03 | 143 | */ |
kevman | 0:38ceb79fef03 | 144 | #ifndef MBED_WEAK |
kevman | 0:38ceb79fef03 | 145 | #if defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 146 | #define MBED_WEAK __weak |
kevman | 0:38ceb79fef03 | 147 | #elif defined(__MINGW32__) |
kevman | 0:38ceb79fef03 | 148 | #define MBED_WEAK |
kevman | 0:38ceb79fef03 | 149 | #else |
kevman | 0:38ceb79fef03 | 150 | #define MBED_WEAK __attribute__((weak)) |
kevman | 0:38ceb79fef03 | 151 | #endif |
kevman | 0:38ceb79fef03 | 152 | #endif |
kevman | 0:38ceb79fef03 | 153 | |
kevman | 0:38ceb79fef03 | 154 | /** MBED_PURE |
kevman | 0:38ceb79fef03 | 155 | * Hint to the compiler that a function depends only on parameters |
kevman | 0:38ceb79fef03 | 156 | * |
kevman | 0:38ceb79fef03 | 157 | * @code |
kevman | 0:38ceb79fef03 | 158 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 159 | * |
kevman | 0:38ceb79fef03 | 160 | * MBED_PURE int foo(int arg){ |
kevman | 0:38ceb79fef03 | 161 | * // no access to global variables |
kevman | 0:38ceb79fef03 | 162 | * } |
kevman | 0:38ceb79fef03 | 163 | * @endcode |
kevman | 0:38ceb79fef03 | 164 | */ |
kevman | 0:38ceb79fef03 | 165 | #ifndef MBED_PURE |
kevman | 0:38ceb79fef03 | 166 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 167 | #define MBED_PURE __attribute__((const)) |
kevman | 0:38ceb79fef03 | 168 | #else |
kevman | 0:38ceb79fef03 | 169 | #define MBED_PURE |
kevman | 0:38ceb79fef03 | 170 | #endif |
kevman | 0:38ceb79fef03 | 171 | #endif |
kevman | 0:38ceb79fef03 | 172 | |
kevman | 0:38ceb79fef03 | 173 | /** MBED_NOINLINE |
kevman | 0:38ceb79fef03 | 174 | * Declare a function that must not be inlined. |
kevman | 0:38ceb79fef03 | 175 | * |
kevman | 0:38ceb79fef03 | 176 | * @code |
kevman | 0:38ceb79fef03 | 177 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 178 | * |
kevman | 0:38ceb79fef03 | 179 | * MBED_NOINLINE void foo() { |
kevman | 0:38ceb79fef03 | 180 | * |
kevman | 0:38ceb79fef03 | 181 | * } |
kevman | 0:38ceb79fef03 | 182 | * @endcode |
kevman | 0:38ceb79fef03 | 183 | */ |
kevman | 0:38ceb79fef03 | 184 | #ifndef MBED_NOINLINE |
kevman | 0:38ceb79fef03 | 185 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 186 | #define MBED_NOINLINE __attribute__((noinline)) |
kevman | 0:38ceb79fef03 | 187 | #elif defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 188 | #define MBED_NOINLINE _Pragma("inline=never") |
kevman | 0:38ceb79fef03 | 189 | #else |
kevman | 0:38ceb79fef03 | 190 | #define MBED_NOINLINE |
kevman | 0:38ceb79fef03 | 191 | #endif |
kevman | 0:38ceb79fef03 | 192 | #endif |
kevman | 0:38ceb79fef03 | 193 | |
kevman | 0:38ceb79fef03 | 194 | /** MBED_FORCEINLINE |
kevman | 0:38ceb79fef03 | 195 | * Declare a function that must always be inlined. Failure to inline |
kevman | 0:38ceb79fef03 | 196 | * such a function will result in an error. |
kevman | 0:38ceb79fef03 | 197 | * |
kevman | 0:38ceb79fef03 | 198 | * @code |
kevman | 0:38ceb79fef03 | 199 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 200 | * |
kevman | 0:38ceb79fef03 | 201 | * MBED_FORCEINLINE void foo() { |
kevman | 0:38ceb79fef03 | 202 | * |
kevman | 0:38ceb79fef03 | 203 | * } |
kevman | 0:38ceb79fef03 | 204 | * @endcode |
kevman | 0:38ceb79fef03 | 205 | */ |
kevman | 0:38ceb79fef03 | 206 | #ifndef MBED_FORCEINLINE |
kevman | 0:38ceb79fef03 | 207 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 208 | #define MBED_FORCEINLINE static inline __attribute__((always_inline)) |
kevman | 0:38ceb79fef03 | 209 | #elif defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 210 | #define MBED_FORCEINLINE _Pragma("inline=forced") static |
kevman | 0:38ceb79fef03 | 211 | #else |
kevman | 0:38ceb79fef03 | 212 | #define MBED_FORCEINLINE static inline |
kevman | 0:38ceb79fef03 | 213 | #endif |
kevman | 0:38ceb79fef03 | 214 | #endif |
kevman | 0:38ceb79fef03 | 215 | |
kevman | 0:38ceb79fef03 | 216 | /** MBED_NORETURN |
kevman | 0:38ceb79fef03 | 217 | * Declare a function that will never return. |
kevman | 0:38ceb79fef03 | 218 | * |
kevman | 0:38ceb79fef03 | 219 | * @code |
kevman | 0:38ceb79fef03 | 220 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 221 | * |
kevman | 0:38ceb79fef03 | 222 | * MBED_NORETURN void foo() { |
kevman | 0:38ceb79fef03 | 223 | * // must never return |
kevman | 0:38ceb79fef03 | 224 | * while (1) {} |
kevman | 0:38ceb79fef03 | 225 | * } |
kevman | 0:38ceb79fef03 | 226 | * @endcode |
kevman | 0:38ceb79fef03 | 227 | */ |
kevman | 0:38ceb79fef03 | 228 | #ifndef MBED_NORETURN |
kevman | 0:38ceb79fef03 | 229 | #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 230 | #define MBED_NORETURN __attribute__((noreturn)) |
kevman | 0:38ceb79fef03 | 231 | #elif defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 232 | #define MBED_NORETURN __noreturn |
kevman | 0:38ceb79fef03 | 233 | #else |
kevman | 0:38ceb79fef03 | 234 | #define MBED_NORETURN |
kevman | 0:38ceb79fef03 | 235 | #endif |
kevman | 0:38ceb79fef03 | 236 | #endif |
kevman | 0:38ceb79fef03 | 237 | |
kevman | 0:38ceb79fef03 | 238 | /** MBED_UNREACHABLE |
kevman | 0:38ceb79fef03 | 239 | * An unreachable statement. If the statement is reached, |
kevman | 0:38ceb79fef03 | 240 | * behaviour is undefined. Useful in situations where the compiler |
kevman | 0:38ceb79fef03 | 241 | * cannot deduce the unreachability of code. |
kevman | 0:38ceb79fef03 | 242 | * |
kevman | 0:38ceb79fef03 | 243 | * @code |
kevman | 0:38ceb79fef03 | 244 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 245 | * |
kevman | 0:38ceb79fef03 | 246 | * void foo(int arg) { |
kevman | 0:38ceb79fef03 | 247 | * switch (arg) { |
kevman | 0:38ceb79fef03 | 248 | * case 1: return 1; |
kevman | 0:38ceb79fef03 | 249 | * case 2: return 2; |
kevman | 0:38ceb79fef03 | 250 | * ... |
kevman | 0:38ceb79fef03 | 251 | * } |
kevman | 0:38ceb79fef03 | 252 | * MBED_UNREACHABLE; |
kevman | 0:38ceb79fef03 | 253 | * } |
kevman | 0:38ceb79fef03 | 254 | * @endcode |
kevman | 0:38ceb79fef03 | 255 | */ |
kevman | 0:38ceb79fef03 | 256 | #ifndef MBED_UNREACHABLE |
kevman | 0:38ceb79fef03 | 257 | #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 258 | #define MBED_UNREACHABLE __builtin_unreachable() |
kevman | 0:38ceb79fef03 | 259 | #else |
kevman | 0:38ceb79fef03 | 260 | #define MBED_UNREACHABLE while (1) |
kevman | 0:38ceb79fef03 | 261 | #endif |
kevman | 0:38ceb79fef03 | 262 | #endif |
kevman | 0:38ceb79fef03 | 263 | |
kevman | 0:38ceb79fef03 | 264 | /** MBED_DEPRECATED("message string") |
kevman | 0:38ceb79fef03 | 265 | * Mark a function declaration as deprecated, if it used then a warning will be |
kevman | 0:38ceb79fef03 | 266 | * issued by the compiler possibly including the provided message. Note that not |
kevman | 0:38ceb79fef03 | 267 | * all compilers are able to display the message. |
kevman | 0:38ceb79fef03 | 268 | * |
kevman | 0:38ceb79fef03 | 269 | * @code |
kevman | 0:38ceb79fef03 | 270 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 271 | * |
kevman | 0:38ceb79fef03 | 272 | * MBED_DEPRECATED("don't foo any more, bar instead") |
kevman | 0:38ceb79fef03 | 273 | * void foo(int arg); |
kevman | 0:38ceb79fef03 | 274 | * @endcode |
kevman | 0:38ceb79fef03 | 275 | */ |
kevman | 0:38ceb79fef03 | 276 | #ifndef MBED_DEPRECATED |
kevman | 0:38ceb79fef03 | 277 | #if defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 278 | #define MBED_DEPRECATED(M) __attribute__((deprecated)) |
kevman | 0:38ceb79fef03 | 279 | #elif defined(__GNUC__) || defined(__clang__) |
kevman | 0:38ceb79fef03 | 280 | #define MBED_DEPRECATED(M) __attribute__((deprecated(M))) |
kevman | 0:38ceb79fef03 | 281 | #else |
kevman | 0:38ceb79fef03 | 282 | #define MBED_DEPRECATED(M) |
kevman | 0:38ceb79fef03 | 283 | #endif |
kevman | 0:38ceb79fef03 | 284 | #endif |
kevman | 0:38ceb79fef03 | 285 | |
kevman | 0:38ceb79fef03 | 286 | /** MBED_DEPRECATED_SINCE("version", "message string") |
kevman | 0:38ceb79fef03 | 287 | * Mark a function declaration as deprecated, noting that the declaration was |
kevman | 0:38ceb79fef03 | 288 | * deprecated on the specified version. If the function is used then a warning |
kevman | 0:38ceb79fef03 | 289 | * will be issued by the compiler possibly including the provided message. |
kevman | 0:38ceb79fef03 | 290 | * Note that not all compilers are able to display this message. |
kevman | 0:38ceb79fef03 | 291 | * |
kevman | 0:38ceb79fef03 | 292 | * @code |
kevman | 0:38ceb79fef03 | 293 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 294 | * |
kevman | 0:38ceb79fef03 | 295 | * MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead") |
kevman | 0:38ceb79fef03 | 296 | * void foo(int arg); |
kevman | 0:38ceb79fef03 | 297 | * @endcode |
kevman | 0:38ceb79fef03 | 298 | */ |
kevman | 0:38ceb79fef03 | 299 | #define MBED_DEPRECATED_SINCE(D, M) MBED_DEPRECATED(M " [since " D "]") |
kevman | 0:38ceb79fef03 | 300 | |
kevman | 0:38ceb79fef03 | 301 | /** MBED_CALLER_ADDR() |
kevman | 0:38ceb79fef03 | 302 | * Returns the caller of the current function. |
kevman | 0:38ceb79fef03 | 303 | * |
kevman | 0:38ceb79fef03 | 304 | * @note |
kevman | 0:38ceb79fef03 | 305 | * This macro is only implemented for GCC and ARMCC. |
kevman | 0:38ceb79fef03 | 306 | * |
kevman | 0:38ceb79fef03 | 307 | * @code |
kevman | 0:38ceb79fef03 | 308 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 309 | * |
kevman | 0:38ceb79fef03 | 310 | * printf("This function was called from %p", MBED_CALLER_ADDR()); |
kevman | 0:38ceb79fef03 | 311 | * @endcode |
kevman | 0:38ceb79fef03 | 312 | * |
kevman | 0:38ceb79fef03 | 313 | * @return Address of the calling function |
kevman | 0:38ceb79fef03 | 314 | */ |
kevman | 0:38ceb79fef03 | 315 | #ifndef MBED_CALLER_ADDR |
kevman | 0:38ceb79fef03 | 316 | #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 317 | #define MBED_CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0)) |
kevman | 0:38ceb79fef03 | 318 | #elif defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 319 | #define MBED_CALLER_ADDR() __builtin_return_address(0) |
kevman | 0:38ceb79fef03 | 320 | #else |
kevman | 0:38ceb79fef03 | 321 | #define MBED_CALLER_ADDR() (NULL) |
kevman | 0:38ceb79fef03 | 322 | #endif |
kevman | 0:38ceb79fef03 | 323 | #endif |
kevman | 0:38ceb79fef03 | 324 | |
kevman | 0:38ceb79fef03 | 325 | #ifndef MBED_SECTION |
kevman | 0:38ceb79fef03 | 326 | #if (defined(__GNUC__) || defined(__clang__)) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 327 | #define MBED_SECTION(name) __attribute__ ((section (name))) |
kevman | 0:38ceb79fef03 | 328 | #elif defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 329 | #define MBED_SECTION(name) _Pragma(MBED_STRINGIFY(location=name)) |
kevman | 0:38ceb79fef03 | 330 | #else |
kevman | 0:38ceb79fef03 | 331 | #error "Missing MBED_SECTION directive" |
kevman | 0:38ceb79fef03 | 332 | #endif |
kevman | 0:38ceb79fef03 | 333 | #endif |
kevman | 0:38ceb79fef03 | 334 | |
kevman | 0:38ceb79fef03 | 335 | /** |
kevman | 0:38ceb79fef03 | 336 | * Macro expanding to a string literal of the enclosing function name. |
kevman | 0:38ceb79fef03 | 337 | * |
kevman | 0:38ceb79fef03 | 338 | * The string returned takes into account language specificity and yield human |
kevman | 0:38ceb79fef03 | 339 | * readable content. |
kevman | 0:38ceb79fef03 | 340 | * |
kevman | 0:38ceb79fef03 | 341 | * As an example, if the macro is used within a C++ function then the string |
kevman | 0:38ceb79fef03 | 342 | * literal containing the function name will contain the complete signature of |
kevman | 0:38ceb79fef03 | 343 | * the function - including template parameters - and namespace qualifications. |
kevman | 0:38ceb79fef03 | 344 | */ |
kevman | 0:38ceb79fef03 | 345 | #ifndef MBED_PRETTY_FUNCTION |
kevman | 0:38ceb79fef03 | 346 | #define MBED_PRETTY_FUNCTION __PRETTY_FUNCTION__ |
kevman | 0:38ceb79fef03 | 347 | #endif |
kevman | 0:38ceb79fef03 | 348 | |
kevman | 0:38ceb79fef03 | 349 | #ifndef MBED_PRINTF |
kevman | 0:38ceb79fef03 | 350 | #if defined(__GNUC__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 351 | #define MBED_PRINTF(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx, first_param_idx))) |
kevman | 0:38ceb79fef03 | 352 | #else |
kevman | 0:38ceb79fef03 | 353 | #define MBED_PRINTF(format_idx, first_param_idx) |
kevman | 0:38ceb79fef03 | 354 | #endif |
kevman | 0:38ceb79fef03 | 355 | #endif |
kevman | 0:38ceb79fef03 | 356 | |
kevman | 0:38ceb79fef03 | 357 | #ifndef MBED_PRINTF_METHOD |
kevman | 0:38ceb79fef03 | 358 | #if defined(__GNUC__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 359 | #define MBED_PRINTF_METHOD(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx+1, first_param_idx+1))) |
kevman | 0:38ceb79fef03 | 360 | #else |
kevman | 0:38ceb79fef03 | 361 | #define MBED_PRINTF_METHOD(format_idx, first_param_idx) |
kevman | 0:38ceb79fef03 | 362 | #endif |
kevman | 0:38ceb79fef03 | 363 | #endif |
kevman | 0:38ceb79fef03 | 364 | |
kevman | 0:38ceb79fef03 | 365 | #ifndef MBED_SCANF |
kevman | 0:38ceb79fef03 | 366 | #if defined(__GNUC__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 367 | #define MBED_SCANF(format_idx, first_param_idx) __attribute__ ((__format__(__scanf__, format_idx, first_param_idx))) |
kevman | 0:38ceb79fef03 | 368 | #else |
kevman | 0:38ceb79fef03 | 369 | #define MBED_SCANF(format_idx, first_param_idx) |
kevman | 0:38ceb79fef03 | 370 | #endif |
kevman | 0:38ceb79fef03 | 371 | #endif |
kevman | 0:38ceb79fef03 | 372 | |
kevman | 0:38ceb79fef03 | 373 | #ifndef MBED_SCANF_METHOD |
kevman | 0:38ceb79fef03 | 374 | #if defined(__GNUC__) || defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 375 | #define MBED_SCANF_METHOD(format_idx, first_param_idx) __attribute__ ((__format__(__scanf__, format_idx+1, first_param_idx+1))) |
kevman | 0:38ceb79fef03 | 376 | #else |
kevman | 0:38ceb79fef03 | 377 | #define MBED_SCANF_METHOD(format_idx, first_param_idx) |
kevman | 0:38ceb79fef03 | 378 | #endif |
kevman | 0:38ceb79fef03 | 379 | #endif |
kevman | 0:38ceb79fef03 | 380 | |
kevman | 0:38ceb79fef03 | 381 | // Macro containing the filename part of the value of __FILE__. Defined as |
kevman | 0:38ceb79fef03 | 382 | // string literal. |
kevman | 0:38ceb79fef03 | 383 | #ifndef MBED_FILENAME |
kevman | 0:38ceb79fef03 | 384 | #if defined(__CC_ARM) |
kevman | 0:38ceb79fef03 | 385 | #define MBED_FILENAME __MODULE__ |
kevman | 0:38ceb79fef03 | 386 | #elif defined(__GNUC__) |
kevman | 0:38ceb79fef03 | 387 | #define MBED_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__) |
kevman | 0:38ceb79fef03 | 388 | #elif defined(__ICCARM__) |
kevman | 0:38ceb79fef03 | 389 | #define MBED_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) |
kevman | 0:38ceb79fef03 | 390 | #else |
kevman | 0:38ceb79fef03 | 391 | #define MBED_FILENAME __FILE__ |
kevman | 0:38ceb79fef03 | 392 | #endif |
kevman | 0:38ceb79fef03 | 393 | #endif // #ifndef MBED_FILENAME |
kevman | 0:38ceb79fef03 | 394 | |
kevman | 0:38ceb79fef03 | 395 | // FILEHANDLE declaration |
kevman | 0:38ceb79fef03 | 396 | #if defined(TOOLCHAIN_ARM) |
kevman | 0:38ceb79fef03 | 397 | #include <rt_sys.h> |
kevman | 0:38ceb79fef03 | 398 | #endif |
kevman | 0:38ceb79fef03 | 399 | |
kevman | 0:38ceb79fef03 | 400 | #ifndef FILEHANDLE |
kevman | 0:38ceb79fef03 | 401 | typedef int FILEHANDLE; |
kevman | 0:38ceb79fef03 | 402 | #endif |
kevman | 0:38ceb79fef03 | 403 | |
kevman | 0:38ceb79fef03 | 404 | // Backwards compatibility |
kevman | 0:38ceb79fef03 | 405 | #ifndef WEAK |
kevman | 0:38ceb79fef03 | 406 | #define WEAK MBED_WEAK |
kevman | 0:38ceb79fef03 | 407 | #endif |
kevman | 0:38ceb79fef03 | 408 | |
kevman | 0:38ceb79fef03 | 409 | #ifndef PACKED |
kevman | 0:38ceb79fef03 | 410 | #define PACKED MBED_PACKED() |
kevman | 0:38ceb79fef03 | 411 | #endif |
kevman | 0:38ceb79fef03 | 412 | |
kevman | 0:38ceb79fef03 | 413 | #ifndef EXTERN |
kevman | 0:38ceb79fef03 | 414 | #define EXTERN extern |
kevman | 0:38ceb79fef03 | 415 | #endif |
kevman | 0:38ceb79fef03 | 416 | |
kevman | 0:38ceb79fef03 | 417 | /** MBED_NONSECURE_ENTRY |
kevman | 0:38ceb79fef03 | 418 | * Declare a function that can be called from non-secure world or secure world |
kevman | 0:38ceb79fef03 | 419 | * |
kevman | 0:38ceb79fef03 | 420 | * @code |
kevman | 0:38ceb79fef03 | 421 | * #include "mbed_toolchain.h" |
kevman | 0:38ceb79fef03 | 422 | * |
kevman | 0:38ceb79fef03 | 423 | * MBED_NONSECURE_ENTRY void foo() { |
kevman | 0:38ceb79fef03 | 424 | * |
kevman | 0:38ceb79fef03 | 425 | * } |
kevman | 0:38ceb79fef03 | 426 | * @endcode |
kevman | 0:38ceb79fef03 | 427 | */ |
kevman | 0:38ceb79fef03 | 428 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3L) |
kevman | 0:38ceb79fef03 | 429 | #if defined (__ICCARM__) |
kevman | 0:38ceb79fef03 | 430 | #define MBED_NONSECURE_ENTRY __cmse_nonsecure_entry |
kevman | 0:38ceb79fef03 | 431 | #else |
kevman | 0:38ceb79fef03 | 432 | #define MBED_NONSECURE_ENTRY __attribute__((cmse_nonsecure_entry)) |
kevman | 0:38ceb79fef03 | 433 | #endif |
kevman | 0:38ceb79fef03 | 434 | #else |
kevman | 0:38ceb79fef03 | 435 | #define MBED_NONSECURE_ENTRY |
kevman | 0:38ceb79fef03 | 436 | #endif |
kevman | 0:38ceb79fef03 | 437 | |
kevman | 0:38ceb79fef03 | 438 | #endif |
kevman | 0:38ceb79fef03 | 439 | |
kevman | 0:38ceb79fef03 | 440 | /** @}*/ |
kevman | 0:38ceb79fef03 | 441 | /** @}*/ |