Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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