The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Kojto
Date:
Thu Jul 07 14:34:11 2016 +0100
Revision:
122:f9eeca106725
Parent:
66:9c8f0e3462fb
Child:
124:2241e3a39974
Release 122 of the mbed library

Changes:
- new targets - Nucleo L432KC, Beetle, Nucleo F446ZE, Nucleo L011K4
- Thread safety addition - mbed API should contain a statement about thread safety
- critical section API addition
- CAS API (core_util_atomic_incr/decr)
- DEVICE_ are generated from targets.json file, device.h deprecated
- Callback replaces FunctionPointer to provide std like interface
- mbed HAL API docs improvements
- toolchain - prexif attributes with MBED_
- add new attributes - packed, weak, forcedinline, align
- target.json - contains targets definitions
- ST - L1XX - Cube update to 1.5
- SPI clock selection fix (clock from APB domain)
- F7 - Cube update v1.4.0
- L0 - baudrate init fix
- L1 - Cube update v1.5
- F3 - baudrate init fix, 3 targets CAN support
- F4 - Cube update v1.12.0, 3 targets CAN support
- L4XX - Cube update v1.5.1
- F0 - update Cube to v1.5.0
- L4 - 2 targets (L476RG/VG) CAN support
- NXP - pwm clock fix for KSDK2 MCU
- LPC2368 - remove ARM toolchain support - due to regression
- KSDK2 - fix SPI , I2C address and repeat start
- Silabs - some fixes backported from mbed 3
- Renesas - RZ_A1H - SystemCoreClockUpdate addition

Who changed what in which revision?

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