1 /*
2  * Copyright (c) 2009-2023 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /*
20  * CMSIS Compiler Generic Header File
21  */
22 
23 #ifndef __CMSIS_COMPILER_H
24 #define __CMSIS_COMPILER_H
25 
26 #include <stdint.h>
27 
28 /*
29  * Arm Compiler above 6.10.1 (armclang)
30  */
31 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
32   #include "cmsis_armclang.h"
33 
34 /*
35  * TI Arm Clang Compiler (tiarmclang)
36  */
37 #elif defined (__ti__)
38   #include "cmsis_tiarmclang.h"
39 
40 
41 /*
42  * LLVM/Clang Compiler
43  */
44 #elif defined ( __clang__ )
45   #include "cmsis_clang.h"
46 
47 
48 /*
49  * GNU Compiler
50  */
51 #elif defined ( __GNUC__ )
52   #include "cmsis_gcc.h"
53 
54 
55 /*
56  * IAR Compiler
57  */
58 #elif defined ( __ICCARM__ )
59   #if __ARM_ARCH_PROFILE == 'A'
60     #include "a-profile/cmsis_iccarm_a.h"
61   #elif __ARM_ARCH_PROFILE == 'R'
62     #include "r-profile/cmsis_iccarm_r.h"
63   #elif __ARM_ARCH_PROFILE == 'M'
64     #include "m-profile/cmsis_iccarm_m.h"
65   #else
66     #error "Unknown Arm architecture profile"
67   #endif
68 
69 
70 /*
71  * TI Arm Compiler (armcl)
72  */
73 #elif defined ( __TI_ARM__ )
74   #include <cmsis_ccs.h>
75 
76   #ifndef   __ASM
77     #define __ASM                                  __asm
78   #endif
79   #ifndef   __INLINE
80     #define __INLINE                               inline
81   #endif
82   #ifndef   __STATIC_INLINE
83     #define __STATIC_INLINE                        static inline
84   #endif
85   #ifndef   __STATIC_FORCEINLINE
86     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
87   #endif
88   #ifndef   __NO_RETURN
89     #define __NO_RETURN                            __attribute__((noreturn))
90   #endif
91   #ifndef   __USED
92     #define __USED                                 __attribute__((used))
93   #endif
94   #ifndef   __WEAK
95     #define __WEAK                                 __attribute__((weak))
96   #endif
97   #ifndef   __PACKED
98     #define __PACKED                               __attribute__((packed))
99   #endif
100   #ifndef   __PACKED_STRUCT
101     #define __PACKED_STRUCT                        struct __attribute__((packed))
102   #endif
103   #ifndef   __PACKED_UNION
104     #define __PACKED_UNION                         union __attribute__((packed))
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     #define __ALIGNED(x)                           __attribute__((aligned(x)))
124   #endif
125   #ifndef   __RESTRICT
126     #define __RESTRICT                             __restrict
127   #endif
128   #ifndef   __COMPILER_BARRIER
129     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
130     #define __COMPILER_BARRIER()                   (void)0
131   #endif
132   #ifndef __NO_INIT
133     #define __NO_INIT                              __attribute__ ((section (".noinit")))
134   #endif
135   #ifndef __ALIAS
136     #define __ALIAS(x)                             __attribute__ ((alias(x)))
137   #endif
138 
139 /*
140  * TASKING Compiler
141  */
142 #elif defined ( __TASKING__ )
143   /*
144    * The CMSIS functions have been implemented as intrinsics in the compiler.
145    * Please use "carm -?i" to get an up to date list of all intrinsics,
146    * Including the CMSIS ones.
147    */
148 
149   #ifndef   __ASM
150     #define __ASM                                  __asm
151   #endif
152   #ifndef   __INLINE
153     #define __INLINE                               inline
154   #endif
155   #ifndef   __STATIC_INLINE
156     #define __STATIC_INLINE                        static inline
157   #endif
158   #ifndef   __STATIC_FORCEINLINE
159     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
160   #endif
161   #ifndef   __NO_RETURN
162     #define __NO_RETURN                            __attribute__((noreturn))
163   #endif
164   #ifndef   __USED
165     #define __USED                                 __attribute__((used))
166   #endif
167   #ifndef   __WEAK
168     #define __WEAK                                 __attribute__((weak))
169   #endif
170   #ifndef   __PACKED
171     #define __PACKED                               __packed__
172   #endif
173   #ifndef   __PACKED_STRUCT
174     #define __PACKED_STRUCT                        struct __packed__
175   #endif
176   #ifndef   __PACKED_UNION
177     #define __PACKED_UNION                         union __packed__
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)                           __align(x)
197   #endif
198   #ifndef   __RESTRICT
199     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
200     #define __RESTRICT
201   #endif
202   #ifndef   __COMPILER_BARRIER
203     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
204     #define __COMPILER_BARRIER()                   (void)0
205   #endif
206   #ifndef __NO_INIT
207     #define __NO_INIT                              __attribute__ ((section (".noinit")))
208   #endif
209   #ifndef __ALIAS
210     #define __ALIAS(x)                             __attribute__ ((alias(x)))
211   #endif
212 
213 /*
214  * COSMIC Compiler
215  */
216 #elif defined ( __CSMC__ )
217    #include <cmsis_csm.h>
218 
219  #ifndef   __ASM
220     #define __ASM                                  _asm
221   #endif
222   #ifndef   __INLINE
223     #define __INLINE                               inline
224   #endif
225   #ifndef   __STATIC_INLINE
226     #define __STATIC_INLINE                        static inline
227   #endif
228   #ifndef   __STATIC_FORCEINLINE
229     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
230   #endif
231   #ifndef   __NO_RETURN
232     // NO RETURN is automatically detected hence no warning here
233     #define __NO_RETURN
234   #endif
235   #ifndef   __USED
236     #warning No compiler specific solution for __USED. __USED is ignored.
237     #define __USED
238   #endif
239   #ifndef   __WEAK
240     #define __WEAK                                 __weak
241   #endif
242   #ifndef   __PACKED
243     #define __PACKED                               @packed
244   #endif
245   #ifndef   __PACKED_STRUCT
246     #define __PACKED_STRUCT                        @packed struct
247   #endif
248   #ifndef   __PACKED_UNION
249     #define __PACKED_UNION                         @packed union
250   #endif
251   #ifndef   __UNALIGNED_UINT16_WRITE
252     __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
253     #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
254   #endif
255   #ifndef   __UNALIGNED_UINT16_READ
256     __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
257     #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
258   #endif
259   #ifndef   __UNALIGNED_UINT32_WRITE
260     __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
261     #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
262   #endif
263   #ifndef   __UNALIGNED_UINT32_READ
264     __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
265     #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
266   #endif
267   #ifndef   __ALIGNED
268     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
269     #define __ALIGNED(x)
270   #endif
271   #ifndef   __RESTRICT
272     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
273     #define __RESTRICT
274   #endif
275   #ifndef   __COMPILER_BARRIER
276     #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
277     #define __COMPILER_BARRIER()                   (void)0
278   #endif
279   #ifndef __NO_INIT
280     #define __NO_INIT                              __attribute__ ((section (".noinit")))
281   #endif
282   #ifndef __ALIAS
283     #define __ALIAS(x)                             __attribute__ ((alias(x)))
284   #endif
285 
286 #else
287   #error Unknown compiler.
288 #endif
289 
290 
291 #endif /* __CMSIS_COMPILER_H */
292 
293