1 /**************************************************************************//**
2  * @file     cmsis_compiler.h
3  * @brief    CMSIS compiler generic header file
4  * @version  V5.0.1
5  * @date     30. January 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 #ifndef   __ASM
57 #define __ASM                     __asm
58 #endif
59 #ifndef   __INLINE
60 #define __INLINE                  inline
61 #endif
62 #ifndef   __STATIC_INLINE
63 #define __STATIC_INLINE           static inline
64 #endif
65 
66 #include <cmsis_iar.h>
67 
68 #ifndef   __NO_RETURN
69 #define __NO_RETURN               __noreturn
70 #endif
71 #ifndef   __USED
72 #define __USED                    __root
73 #endif
74 #ifndef   __WEAK
75 #define __WEAK                    __weak
76 #endif
77 #ifndef   __UNALIGNED_UINT32
78 __packed struct T_UINT32 {
79     uint32_t v;
80 };
81 #define __UNALIGNED_UINT32(x)     (((struct T_UINT32 *)(x))->v)
82 #endif
83 #ifndef   __ALIGNED
84 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
85 #define __ALIGNED(x)
86 #endif
87 #ifndef   __PACKED
88 #define __PACKED                  __packed
89 #endif
90 #ifndef   __PACKED_STRUCT
91 #define __PACKED_STRUCT           __packed struct
92 #endif
93 
94 
95 /*
96  * TI ARM Compiler
97  */
98 #elif defined ( __TI_ARM__ )
99 #include <cmsis_ccs.h>
100 
101 #ifndef   __ASM
102 #define __ASM                     __asm
103 #endif
104 #ifndef   __INLINE
105 #define __INLINE                  inline
106 #endif
107 #ifndef   __STATIC_INLINE
108 #define __STATIC_INLINE           static inline
109 #endif
110 #ifndef   __NO_RETURN
111 #define __NO_RETURN               __attribute__((noreturn))
112 #endif
113 #ifndef   __USED
114 #define __USED                    __attribute__((used))
115 #endif
116 #ifndef   __WEAK
117 #define __WEAK                    __attribute__((weak))
118 #endif
119 #ifndef   __UNALIGNED_UINT32
120 struct __attribute__((packed)) T_UINT32 {
121     uint32_t v;
122 };
123 #define __UNALIGNED_UINT32(x)     (((struct T_UINT32 *)(x))->v)
124 #endif
125 #ifndef   __ALIGNED
126 #define __ALIGNED(x)              __attribute__((aligned(x)))
127 #endif
128 #ifndef   __PACKED
129 #define __PACKED                  __attribute__((packed))
130 #endif
131 #ifndef   __PACKED_STRUCT
132 #define __PACKED_STRUCT           struct __attribute__((packed))
133 #endif
134 
135 
136 /*
137  * TASKING Compiler
138  */
139 #elif defined ( __TASKING__ )
140 /*
141  * The CMSIS functions have been implemented as intrinsics in the compiler.
142  * Please use "carm -?i" to get an up to date list of all intrinsics,
143  * Including the CMSIS ones.
144  */
145 
146 #ifndef   __ASM
147 #define __ASM                     __asm
148 #endif
149 #ifndef   __INLINE
150 #define __INLINE                  inline
151 #endif
152 #ifndef   __STATIC_INLINE
153 #define __STATIC_INLINE           static inline
154 #endif
155 #ifndef   __NO_RETURN
156 #define __NO_RETURN               __attribute__((noreturn))
157 #endif
158 #ifndef   __USED
159 #define __USED                    __attribute__((used))
160 #endif
161 #ifndef   __WEAK
162 #define __WEAK                    __attribute__((weak))
163 #endif
164 #ifndef   __UNALIGNED_UINT32
165 struct __packed__ T_UINT32 {
166     uint32_t v;
167 };
168 #define __UNALIGNED_UINT32(x)     (((struct T_UINT32 *)(x))->v)
169 #endif
170 #ifndef   __ALIGNED
171 #define __ALIGNED(x)              __align(x)
172 #endif
173 #ifndef   __PACKED
174 #define __PACKED                  __packed__
175 #endif
176 #ifndef   __PACKED_STRUCT
177 #define __PACKED_STRUCT           struct __packed__
178 #endif
179 
180 
181 /*
182  * COSMIC Compiler
183  */
184 #elif defined ( __CSMC__ )
185 #include <cmsis_csm.h>
186 
187 #ifndef   __ASM
188 #define __ASM                     _asm
189 #endif
190 #ifndef   __INLINE
191 #define __INLINE                  inline
192 #endif
193 #ifndef   __STATIC_INLINE
194 #define __STATIC_INLINE           static inline
195 #endif
196 #ifndef   __NO_RETURN
197 // NO RETURN is automatically detected hence no warning here
198 #define __NO_RETURN
199 #endif
200 #ifndef   __USED
201 #warning No compiler specific solution for __USED. __USED is ignored.
202 #define __USED
203 #endif
204 #ifndef   __WEAK
205 #define __WEAK                    __weak
206 #endif
207 #ifndef   __UNALIGNED_UINT32
208 @packed struct T_UINT32 {
209     uint32_t v;
210 };
211 #define __UNALIGNED_UINT32(x)     (((struct T_UINT32 *)(x))->v)
212 #endif
213 #ifndef   __ALIGNED
214 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
215 #define __ALIGNED(x)
216 #endif
217 #ifndef   __PACKED
218 #define __PACKED                  @packed
219 #endif
220 #ifndef   __PACKED_STRUCT
221 #define __PACKED_STRUCT           @packed struct
222 #endif
223 
224 
225 #else
226 #error Unknown compiler.
227 #endif
228 
229 
230 #endif /* __CMSIS_COMPILER_H */
231 
232