1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V5.1.0
5  * @date     09. October 2018
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2018 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.6 LTM (armclang)
39  */
40 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
41 #include "cmsis_armclang_ltm.h"
42 
43 /*
44 * Arm Compiler above 6.10.1 (armclang)
45 */
46 #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
47 #include "cmsis_armclang.h"
48 
49 
50 /*
51  * GNU Compiler
52  */
53 #elif defined ( __GNUC__ )
54 #include "cmsis_gcc.h"
55 
56 
57 /*
58  * IAR Compiler
59  */
60 #elif defined ( __ICCARM__ )
61 #include <cmsis_iccarm.h>
62 
63 
64 /*
65  * TI Arm Compiler
66  */
67 #elif defined ( __TI_ARM__ )
68 #include <cmsis_ccs.h>
69 
70 #ifndef   __ASM
71     #define __ASM                                  __asm
72 #endif
73 #ifndef   __INLINE
74     #define __INLINE                               inline
75 #endif
76 #ifndef   __STATIC_INLINE
77     #define __STATIC_INLINE                        static inline
78 #endif
79 #ifndef   __STATIC_FORCEINLINE
80     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
81 #endif
82 #ifndef   __NO_RETURN
83     #define __NO_RETURN                            __attribute__((noreturn))
84 #endif
85 #ifndef   __USED
86     #define __USED                                 __attribute__((used))
87 #endif
88 #ifndef   __WEAK
89     #define __WEAK                                 __attribute__((weak))
90 #endif
91 #ifndef   __PACKED
92     #define __PACKED                               __attribute__((packed))
93 #endif
94 #ifndef   __PACKED_STRUCT
95     #define __PACKED_STRUCT                        struct __attribute__((packed))
96 #endif
97 #ifndef   __PACKED_UNION
98     #define __PACKED_UNION                         union __attribute__((packed))
99 #endif
100 #ifndef   __UNALIGNED_UINT32        /* deprecated */
101 struct __attribute__((packed)) T_UINT32
102 {
103     uint32_t v;
104 };
105 #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
106 #endif
107 #ifndef   __UNALIGNED_UINT16_WRITE
108 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
109 #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
110 #endif
111 #ifndef   __UNALIGNED_UINT16_READ
112 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
113 #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
114 #endif
115 #ifndef   __UNALIGNED_UINT32_WRITE
116 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
117 #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
118 #endif
119 #ifndef   __UNALIGNED_UINT32_READ
120 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
121 #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
122 #endif
123 #ifndef   __ALIGNED
124     #define __ALIGNED(x)                           __attribute__((aligned(x)))
125 #endif
126 #ifndef   __RESTRICT
127     #define __RESTRICT                             __restrict
128 #endif
129 
130 
131 /*
132  * TASKING Compiler
133  */
134 #elif defined ( __TASKING__ )
135 /*
136  * The CMSIS functions have been implemented as intrinsics in the compiler.
137  * Please use "carm -?i" to get an up to date list of all intrinsics,
138  * Including the CMSIS ones.
139  */
140 
141 #ifndef   __ASM
142     #define __ASM                                  __asm
143 #endif
144 #ifndef   __INLINE
145     #define __INLINE                               inline
146 #endif
147 #ifndef   __STATIC_INLINE
148     #define __STATIC_INLINE                        static inline
149 #endif
150 #ifndef   __STATIC_FORCEINLINE
151     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
152 #endif
153 #ifndef   __NO_RETURN
154     #define __NO_RETURN                            __attribute__((noreturn))
155 #endif
156 #ifndef   __USED
157     #define __USED                                 __attribute__((used))
158 #endif
159 #ifndef   __WEAK
160     #define __WEAK                                 __attribute__((weak))
161 #endif
162 #ifndef   __PACKED
163     #define __PACKED                               __packed__
164 #endif
165 #ifndef   __PACKED_STRUCT
166     #define __PACKED_STRUCT                        struct __packed__
167 #endif
168 #ifndef   __PACKED_UNION
169     #define __PACKED_UNION                         union __packed__
170 #endif
171 #ifndef   __UNALIGNED_UINT32        /* deprecated */
172 struct __packed__ T_UINT32
173 {
174     uint32_t v;
175 };
176 #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
177 #endif
178 #ifndef   __UNALIGNED_UINT16_WRITE
179 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
180 #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
181 #endif
182 #ifndef   __UNALIGNED_UINT16_READ
183 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
184 #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
185 #endif
186 #ifndef   __UNALIGNED_UINT32_WRITE
187 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
188 #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
189 #endif
190 #ifndef   __UNALIGNED_UINT32_READ
191 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
192 #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
193 #endif
194 #ifndef   __ALIGNED
195     #define __ALIGNED(x)              __align(x)
196 #endif
197 #ifndef   __RESTRICT
198     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
199     #define __RESTRICT
200 #endif
201 
202 
203 /*
204  * COSMIC Compiler
205  */
206 #elif defined ( __CSMC__ )
207 #include <cmsis_csm.h>
208 
209 #ifndef   __ASM
210     #define __ASM                                  _asm
211 #endif
212 #ifndef   __INLINE
213     #define __INLINE                               inline
214 #endif
215 #ifndef   __STATIC_INLINE
216     #define __STATIC_INLINE                        static inline
217 #endif
218 #ifndef   __STATIC_FORCEINLINE
219     #define __STATIC_FORCEINLINE                   __STATIC_INLINE
220 #endif
221 #ifndef   __NO_RETURN
222     // NO RETURN is automatically detected hence no warning here
223     #define __NO_RETURN
224 #endif
225 #ifndef   __USED
226     #warning No compiler specific solution for __USED. __USED is ignored.
227     #define __USED
228 #endif
229 #ifndef   __WEAK
230     #define __WEAK                                 __weak
231 #endif
232 #ifndef   __PACKED
233     #define __PACKED                               @packed
234 #endif
235 #ifndef   __PACKED_STRUCT
236     #define __PACKED_STRUCT                        @packed struct
237 #endif
238 #ifndef   __PACKED_UNION
239     #define __PACKED_UNION                         @packed union
240 #endif
241 #ifndef   __UNALIGNED_UINT32        /* deprecated */
242 @packed struct T_UINT32
243 {
244     uint32_t v;
245 };
246 #define __UNALIGNED_UINT32(x)                  (((struct T_UINT32 *)(x))->v)
247 #endif
248 #ifndef   __UNALIGNED_UINT16_WRITE
249 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
250 #define __UNALIGNED_UINT16_WRITE(addr, val)    (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
251 #endif
252 #ifndef   __UNALIGNED_UINT16_READ
253 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
254 #define __UNALIGNED_UINT16_READ(addr)          (((const struct T_UINT16_READ *)(const void *)(addr))->v)
255 #endif
256 #ifndef   __UNALIGNED_UINT32_WRITE
257 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
258 #define __UNALIGNED_UINT32_WRITE(addr, val)    (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
259 #endif
260 #ifndef   __UNALIGNED_UINT32_READ
261 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
262 #define __UNALIGNED_UINT32_READ(addr)          (((const struct T_UINT32_READ *)(const void *)(addr))->v)
263 #endif
264 #ifndef   __ALIGNED
265     #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
266     #define __ALIGNED(x)
267 #endif
268 #ifndef   __RESTRICT
269     #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
270     #define __RESTRICT
271 #endif
272 
273 
274 #else
275 #error Unknown compiler.
276 #endif
277 
278 
279 #endif /* __CMSIS_COMPILER_H */
280 
281