mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
Embed:
(wiki syntax)
Show/hide line numbers
toolchain.h
00001 00002 /** \addtogroup platform */ 00003 /** @{*/ 00004 /* mbed Microcontroller Library 00005 * Copyright (c) 2006-2013 ARM Limited 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); 00008 * you may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 */ 00019 #ifndef MBED_TOOLCHAIN_H 00020 #define MBED_TOOLCHAIN_H 00021 00022 #include "mbed_preprocessor.h" 00023 00024 00025 // Warning for unsupported compilers 00026 #if !defined(__GNUC__) /* GCC */ \ 00027 && !defined(__CC_ARM) /* ARMCC */ \ 00028 && !defined(__clang__) /* LLVM/Clang */ \ 00029 && !defined(__ICCARM__) /* IAR */ 00030 #warning "This compiler is not yet supported." 00031 #endif 00032 00033 00034 // Attributes 00035 00036 /** MBED_PACKED 00037 * Pack a structure, preventing any padding from being added between fields. 00038 * 00039 * @code 00040 * #include "toolchain.h" 00041 * 00042 * MBED_PACKED(struct) foo { 00043 * char x; 00044 * int y; 00045 * }; 00046 * @endcode 00047 */ 00048 #ifndef MBED_PACKED 00049 #if defined(__ICCARM__) 00050 #define MBED_PACKED(struct) __packed struct 00051 #else 00052 #define MBED_PACKED(struct) struct __attribute__((packed)) 00053 #endif 00054 #endif 00055 00056 /** MBED_ALIGN(N) 00057 * Declare a variable to be aligned on an N-byte boundary. 00058 * 00059 * @note 00060 * IAR does not support alignment greater than word size on the stack 00061 * 00062 * @code 00063 * #include "toolchain.h" 00064 * 00065 * MBED_ALIGN(16) char a; 00066 * @endcode 00067 */ 00068 #ifndef MBED_ALIGN 00069 #if defined(__ICCARM__) 00070 #define MBED_ALIGN(N) _Pragma(MBED_STRINGIFY(data_alignment=N)) 00071 #else 00072 #define MBED_ALIGN(N) __attribute__((aligned(N))) 00073 #endif 00074 #endif 00075 00076 /** MBED_UNUSED 00077 * Declare a function argument to be unused, suppressing compiler warnings 00078 * 00079 * @code 00080 * #include "toolchain.h" 00081 * 00082 * void foo(MBED_UNUSED int arg) { 00083 * 00084 * } 00085 * @endcode 00086 */ 00087 #ifndef MBED_UNUSED 00088 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00089 #define MBED_UNUSED __attribute__((__unused__)) 00090 #else 00091 #define MBED_UNUSED 00092 #endif 00093 #endif 00094 00095 /** MBED_WEAK 00096 * Mark a function as being weak. 00097 * 00098 * @note 00099 * weak functions are not friendly to making code re-usable, as they can only 00100 * be overridden once (and if they are multiply overridden the linker will emit 00101 * no warning). You should not normally use weak symbols as part of the API to 00102 * re-usable modules. 00103 * 00104 * @code 00105 * #include "toolchain.h" 00106 * 00107 * MBED_WEAK void foo() { 00108 * // a weak implementation of foo that can be overriden by a definition 00109 * // without __weak 00110 * } 00111 * @endcode 00112 */ 00113 #ifndef MBED_WEAK 00114 #if defined(__ICCARM__) 00115 #define MBED_WEAK __weak 00116 #else 00117 #define MBED_WEAK __attribute__((weak)) 00118 #endif 00119 #endif 00120 00121 /** MBED_PURE 00122 * Hint to the compiler that a function depends only on parameters 00123 * 00124 * @code 00125 * #include "toolchain.h" 00126 * 00127 * MBED_PURE int foo(int arg){ 00128 * // no access to global variables 00129 * } 00130 * @endcode 00131 */ 00132 #ifndef MBED_PURE 00133 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00134 #define MBED_PURE __attribute__((const)) 00135 #else 00136 #define MBED_PURE 00137 #endif 00138 #endif 00139 00140 /** MBED_FORCEINLINE 00141 * Declare a function that must always be inlined. Failure to inline 00142 * such a function will result in an error. 00143 * 00144 * @code 00145 * #include "toolchain.h" 00146 * 00147 * MBED_FORCEINLINE void foo() { 00148 * 00149 * } 00150 * @endcode 00151 */ 00152 #ifndef MBED_FORCEINLINE 00153 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00154 #define MBED_FORCEINLINE static inline __attribute__((always_inline)) 00155 #elif defined(__ICCARM__) 00156 #define MBED_FORCEINLINE _Pragma("inline=forced") static 00157 #else 00158 #define MBED_FORCEINLINE static inline 00159 #endif 00160 #endif 00161 00162 /** MBED_NORETURN 00163 * Declare a function that will never return. 00164 * 00165 * @code 00166 * #include "toolchain.h" 00167 * 00168 * MBED_NORETURN void foo() { 00169 * // must never return 00170 * while (1) {} 00171 * } 00172 * @endcode 00173 */ 00174 #ifndef MBED_NORETURN 00175 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00176 #define MBED_NORETURN __attribute__((noreturn)) 00177 #elif defined(__ICCARM__) 00178 #define MBED_NORETURN __noreturn 00179 #else 00180 #define MBED_NORETURN 00181 #endif 00182 #endif 00183 00184 /** MBED_UNREACHABLE 00185 * An unreachable statement. If the statement is reached, 00186 * behaviour is undefined. Useful in situations where the compiler 00187 * cannot deduce the unreachability of code. 00188 * 00189 * @code 00190 * #include "toolchain.h" 00191 * 00192 * void foo(int arg) { 00193 * switch (arg) { 00194 * case 1: return 1; 00195 * case 2: return 2; 00196 * ... 00197 * } 00198 * MBED_UNREACHABLE; 00199 * } 00200 * @endcode 00201 */ 00202 #ifndef MBED_UNREACHABLE 00203 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) 00204 #define MBED_UNREACHABLE __builtin_unreachable() 00205 #else 00206 #define MBED_UNREACHABLE while (1) 00207 #endif 00208 #endif 00209 00210 /** MBED_DEPRECATED("message string") 00211 * Mark a function declaration as deprecated, if it used then a warning will be 00212 * issued by the compiler possibly including the provided message. Note that not 00213 * all compilers are able to display the message. 00214 * 00215 * @code 00216 * #include "toolchain.h" 00217 * 00218 * MBED_DEPRECATED("don't foo any more, bar instead") 00219 * void foo(int arg); 00220 * @endcode 00221 */ 00222 #ifndef MBED_DEPRECATED 00223 #if defined(__CC_ARM) 00224 #define MBED_DEPRECATED(M) __attribute__((deprecated)) 00225 #elif defined(__GNUC__) || defined(__clang__) 00226 #define MBED_DEPRECATED(M) __attribute__((deprecated(M))) 00227 #else 00228 #define MBED_DEPRECATED(M) 00229 #endif 00230 #endif 00231 00232 /** MBED_DEPRECATED_SINCE("version", "message string") 00233 * Mark a function declaration as deprecated, noting that the declaration was 00234 * deprecated on the specified version. If the function is used then a warning 00235 * will be issued by the compiler possibly including the provided message. 00236 * Note that not all compilers are able to display this message. 00237 * 00238 * @code 00239 * #include "toolchain.h" 00240 * 00241 * MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead") 00242 * void foo(int arg); 00243 * @endcode 00244 */ 00245 #define MBED_DEPRECATED_SINCE(D, M) MBED_DEPRECATED(M " [since " D "]") 00246 00247 /** MBED_CALLER_ADDR() 00248 * Returns the caller of the current function. 00249 * 00250 * @note 00251 * This macro is only implemented for GCC and ARMCC. 00252 * 00253 * @code 00254 * #include "toolchain.h" 00255 * 00256 * printf("This function was called from %p", MBED_CALLER_ADDR()); 00257 * @endcode 00258 * 00259 * @return Address of the calling function 00260 */ 00261 #ifndef MBED_CALLER_ADDR 00262 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) 00263 #define MBED_CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0)) 00264 #elif defined(__CC_ARM) 00265 #define MBED_CALLER_ADDR() __builtin_return_address(0) 00266 #else 00267 #define MBED_CALLER_ADDR() (NULL) 00268 #endif 00269 #endif 00270 00271 // FILEHANDLE declaration 00272 #if defined(TOOLCHAIN_ARM) 00273 #include <rt_sys.h> 00274 #endif 00275 00276 #ifndef FILEHANDLE 00277 typedef int FILEHANDLE; 00278 #endif 00279 00280 // Backwards compatibility 00281 #ifndef WEAK 00282 #define WEAK MBED_WEAK 00283 #endif 00284 00285 #ifndef PACKED 00286 #define PACKED MBED_PACKED() 00287 #endif 00288 00289 #ifndef EXTERN 00290 #define EXTERN extern 00291 #endif 00292 00293 #endif 00294 00295 /** @}*/
Generated on Tue Jul 12 2022 23:05:49 by 1.7.2