CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Mon Nov 05 09:52:17 2018 -0700
Revision:
3:c547dba5d39b
Parent:
0:aa13e1c335cd
debug

Who changed what in which revision?

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