source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/platform/mbed_toolchain.h@ 352

Last change on this file since 352 was 352, checked in by coas-nagasima, 6 years ago

arm向けASP3版ECNLを追加

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