]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_compiler.h
Modified LINT comments to use C-style instead of C++-style in order to be C89 compliant.
[cmsis] / CMSIS / Core / Include / cmsis_compiler.h
1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V5.0.2
5  * @date     13. February 2017
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24
25 #ifndef __CMSIS_COMPILER_H
26 #define __CMSIS_COMPILER_H
27
28 #include <stdint.h>
29
30 /*
31  * ARM Compiler 4/5
32  */
33 #if   defined ( __CC_ARM )
34   #include "cmsis_armcc.h"
35
36
37 /*
38  * ARM Compiler 6 (armclang)
39  */
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
41   #include "cmsis_armclang.h"
42
43
44 /*
45  * GNU Compiler
46  */
47 #elif defined ( __GNUC__ )
48   #include "cmsis_gcc.h"
49
50
51 /*
52  * IAR Compiler
53  */
54 #elif defined ( __ICCARM__ )
55
56
57   #ifndef   __ASM
58     #define __ASM                                  __asm
59   #endif
60   #ifndef   __INLINE
61     #define __INLINE                               inline
62   #endif
63   #ifndef   __STATIC_INLINE
64     #define __STATIC_INLINE                        static inline
65   #endif
66
67   #include <cmsis_iar.h>
68
69   /* CMSIS compiler control architecture macros */
70   #if (__CORE__ == __ARM6M__) || (__CORE__ == __ARM6SM__)
71     #ifndef __ARM_ARCH_6M__
72       #define __ARM_ARCH_6M__                      1
73     #endif
74   #elif (__CORE__ == __ARM7M__)
75     #ifndef __ARM_ARCH_7M__
76       #define __ARM_ARCH_7M__                      1
77     #endif
78   #elif (__CORE__ == __ARM7EM__)
79     #ifndef __ARM_ARCH_7EM__
80       #define __ARM_ARCH_7EM__                     1
81     #endif
82   #endif
83
84   #ifndef   __NO_RETURN
85     #define __NO_RETURN                            __noreturn
86   #endif
87   #ifndef   __USED
88     #define __USED                                 __root
89   #endif
90   #ifndef   __WEAK
91     #define __WEAK                                 __weak
92   #endif
93   #ifndef   __PACKED
94     #define __PACKED                               __packed
95   #endif
96   #ifndef   __PACKED_STRUCT
97     #define __PACKED_STRUCT                        __packed struct
98   #endif
99   #ifndef   __PACKED_UNION
100     #define __PACKED_UNION                         __packed union
101   #endif
102   #ifndef   __UNALIGNED_UINT32        /* deprecated */
103     __packed struct T_UINT32 { uint32_t v; };
104     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
105   #endif
106   #ifndef   __UNALIGNED_UINT16_WRITE
107     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
108     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
109   #endif
110   #ifndef   __UNALIGNED_UINT16_READ
111     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
112     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
113   #endif
114   #ifndef   __UNALIGNED_UINT32_WRITE
115     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
116     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
117   #endif
118   #ifndef   __UNALIGNED_UINT32_READ
119     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
120     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
121   #endif
122   #ifndef   __ALIGNED
123     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
124     #define __ALIGNED(x)
125   #endif
126
127   // Workaround for missing __CLZ intrinsic in
128   // various versions of the IAR compilers.
129   // __IAR_FEATURE_CLZ__ should be defined by
130   // the compiler that supports __CLZ internally.
131   #if (defined (__ARM_ARCH_6M__)) && (__ARM_ARCH_6M__ == 1) && (!defined (__IAR_FEATURE_CLZ__))
132     __STATIC_INLINE uint32_t __CLZ(uint32_t data)
133     {
134       if (data == 0u) { return 32u; }
135       
136       uint32_t count = 0;
137       uint32_t mask = 0x80000000;
138       
139       while ((data & mask) == 0)
140       {
141         count += 1u;
142         mask = mask >> 1u;
143       }
144       
145       return (count);
146     }
147   #endif
148
149
150 /*
151  * TI ARM Compiler
152  */
153 #elif defined ( __TI_ARM__ )
154   #include <cmsis_ccs.h>
155
156   #ifndef   __ASM
157     #define __ASM                                  __asm
158   #endif
159   #ifndef   __INLINE
160     #define __INLINE                               inline
161   #endif
162   #ifndef   __STATIC_INLINE
163     #define __STATIC_INLINE                        static inline
164   #endif
165   #ifndef   __NO_RETURN
166     #define __NO_RETURN                            __attribute__((noreturn))
167   #endif
168   #ifndef   __USED
169     #define __USED                                 __attribute__((used))
170   #endif
171   #ifndef   __WEAK
172     #define __WEAK                                 __attribute__((weak))
173   #endif
174   #ifndef   __PACKED
175     #define __PACKED                               __attribute__((packed))
176   #endif
177   #ifndef   __PACKED_STRUCT
178     #define __PACKED_STRUCT                        struct __attribute__((packed))
179   #endif
180   #ifndef   __PACKED_UNION
181     #define __PACKED_UNION                         union __attribute__((packed))
182   #endif
183   #ifndef   __UNALIGNED_UINT32        /* deprecated */
184     struct __attribute__((packed)) T_UINT32 { uint32_t v; };
185     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
186   #endif
187   #ifndef   __UNALIGNED_UINT16_WRITE
188     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
189     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
190   #endif
191   #ifndef   __UNALIGNED_UINT16_READ
192     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
193     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
194   #endif
195   #ifndef   __UNALIGNED_UINT32_WRITE
196     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
197     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
198   #endif
199   #ifndef   __UNALIGNED_UINT32_READ
200     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
201     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
202   #endif
203   #ifndef   __ALIGNED
204     #define __ALIGNED(x)                           __attribute__((aligned(x)))
205   #endif
206
207
208 /*
209  * TASKING Compiler
210  */
211 #elif defined ( __TASKING__ )
212   /*
213    * The CMSIS functions have been implemented as intrinsics in the compiler.
214    * Please use "carm -?i" to get an up to date list of all intrinsics,
215    * Including the CMSIS ones.
216    */
217
218   #ifndef   __ASM
219     #define __ASM                                  __asm
220   #endif
221   #ifndef   __INLINE
222     #define __INLINE                               inline
223   #endif
224   #ifndef   __STATIC_INLINE
225     #define __STATIC_INLINE                        static inline
226   #endif
227   #ifndef   __NO_RETURN
228     #define __NO_RETURN                            __attribute__((noreturn))
229   #endif
230   #ifndef   __USED
231     #define __USED                                 __attribute__((used))
232   #endif
233   #ifndef   __WEAK
234     #define __WEAK                                 __attribute__((weak))
235   #endif
236   #ifndef   __PACKED
237     #define __PACKED                               __packed__
238   #endif
239   #ifndef   __PACKED_STRUCT
240     #define __PACKED_STRUCT                        struct __packed__
241   #endif
242   #ifndef   __PACKED_UNION
243     #define __PACKED_UNION                         union __packed__
244   #endif
245   #ifndef   __UNALIGNED_UINT32        /* deprecated */
246     struct __packed__ T_UINT32 { uint32_t v; };
247     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
248   #endif
249   #ifndef   __UNALIGNED_UINT16_WRITE
250     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
251     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
252   #endif
253   #ifndef   __UNALIGNED_UINT16_READ
254     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
255     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
256   #endif
257   #ifndef   __UNALIGNED_UINT32_WRITE
258     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
259     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
260   #endif
261   #ifndef   __UNALIGNED_UINT32_READ
262     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
263     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
264   #endif
265   #ifndef   __ALIGNED
266     #define __ALIGNED(x)              __align(x)
267   #endif
268
269
270 /*
271  * COSMIC Compiler
272  */
273 #elif defined ( __CSMC__ )
274    #include <cmsis_csm.h>
275
276  #ifndef   __ASM
277     #define __ASM                                  _asm
278   #endif
279   #ifndef   __INLINE
280     #define __INLINE                               inline
281   #endif
282   #ifndef   __STATIC_INLINE
283     #define __STATIC_INLINE                        static inline
284   #endif
285   #ifndef   __NO_RETURN
286     // NO RETURN is automatically detected hence no warning here
287     #define __NO_RETURN
288   #endif
289   #ifndef   __USED
290     #warning No compiler specific solution for __USED. __USED is ignored.
291     #define __USED
292   #endif
293   #ifndef   __WEAK
294     #define __WEAK                                 __weak
295   #endif
296   #ifndef   __PACKED
297     #define __PACKED                               @packed
298   #endif
299   #ifndef   __PACKED_STRUCT
300     #define __PACKED_STRUCT                        @packed struct
301   #endif
302   #ifndef   __PACKED_UNION
303     #define __PACKED_UNION                         @packed union
304   #endif
305   #ifndef   __UNALIGNED_UINT32        /* deprecated */
306     @packed struct T_UINT32 { uint32_t v; };
307     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
308   #endif
309   #ifndef   __UNALIGNED_UINT16_WRITE
310     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
311     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
312   #endif
313   #ifndef   __UNALIGNED_UINT16_READ
314     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
315     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
316   #endif
317   #ifndef   __UNALIGNED_UINT32_WRITE
318     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
319     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
320   #endif
321   #ifndef   __UNALIGNED_UINT32_READ
322     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
323     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
324   #endif
325   #ifndef   __ALIGNED
326     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
327     #define __ALIGNED(x)
328   #endif
329
330
331 #else
332   #error Unknown compiler.
333 #endif
334
335
336 #endif /* __CMSIS_COMPILER_H */
337