this hurts

Dependencies:   FFT

Committer:
annieluo2
Date:
Wed Dec 02 18:02:03 2020 +0000
Revision:
0:d6c9b09b4042
boo

Who changed what in which revision?

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