Maxim mbed development library

Dependents:   sensomed

Committer:
switches
Date:
Tue Nov 08 18:27:11 2016 +0000
Revision:
0:0e018d759a2a
Initial commit

Who changed what in which revision?

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