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 { uint32_t v; }; 102 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 103 #endif 104 #ifndef __UNALIGNED_UINT16_WRITE 105 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 106 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 107 #endif 108 #ifndef __UNALIGNED_UINT16_READ 109 __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 110 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 111 #endif 112 #ifndef __UNALIGNED_UINT32_WRITE 113 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 114 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 115 #endif 116 #ifndef __UNALIGNED_UINT32_READ 117 __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 118 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 119 #endif 120 #ifndef __ALIGNED 121 #define __ALIGNED(x) __attribute__((aligned(x))) 122 #endif 123 #ifndef __RESTRICT 124 #define __RESTRICT __restrict 125 #endif 126 #ifndef __COMPILER_BARRIER 127 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 128 #define __COMPILER_BARRIER() (void)0 129 #endif 130 131 132 /* 133 * TASKING Compiler 134 */ 135 #elif defined ( __TASKING__ ) 136 /* 137 * The CMSIS functions have been implemented as intrinsics in the compiler. 138 * Please use "carm -?i" to get an up to date list of all intrinsics, 139 * Including the CMSIS ones. 140 */ 141 142 #ifndef __ASM 143 #define __ASM __asm 144 #endif 145 #ifndef __INLINE 146 #define __INLINE inline 147 #endif 148 #ifndef __STATIC_INLINE 149 #define __STATIC_INLINE static inline 150 #endif 151 #ifndef __STATIC_FORCEINLINE 152 #define __STATIC_FORCEINLINE __STATIC_INLINE 153 #endif 154 #ifndef __NO_RETURN 155 #define __NO_RETURN __attribute__((noreturn)) 156 #endif 157 #ifndef __USED 158 #define __USED __attribute__((used)) 159 #endif 160 #ifndef __WEAK 161 #define __WEAK __attribute__((weak)) 162 #endif 163 #ifndef __PACKED 164 #define __PACKED __packed__ 165 #endif 166 #ifndef __PACKED_STRUCT 167 #define __PACKED_STRUCT struct __packed__ 168 #endif 169 #ifndef __PACKED_UNION 170 #define __PACKED_UNION union __packed__ 171 #endif 172 #ifndef __UNALIGNED_UINT32 /* deprecated */ 173 struct __packed__ T_UINT32 { uint32_t v; }; 174 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 175 #endif 176 #ifndef __UNALIGNED_UINT16_WRITE 177 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 178 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 179 #endif 180 #ifndef __UNALIGNED_UINT16_READ 181 __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 182 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 183 #endif 184 #ifndef __UNALIGNED_UINT32_WRITE 185 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 186 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 187 #endif 188 #ifndef __UNALIGNED_UINT32_READ 189 __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 190 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 191 #endif 192 #ifndef __ALIGNED 193 #define __ALIGNED(x) __align(x) 194 #endif 195 #ifndef __RESTRICT 196 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 197 #define __RESTRICT 198 #endif 199 #ifndef __COMPILER_BARRIER 200 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 201 #define __COMPILER_BARRIER() (void)0 202 #endif 203 204 205 /* 206 * COSMIC Compiler 207 */ 208 #elif defined ( __CSMC__ ) 209 #include <cmsis_csm.h> 210 211 #ifndef __ASM 212 #define __ASM _asm 213 #endif 214 #ifndef __INLINE 215 #define __INLINE inline 216 #endif 217 #ifndef __STATIC_INLINE 218 #define __STATIC_INLINE static inline 219 #endif 220 #ifndef __STATIC_FORCEINLINE 221 #define __STATIC_FORCEINLINE __STATIC_INLINE 222 #endif 223 #ifndef __NO_RETURN 224 // NO RETURN is automatically detected hence no warning here 225 #define __NO_RETURN 226 #endif 227 #ifndef __USED 228 #warning No compiler specific solution for __USED. __USED is ignored. 229 #define __USED 230 #endif 231 #ifndef __WEAK 232 #define __WEAK __weak 233 #endif 234 #ifndef __PACKED 235 #define __PACKED @packed 236 #endif 237 #ifndef __PACKED_STRUCT 238 #define __PACKED_STRUCT @packed struct 239 #endif 240 #ifndef __PACKED_UNION 241 #define __PACKED_UNION @packed union 242 #endif 243 #ifndef __UNALIGNED_UINT32 /* deprecated */ 244 @packed struct T_UINT32 { uint32_t v; }; 245 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 246 #endif 247 #ifndef __UNALIGNED_UINT16_WRITE 248 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 249 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 250 #endif 251 #ifndef __UNALIGNED_UINT16_READ 252 __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 253 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 254 #endif 255 #ifndef __UNALIGNED_UINT32_WRITE 256 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 257 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 258 #endif 259 #ifndef __UNALIGNED_UINT32_READ 260 __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 261 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 262 #endif 263 #ifndef __ALIGNED 264 #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 265 #define __ALIGNED(x) 266 #endif 267 #ifndef __RESTRICT 268 #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 269 #define __RESTRICT 270 #endif 271 #ifndef __COMPILER_BARRIER 272 #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. 273 #define __COMPILER_BARRIER() (void)0 274 #endif 275 276 277 #else 278 #error Unknown compiler. 279 #endif 280 281 282 #endif /* __CMSIS_COMPILER_H */ 283