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