]> begriffs open source - cmsis/blob - CMSIS/Core/Include/cmsis_compiler.h
cmsis: fix IAR architecture macros
[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   __UNALIGNED_UINT32        /* deprecated */
100     __packed struct T_UINT32 { uint32_t v; };
101     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
102   #endif
103   #ifndef   __UNALIGNED_UINT16_WRITE
104     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
105     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
106   #endif
107   #ifndef   __UNALIGNED_UINT16_READ
108     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
109     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
110   #endif
111   #ifndef   __UNALIGNED_UINT32_WRITE
112     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
113     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
114   #endif
115   #ifndef   __UNALIGNED_UINT32_READ
116     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
117     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
118   #endif
119   #ifndef   __ALIGNED
120     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
121     #define __ALIGNED(x)
122   #endif
123
124   // Workaround for missing __CLZ intrinsic in
125   // IAR compilers prior 8.0
126   #if (__CORE__ == __ARM6M__) && (__VER__ < 8000000)
127     __STATIC_INLINE uint32_t __CLZ(uint32_t data)
128     {
129       if (data == 0u) { return 32u; }
130       
131       uint32_t count = 0;
132       uint32_t mask = 0x80000000;
133       
134       while ((data & mask) == 0)
135       {
136         count += 1u;
137         mask = mask >> 1u;
138       }
139       
140       return (count);
141     }
142   #endif
143
144
145 /*
146  * TI ARM Compiler
147  */
148 #elif defined ( __TI_ARM__ )
149   #include <cmsis_ccs.h>
150
151   #ifndef   __ASM
152     #define __ASM                                  __asm
153   #endif
154   #ifndef   __INLINE
155     #define __INLINE                               inline
156   #endif
157   #ifndef   __STATIC_INLINE
158     #define __STATIC_INLINE                        static inline
159   #endif
160   #ifndef   __NO_RETURN
161     #define __NO_RETURN                            __attribute__((noreturn))
162   #endif
163   #ifndef   __USED
164     #define __USED                                 __attribute__((used))
165   #endif
166   #ifndef   __WEAK
167     #define __WEAK                                 __attribute__((weak))
168   #endif
169   #ifndef   __PACKED
170     #define __PACKED                               __attribute__((packed))
171   #endif
172   #ifndef   __PACKED_STRUCT
173     #define __PACKED_STRUCT                        struct __attribute__((packed))
174   #endif
175   #ifndef   __UNALIGNED_UINT32        /* deprecated */
176     struct __attribute__((packed)) T_UINT32 { uint32_t v; };
177     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
178   #endif
179   #ifndef   __UNALIGNED_UINT16_WRITE
180     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
181     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
182   #endif
183   #ifndef   __UNALIGNED_UINT16_READ
184     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
185     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
186   #endif
187   #ifndef   __UNALIGNED_UINT32_WRITE
188     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
189     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
190   #endif
191   #ifndef   __UNALIGNED_UINT32_READ
192     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
193     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
194   #endif
195   #ifndef   __ALIGNED
196     #define __ALIGNED(x)                           __attribute__((aligned(x)))
197   #endif
198
199
200 /*
201  * TASKING Compiler
202  */
203 #elif defined ( __TASKING__ )
204   /*
205    * The CMSIS functions have been implemented as intrinsics in the compiler.
206    * Please use "carm -?i" to get an up to date list of all intrinsics,
207    * Including the CMSIS ones.
208    */
209
210   #ifndef   __ASM
211     #define __ASM                                  __asm
212   #endif
213   #ifndef   __INLINE
214     #define __INLINE                               inline
215   #endif
216   #ifndef   __STATIC_INLINE
217     #define __STATIC_INLINE                        static inline
218   #endif
219   #ifndef   __NO_RETURN
220     #define __NO_RETURN                            __attribute__((noreturn))
221   #endif
222   #ifndef   __USED
223     #define __USED                                 __attribute__((used))
224   #endif
225   #ifndef   __WEAK
226     #define __WEAK                                 __attribute__((weak))
227   #endif
228   #ifndef   __PACKED
229     #define __PACKED                               __packed__
230   #endif
231   #ifndef   __PACKED_STRUCT
232     #define __PACKED_STRUCT                        struct __packed__
233   #endif
234   #ifndef   __UNALIGNED_UINT32        /* deprecated */
235     struct __packed__ T_UINT32 { uint32_t v; };
236     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
237   #endif
238   #ifndef   __UNALIGNED_UINT16_WRITE
239     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
240     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
241   #endif
242   #ifndef   __UNALIGNED_UINT16_READ
243     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
244     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
245   #endif
246   #ifndef   __UNALIGNED_UINT32_WRITE
247     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
248     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
249   #endif
250   #ifndef   __UNALIGNED_UINT32_READ
251     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
252     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
253   #endif
254   #ifndef   __ALIGNED
255     #define __ALIGNED(x)              __align(x)
256   #endif
257
258
259 /*
260  * COSMIC Compiler
261  */
262 #elif defined ( __CSMC__ )
263    #include <cmsis_csm.h>
264
265  #ifndef   __ASM
266     #define __ASM                                  _asm
267   #endif
268   #ifndef   __INLINE
269     #define __INLINE                               inline
270   #endif
271   #ifndef   __STATIC_INLINE
272     #define __STATIC_INLINE                        static inline
273   #endif
274   #ifndef   __NO_RETURN
275     // NO RETURN is automatically detected hence no warning here
276     #define __NO_RETURN
277   #endif
278   #ifndef   __USED
279     #warning No compiler specific solution for __USED. __USED is ignored.
280     #define __USED
281   #endif
282   #ifndef   __WEAK
283     #define __WEAK                                 __weak
284   #endif
285   #ifndef   __PACKED
286     #define __PACKED                               @packed
287   #endif
288   #ifndef   __PACKED_STRUCT
289     #define __PACKED_STRUCT                        @packed struct
290   #endif
291   #ifndef   __UNALIGNED_UINT32        /* deprecated */
292     @packed struct T_UINT32 { uint32_t v; };
293     #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
294   #endif
295   #ifndef   __UNALIGNED_UINT16_WRITE
296     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
297     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
298   #endif
299   #ifndef   __UNALIGNED_UINT16_READ
300     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
301     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
302   #endif
303   #ifndef   __UNALIGNED_UINT32_WRITE
304     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
305     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
306   #endif
307   #ifndef   __UNALIGNED_UINT32_READ
308     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
309     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
310   #endif
311   #ifndef   __ALIGNED
312     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
313     #define __ALIGNED(x)
314   #endif
315
316
317 #else
318   #error Unknown compiler.
319 #endif
320
321
322 #endif /* __CMSIS_COMPILER_H */
323