Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
mbed_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 "mbed_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 "mbed_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 "mbed_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 "mbed_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 "mbed_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_NOINLINE 00141 * Declare a function that must not be inlined. 00142 * 00143 * @code 00144 * #include "mbed_toolchain.h" 00145 * 00146 * MBED_NOINLINE void foo() { 00147 * 00148 * } 00149 * @endcode 00150 */ 00151 #ifndef MBED_NOINLINE 00152 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00153 #define MBED_NOINLINE __attribute__((noinline)) 00154 #elif defined(__ICCARM__) 00155 #define MBED_NOINLINE _Pragma("inline=never") 00156 #else 00157 #define MBED_NOINLINE 00158 #endif 00159 #endif 00160 00161 /** MBED_FORCEINLINE 00162 * Declare a function that must always be inlined. Failure to inline 00163 * such a function will result in an error. 00164 * 00165 * @code 00166 * #include "mbed_toolchain.h" 00167 * 00168 * MBED_FORCEINLINE void foo() { 00169 * 00170 * } 00171 * @endcode 00172 */ 00173 #ifndef MBED_FORCEINLINE 00174 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00175 #define MBED_FORCEINLINE static inline __attribute__((always_inline)) 00176 #elif defined(__ICCARM__) 00177 #define MBED_FORCEINLINE _Pragma("inline=forced") static 00178 #else 00179 #define MBED_FORCEINLINE static inline 00180 #endif 00181 #endif 00182 00183 /** MBED_NORETURN 00184 * Declare a function that will never return. 00185 * 00186 * @code 00187 * #include "mbed_toolchain.h" 00188 * 00189 * MBED_NORETURN void foo() { 00190 * // must never return 00191 * while (1) {} 00192 * } 00193 * @endcode 00194 */ 00195 #ifndef MBED_NORETURN 00196 #if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM) 00197 #define MBED_NORETURN __attribute__((noreturn)) 00198 #elif defined(__ICCARM__) 00199 #define MBED_NORETURN __noreturn 00200 #else 00201 #define MBED_NORETURN 00202 #endif 00203 #endif 00204 00205 /** MBED_UNREACHABLE 00206 * An unreachable statement. If the statement is reached, 00207 * behaviour is undefined. Useful in situations where the compiler 00208 * cannot deduce the unreachability of code. 00209 * 00210 * @code 00211 * #include "mbed_toolchain.h" 00212 * 00213 * void foo(int arg) { 00214 * switch (arg) { 00215 * case 1: return 1; 00216 * case 2: return 2; 00217 * ... 00218 * } 00219 * MBED_UNREACHABLE; 00220 * } 00221 * @endcode 00222 */ 00223 #ifndef MBED_UNREACHABLE 00224 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) 00225 #define MBED_UNREACHABLE __builtin_unreachable() 00226 #else 00227 #define MBED_UNREACHABLE while (1) 00228 #endif 00229 #endif 00230 00231 /** MBED_DEPRECATED("message string") 00232 * Mark a function declaration as deprecated, if it used then a warning will be 00233 * issued by the compiler possibly including the provided message. Note that not 00234 * all compilers are able to display the message. 00235 * 00236 * @code 00237 * #include "mbed_toolchain.h" 00238 * 00239 * MBED_DEPRECATED("don't foo any more, bar instead") 00240 * void foo(int arg); 00241 * @endcode 00242 */ 00243 #ifndef MBED_DEPRECATED 00244 #if defined(__CC_ARM) 00245 #define MBED_DEPRECATED(M) __attribute__((deprecated)) 00246 #elif defined(__GNUC__) || defined(__clang__) 00247 #define MBED_DEPRECATED(M) __attribute__((deprecated(M))) 00248 #else 00249 #define MBED_DEPRECATED(M) 00250 #endif 00251 #endif 00252 00253 /** MBED_DEPRECATED_SINCE("version", "message string") 00254 * Mark a function declaration as deprecated, noting that the declaration was 00255 * deprecated on the specified version. If the function is used then a warning 00256 * will be issued by the compiler possibly including the provided message. 00257 * Note that not all compilers are able to display this message. 00258 * 00259 * @code 00260 * #include "mbed_toolchain.h" 00261 * 00262 * MBED_DEPRECATED_SINCE("mbed-os-5.1", "don't foo any more, bar instead") 00263 * void foo(int arg); 00264 * @endcode 00265 */ 00266 #define MBED_DEPRECATED_SINCE(D, M) MBED_DEPRECATED(M " [since " D "]") 00267 00268 /** MBED_CALLER_ADDR() 00269 * Returns the caller of the current function. 00270 * 00271 * @note 00272 * This macro is only implemented for GCC and ARMCC. 00273 * 00274 * @code 00275 * #include "mbed_toolchain.h" 00276 * 00277 * printf("This function was called from %p", MBED_CALLER_ADDR()); 00278 * @endcode 00279 * 00280 * @return Address of the calling function 00281 */ 00282 #ifndef MBED_CALLER_ADDR 00283 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) 00284 #define MBED_CALLER_ADDR() __builtin_extract_return_addr(__builtin_return_address(0)) 00285 #elif defined(__CC_ARM) 00286 #define MBED_CALLER_ADDR() __builtin_return_address(0) 00287 #else 00288 #define MBED_CALLER_ADDR() (NULL) 00289 #endif 00290 #endif 00291 00292 #ifndef MBED_SECTION 00293 #if (defined(__GNUC__) || defined(__clang__)) || defined(__CC_ARM) 00294 #define MBED_SECTION(name) __attribute__ ((section (name))) 00295 #elif defined(__ICCARM__) 00296 #define MBED_SECTION(name) _Pragma(MBED_STRINGIFY(location=name)) 00297 #else 00298 #error "Missing MBED_SECTION directive" 00299 #endif 00300 #endif 00301 00302 #ifndef MBED_PRINTF 00303 #if defined(__GNUC__) || defined(__CC_ARM) 00304 #define MBED_PRINTF(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx, first_param_idx))) 00305 #else 00306 #define MBED_PRINTF(format_idx, first_param_idx) 00307 #endif 00308 #endif 00309 00310 #ifndef MBED_PRINTF_METHOD 00311 #if defined(__GNUC__) || defined(__CC_ARM) 00312 #define MBED_PRINTF_METHOD(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx+1, first_param_idx+1))) 00313 #else 00314 #define MBED_PRINTF_METHOD(format_idx, first_param_idx) 00315 #endif 00316 #endif 00317 00318 #ifndef MBED_SCANF 00319 #if defined(__GNUC__) || defined(__CC_ARM) 00320 #define MBED_SCANF(format_idx, first_param_idx) __attribute__ ((__format__(__scanf__, format_idx, first_param_idx))) 00321 #else 00322 #define MBED_SCANF(format_idx, first_param_idx) 00323 #endif 00324 #endif 00325 00326 #ifndef MBED_SCANF_METHOD 00327 #if defined(__GNUC__) || defined(__CC_ARM) 00328 #define MBED_SCANF_METHOD(format_idx, first_param_idx) __attribute__ ((__format__(__scanf__, format_idx+1, first_param_idx+1))) 00329 #else 00330 #define MBED_SCANF_METHOD(format_idx, first_param_idx) 00331 #endif 00332 #endif 00333 00334 // FILEHANDLE declaration 00335 #if defined(TOOLCHAIN_ARM) 00336 #include <rt_sys.h> 00337 #endif 00338 00339 #ifndef FILEHANDLE 00340 typedef int FILEHANDLE; 00341 #endif 00342 00343 // Backwards compatibility 00344 #ifndef WEAK 00345 #define WEAK MBED_WEAK 00346 #endif 00347 00348 #ifndef PACKED 00349 #define PACKED MBED_PACKED() 00350 #endif 00351 00352 #ifndef EXTERN 00353 #define EXTERN extern 00354 #endif 00355 00356 #endif 00357 00358 /** @}*/
Generated on Wed Nov 13 2024 03:38:36 by
1.7.2
