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 #if __ARM_ARCH_PROFILE == 'A' 33 #include "./a-profile/cmsis_armclang_a.h" 34 #elif __ARM_ARCH_PROFILE == 'R' 35 #include "./r-profile/cmsis_armclang_r.h" 36 #elif __ARM_ARCH_PROFILE == 'M' 37 #include "./m-profile/cmsis_armclang_m.h" 38 #else 39 #error "Unknown Arm architecture profile" 40 #endif 41 42 /* 43 * TI Arm Clang Compiler (tiarmclang) 44 */ 45 #elif defined (__ti__) 46 #if __ARM_ARCH_PROFILE == 'A' 47 #error "Core-A is not supported for this compiler" 48 #elif __ARM_ARCH_PROFILE == 'R' 49 #error "Core-R is not supported for this compiler" 50 #elif __ARM_ARCH_PROFILE == 'M' 51 #include "m-profile/cmsis_tiarmclang_m.h" 52 #else 53 #error "Unknown Arm architecture profile" 54 #endif 55 56 57 /* 58 * LLVM/Clang Compiler 59 */ 60 #elif defined ( __clang__ ) 61 #if __ARM_ARCH_PROFILE == 'A' 62 #include "a-profile/cmsis_clang_a.h" 63 #elif __ARM_ARCH_PROFILE == 'R' 64 #include "r-profile/cmsis_clang_r.h" 65 #elif __ARM_ARCH_PROFILE == 'M' 66 #include "m-profile/cmsis_clang_m.h" 67 #else 68 #error "Unknown Arm architecture profile" 69 #endif 70 71 72 /* 73 * GNU Compiler 74 */ 75 #elif defined ( __GNUC__ ) 76 #if __ARM_ARCH_PROFILE == 'A' 77 #include "a-profile/cmsis_gcc_a.h" 78 #elif __ARM_ARCH_PROFILE == 'R' 79 #include "r-profile/cmsis_gcc_r.h" 80 #elif __ARM_ARCH_PROFILE == 'M' 81 #include "m-profile/cmsis_gcc_m.h" 82 #else 83 #error "Unknown Arm architecture profile" 84 #endif 85 86 87 /* 88 * IAR Compiler 89 */ 90 #elif defined ( __ICCARM__ ) 91 #if __ARM_ARCH_PROFILE == 'A' 92 #include "a-profile/cmsis_iccarm_a.h" 93 #elif __ARM_ARCH_PROFILE == 'R' 94 #include "r-profile/cmsis_iccarm_r.h" 95 #elif __ARM_ARCH_PROFILE == 'M' 96 #include "m-profile/cmsis_iccarm_m.h" 97 #else 98 #error "Unknown Arm architecture profile" 99 #endif 100 101 102 /* 103 * TI Arm Compiler (armcl) 104 */ 105 #elif defined ( __TI_ARM__ ) 106 #include <cmsis_ccs.h> 107 108 #ifndef __ASM 109 #define __ASM __asm 110 #endif 111 #ifndef __INLINE 112 #define __INLINE inline 113 #endif 114 #ifndef __STATIC_INLINE 115 #define __STATIC_INLINE static inline 116 #endif 117 #ifndef __STATIC_FORCEINLINE 118 #define __STATIC_FORCEINLINE __STATIC_INLINE 119 #endif 120 #ifndef __NO_RETURN 121 #define __NO_RETURN __attribute__((noreturn)) 122 #endif 123 #ifndef __USED 124 #define __USED __attribute__((used)) 125 #endif 126 #ifndef __WEAK 127 #define __WEAK __attribute__((weak)) 128 #endif 129 #ifndef __PACKED 130 #define __PACKED __attribute__((packed)) 131 #endif 132 #ifndef __PACKED_STRUCT 133 #define __PACKED_STRUCT struct __attribute__((packed)) 134 #endif 135 #ifndef __PACKED_UNION 136 #define __PACKED_UNION union __attribute__((packed)) 137 #endif 138 #ifndef __UNALIGNED_UINT16_WRITE 139 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 140 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 141 #endif 142 #ifndef __UNALIGNED_UINT16_READ 143 __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 144 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 145 #endif 146 #ifndef __UNALIGNED_UINT32_WRITE 147 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 148 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 149 #endif 150 #ifndef __UNALIGNED_UINT32_READ 151 __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 152 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 153 #endif 154 #ifndef __ALIGNED 155 #define __ALIGNED(x) __attribute__((aligned(x))) 156 #endif 157 #ifndef __RESTRICT 158 #define __RESTRICT __restrict 159 #endif 160 #ifndef __COMPILER_BARRIER 161 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 162 #define __COMPILER_BARRIER() (void)0 163 #endif 164 #ifndef __NO_INIT 165 #define __NO_INIT __attribute__ ((section (".noinit"))) 166 #endif 167 #ifndef __ALIAS 168 #define __ALIAS(x) __attribute__ ((alias(x))) 169 #endif 170 171 /* 172 * TASKING Compiler 173 */ 174 #elif defined ( __TASKING__ ) 175 /* 176 * The CMSIS functions have been implemented as intrinsics in the compiler. 177 * Please use "carm -?i" to get an up to date list of all intrinsics, 178 * Including the CMSIS ones. 179 */ 180 181 #ifndef __ASM 182 #define __ASM __asm 183 #endif 184 #ifndef __INLINE 185 #define __INLINE inline 186 #endif 187 #ifndef __STATIC_INLINE 188 #define __STATIC_INLINE static inline 189 #endif 190 #ifndef __STATIC_FORCEINLINE 191 #define __STATIC_FORCEINLINE __STATIC_INLINE 192 #endif 193 #ifndef __NO_RETURN 194 #define __NO_RETURN __attribute__((noreturn)) 195 #endif 196 #ifndef __USED 197 #define __USED __attribute__((used)) 198 #endif 199 #ifndef __WEAK 200 #define __WEAK __attribute__((weak)) 201 #endif 202 #ifndef __PACKED 203 #define __PACKED __packed__ 204 #endif 205 #ifndef __PACKED_STRUCT 206 #define __PACKED_STRUCT struct __packed__ 207 #endif 208 #ifndef __PACKED_UNION 209 #define __PACKED_UNION union __packed__ 210 #endif 211 #ifndef __UNALIGNED_UINT16_WRITE 212 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 213 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 214 #endif 215 #ifndef __UNALIGNED_UINT16_READ 216 __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 217 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 218 #endif 219 #ifndef __UNALIGNED_UINT32_WRITE 220 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 221 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 222 #endif 223 #ifndef __UNALIGNED_UINT32_READ 224 __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 225 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 226 #endif 227 #ifndef __ALIGNED 228 #define __ALIGNED(x) __align(x) 229 #endif 230 #ifndef __RESTRICT 231 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 232 #define __RESTRICT 233 #endif 234 #ifndef __COMPILER_BARRIER 235 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 236 #define __COMPILER_BARRIER() (void)0 237 #endif 238 #ifndef __NO_INIT 239 #define __NO_INIT __attribute__ ((section (".noinit"))) 240 #endif 241 #ifndef __ALIAS 242 #define __ALIAS(x) __attribute__ ((alias(x))) 243 #endif 244 245 /* 246 * COSMIC Compiler 247 */ 248 #elif defined ( __CSMC__ ) 249 #include <cmsis_csm.h> 250 251 #ifndef __ASM 252 #define __ASM _asm 253 #endif 254 #ifndef __INLINE 255 #define __INLINE inline 256 #endif 257 #ifndef __STATIC_INLINE 258 #define __STATIC_INLINE static inline 259 #endif 260 #ifndef __STATIC_FORCEINLINE 261 #define __STATIC_FORCEINLINE __STATIC_INLINE 262 #endif 263 #ifndef __NO_RETURN 264 // NO RETURN is automatically detected hence no warning here 265 #define __NO_RETURN 266 #endif 267 #ifndef __USED 268 #warning No compiler specific solution for __USED. __USED is ignored. 269 #define __USED 270 #endif 271 #ifndef __WEAK 272 #define __WEAK __weak 273 #endif 274 #ifndef __PACKED 275 #define __PACKED @packed 276 #endif 277 #ifndef __PACKED_STRUCT 278 #define __PACKED_STRUCT @packed struct 279 #endif 280 #ifndef __PACKED_UNION 281 #define __PACKED_UNION @packed union 282 #endif 283 #ifndef __UNALIGNED_UINT16_WRITE 284 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 285 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 286 #endif 287 #ifndef __UNALIGNED_UINT16_READ 288 __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 289 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 290 #endif 291 #ifndef __UNALIGNED_UINT32_WRITE 292 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 293 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 294 #endif 295 #ifndef __UNALIGNED_UINT32_READ 296 __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 297 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 298 #endif 299 #ifndef __ALIGNED 300 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 301 #define __ALIGNED(x) 302 #endif 303 #ifndef __RESTRICT 304 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 305 #define __RESTRICT 306 #endif 307 #ifndef __COMPILER_BARRIER 308 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 309 #define __COMPILER_BARRIER() (void)0 310 #endif 311 #ifndef __NO_INIT 312 #define __NO_INIT __attribute__ ((section (".noinit"))) 313 #endif 314 #ifndef __ALIAS 315 #define __ALIAS(x) __attribute__ ((alias(x))) 316 #endif 317 318 #else 319 #error Unknown compiler. 320 #endif 321 322 323 #endif /* __CMSIS_COMPILER_H */ 324 325