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