1*a8f7f3fcSMatthias Ringwald /**************************************************************************//** 2*a8f7f3fcSMatthias Ringwald * @file cmsis_compiler.h 3*a8f7f3fcSMatthias Ringwald * @brief CMSIS compiler generic header file 4*a8f7f3fcSMatthias Ringwald * @version V5.0.4 5*a8f7f3fcSMatthias Ringwald * @date 10. January 2018 6*a8f7f3fcSMatthias Ringwald ******************************************************************************/ 7*a8f7f3fcSMatthias Ringwald /* 8*a8f7f3fcSMatthias Ringwald * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9*a8f7f3fcSMatthias Ringwald * 10*a8f7f3fcSMatthias Ringwald * SPDX-License-Identifier: Apache-2.0 11*a8f7f3fcSMatthias Ringwald * 12*a8f7f3fcSMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the License); you may 13*a8f7f3fcSMatthias Ringwald * not use this file except in compliance with the License. 14*a8f7f3fcSMatthias Ringwald * You may obtain a copy of the License at 15*a8f7f3fcSMatthias Ringwald * 16*a8f7f3fcSMatthias Ringwald * www.apache.org/licenses/LICENSE-2.0 17*a8f7f3fcSMatthias Ringwald * 18*a8f7f3fcSMatthias Ringwald * Unless required by applicable law or agreed to in writing, software 19*a8f7f3fcSMatthias Ringwald * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20*a8f7f3fcSMatthias Ringwald * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21*a8f7f3fcSMatthias Ringwald * See the License for the specific language governing permissions and 22*a8f7f3fcSMatthias Ringwald * limitations under the License. 23*a8f7f3fcSMatthias Ringwald */ 24*a8f7f3fcSMatthias Ringwald 25*a8f7f3fcSMatthias Ringwald #ifndef __CMSIS_COMPILER_H 26*a8f7f3fcSMatthias Ringwald #define __CMSIS_COMPILER_H 27*a8f7f3fcSMatthias Ringwald 28*a8f7f3fcSMatthias Ringwald #include <stdint.h> 29*a8f7f3fcSMatthias Ringwald 30*a8f7f3fcSMatthias Ringwald /* 31*a8f7f3fcSMatthias Ringwald * Arm Compiler 4/5 32*a8f7f3fcSMatthias Ringwald */ 33*a8f7f3fcSMatthias Ringwald #if defined ( __CC_ARM ) 34*a8f7f3fcSMatthias Ringwald #include "cmsis_armcc.h" 35*a8f7f3fcSMatthias Ringwald 36*a8f7f3fcSMatthias Ringwald 37*a8f7f3fcSMatthias Ringwald /* 38*a8f7f3fcSMatthias Ringwald * Arm Compiler 6 (armclang) 39*a8f7f3fcSMatthias Ringwald */ 40*a8f7f3fcSMatthias Ringwald #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 41*a8f7f3fcSMatthias Ringwald #include "cmsis_armclang.h" 42*a8f7f3fcSMatthias Ringwald 43*a8f7f3fcSMatthias Ringwald 44*a8f7f3fcSMatthias Ringwald /* 45*a8f7f3fcSMatthias Ringwald * GNU Compiler 46*a8f7f3fcSMatthias Ringwald */ 47*a8f7f3fcSMatthias Ringwald #elif defined ( __GNUC__ ) 48*a8f7f3fcSMatthias Ringwald #include "cmsis_gcc.h" 49*a8f7f3fcSMatthias Ringwald 50*a8f7f3fcSMatthias Ringwald 51*a8f7f3fcSMatthias Ringwald /* 52*a8f7f3fcSMatthias Ringwald * IAR Compiler 53*a8f7f3fcSMatthias Ringwald */ 54*a8f7f3fcSMatthias Ringwald #elif defined ( __ICCARM__ ) 55*a8f7f3fcSMatthias Ringwald #include <cmsis_iccarm.h> 56*a8f7f3fcSMatthias Ringwald 57*a8f7f3fcSMatthias Ringwald 58*a8f7f3fcSMatthias Ringwald /* 59*a8f7f3fcSMatthias Ringwald * TI Arm Compiler 60*a8f7f3fcSMatthias Ringwald */ 61*a8f7f3fcSMatthias Ringwald #elif defined ( __TI_ARM__ ) 62*a8f7f3fcSMatthias Ringwald #include <cmsis_ccs.h> 63*a8f7f3fcSMatthias Ringwald 64*a8f7f3fcSMatthias Ringwald #ifndef __ASM 65*a8f7f3fcSMatthias Ringwald #define __ASM __asm 66*a8f7f3fcSMatthias Ringwald #endif 67*a8f7f3fcSMatthias Ringwald #ifndef __INLINE 68*a8f7f3fcSMatthias Ringwald #define __INLINE inline 69*a8f7f3fcSMatthias Ringwald #endif 70*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_INLINE 71*a8f7f3fcSMatthias Ringwald #define __STATIC_INLINE static inline 72*a8f7f3fcSMatthias Ringwald #endif 73*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_FORCEINLINE 74*a8f7f3fcSMatthias Ringwald #define __STATIC_FORCEINLINE __STATIC_INLINE 75*a8f7f3fcSMatthias Ringwald #endif 76*a8f7f3fcSMatthias Ringwald #ifndef __NO_RETURN 77*a8f7f3fcSMatthias Ringwald #define __NO_RETURN __attribute__((noreturn)) 78*a8f7f3fcSMatthias Ringwald #endif 79*a8f7f3fcSMatthias Ringwald #ifndef __USED 80*a8f7f3fcSMatthias Ringwald #define __USED __attribute__((used)) 81*a8f7f3fcSMatthias Ringwald #endif 82*a8f7f3fcSMatthias Ringwald #ifndef __WEAK 83*a8f7f3fcSMatthias Ringwald #define __WEAK __attribute__((weak)) 84*a8f7f3fcSMatthias Ringwald #endif 85*a8f7f3fcSMatthias Ringwald #ifndef __PACKED 86*a8f7f3fcSMatthias Ringwald #define __PACKED __attribute__((packed)) 87*a8f7f3fcSMatthias Ringwald #endif 88*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_STRUCT 89*a8f7f3fcSMatthias Ringwald #define __PACKED_STRUCT struct __attribute__((packed)) 90*a8f7f3fcSMatthias Ringwald #endif 91*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_UNION 92*a8f7f3fcSMatthias Ringwald #define __PACKED_UNION union __attribute__((packed)) 93*a8f7f3fcSMatthias Ringwald #endif 94*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32 /* deprecated */ 95*a8f7f3fcSMatthias Ringwald struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 96*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 97*a8f7f3fcSMatthias Ringwald #endif 98*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_WRITE 99*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 100*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 101*a8f7f3fcSMatthias Ringwald #endif 102*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_READ 103*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 104*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 105*a8f7f3fcSMatthias Ringwald #endif 106*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_WRITE 107*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 108*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 109*a8f7f3fcSMatthias Ringwald #endif 110*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_READ 111*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 112*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 113*a8f7f3fcSMatthias Ringwald #endif 114*a8f7f3fcSMatthias Ringwald #ifndef __ALIGNED 115*a8f7f3fcSMatthias Ringwald #define __ALIGNED(x) __attribute__((aligned(x))) 116*a8f7f3fcSMatthias Ringwald #endif 117*a8f7f3fcSMatthias Ringwald #ifndef __RESTRICT 118*a8f7f3fcSMatthias Ringwald #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 119*a8f7f3fcSMatthias Ringwald #define __RESTRICT 120*a8f7f3fcSMatthias Ringwald #endif 121*a8f7f3fcSMatthias Ringwald 122*a8f7f3fcSMatthias Ringwald 123*a8f7f3fcSMatthias Ringwald /* 124*a8f7f3fcSMatthias Ringwald * TASKING Compiler 125*a8f7f3fcSMatthias Ringwald */ 126*a8f7f3fcSMatthias Ringwald #elif defined ( __TASKING__ ) 127*a8f7f3fcSMatthias Ringwald /* 128*a8f7f3fcSMatthias Ringwald * The CMSIS functions have been implemented as intrinsics in the compiler. 129*a8f7f3fcSMatthias Ringwald * Please use "carm -?i" to get an up to date list of all intrinsics, 130*a8f7f3fcSMatthias Ringwald * Including the CMSIS ones. 131*a8f7f3fcSMatthias Ringwald */ 132*a8f7f3fcSMatthias Ringwald 133*a8f7f3fcSMatthias Ringwald #ifndef __ASM 134*a8f7f3fcSMatthias Ringwald #define __ASM __asm 135*a8f7f3fcSMatthias Ringwald #endif 136*a8f7f3fcSMatthias Ringwald #ifndef __INLINE 137*a8f7f3fcSMatthias Ringwald #define __INLINE inline 138*a8f7f3fcSMatthias Ringwald #endif 139*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_INLINE 140*a8f7f3fcSMatthias Ringwald #define __STATIC_INLINE static inline 141*a8f7f3fcSMatthias Ringwald #endif 142*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_FORCEINLINE 143*a8f7f3fcSMatthias Ringwald #define __STATIC_FORCEINLINE __STATIC_INLINE 144*a8f7f3fcSMatthias Ringwald #endif 145*a8f7f3fcSMatthias Ringwald #ifndef __NO_RETURN 146*a8f7f3fcSMatthias Ringwald #define __NO_RETURN __attribute__((noreturn)) 147*a8f7f3fcSMatthias Ringwald #endif 148*a8f7f3fcSMatthias Ringwald #ifndef __USED 149*a8f7f3fcSMatthias Ringwald #define __USED __attribute__((used)) 150*a8f7f3fcSMatthias Ringwald #endif 151*a8f7f3fcSMatthias Ringwald #ifndef __WEAK 152*a8f7f3fcSMatthias Ringwald #define __WEAK __attribute__((weak)) 153*a8f7f3fcSMatthias Ringwald #endif 154*a8f7f3fcSMatthias Ringwald #ifndef __PACKED 155*a8f7f3fcSMatthias Ringwald #define __PACKED __packed__ 156*a8f7f3fcSMatthias Ringwald #endif 157*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_STRUCT 158*a8f7f3fcSMatthias Ringwald #define __PACKED_STRUCT struct __packed__ 159*a8f7f3fcSMatthias Ringwald #endif 160*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_UNION 161*a8f7f3fcSMatthias Ringwald #define __PACKED_UNION union __packed__ 162*a8f7f3fcSMatthias Ringwald #endif 163*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32 /* deprecated */ 164*a8f7f3fcSMatthias Ringwald struct __packed__ T_UINT32 { uint32_t v; }; 165*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 166*a8f7f3fcSMatthias Ringwald #endif 167*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_WRITE 168*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 169*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 170*a8f7f3fcSMatthias Ringwald #endif 171*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_READ 172*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 173*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 174*a8f7f3fcSMatthias Ringwald #endif 175*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_WRITE 176*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 177*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 178*a8f7f3fcSMatthias Ringwald #endif 179*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_READ 180*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 181*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 182*a8f7f3fcSMatthias Ringwald #endif 183*a8f7f3fcSMatthias Ringwald #ifndef __ALIGNED 184*a8f7f3fcSMatthias Ringwald #define __ALIGNED(x) __align(x) 185*a8f7f3fcSMatthias Ringwald #endif 186*a8f7f3fcSMatthias Ringwald #ifndef __RESTRICT 187*a8f7f3fcSMatthias Ringwald #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 188*a8f7f3fcSMatthias Ringwald #define __RESTRICT 189*a8f7f3fcSMatthias Ringwald #endif 190*a8f7f3fcSMatthias Ringwald 191*a8f7f3fcSMatthias Ringwald 192*a8f7f3fcSMatthias Ringwald /* 193*a8f7f3fcSMatthias Ringwald * COSMIC Compiler 194*a8f7f3fcSMatthias Ringwald */ 195*a8f7f3fcSMatthias Ringwald #elif defined ( __CSMC__ ) 196*a8f7f3fcSMatthias Ringwald #include <cmsis_csm.h> 197*a8f7f3fcSMatthias Ringwald 198*a8f7f3fcSMatthias Ringwald #ifndef __ASM 199*a8f7f3fcSMatthias Ringwald #define __ASM _asm 200*a8f7f3fcSMatthias Ringwald #endif 201*a8f7f3fcSMatthias Ringwald #ifndef __INLINE 202*a8f7f3fcSMatthias Ringwald #define __INLINE inline 203*a8f7f3fcSMatthias Ringwald #endif 204*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_INLINE 205*a8f7f3fcSMatthias Ringwald #define __STATIC_INLINE static inline 206*a8f7f3fcSMatthias Ringwald #endif 207*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_FORCEINLINE 208*a8f7f3fcSMatthias Ringwald #define __STATIC_FORCEINLINE __STATIC_INLINE 209*a8f7f3fcSMatthias Ringwald #endif 210*a8f7f3fcSMatthias Ringwald #ifndef __NO_RETURN 211*a8f7f3fcSMatthias Ringwald // NO RETURN is automatically detected hence no warning here 212*a8f7f3fcSMatthias Ringwald #define __NO_RETURN 213*a8f7f3fcSMatthias Ringwald #endif 214*a8f7f3fcSMatthias Ringwald #ifndef __USED 215*a8f7f3fcSMatthias Ringwald #warning No compiler specific solution for __USED. __USED is ignored. 216*a8f7f3fcSMatthias Ringwald #define __USED 217*a8f7f3fcSMatthias Ringwald #endif 218*a8f7f3fcSMatthias Ringwald #ifndef __WEAK 219*a8f7f3fcSMatthias Ringwald #define __WEAK __weak 220*a8f7f3fcSMatthias Ringwald #endif 221*a8f7f3fcSMatthias Ringwald #ifndef __PACKED 222*a8f7f3fcSMatthias Ringwald #define __PACKED @packed 223*a8f7f3fcSMatthias Ringwald #endif 224*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_STRUCT 225*a8f7f3fcSMatthias Ringwald #define __PACKED_STRUCT @packed struct 226*a8f7f3fcSMatthias Ringwald #endif 227*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_UNION 228*a8f7f3fcSMatthias Ringwald #define __PACKED_UNION @packed union 229*a8f7f3fcSMatthias Ringwald #endif 230*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32 /* deprecated */ 231*a8f7f3fcSMatthias Ringwald @packed struct T_UINT32 { uint32_t v; }; 232*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 233*a8f7f3fcSMatthias Ringwald #endif 234*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_WRITE 235*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 236*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 237*a8f7f3fcSMatthias Ringwald #endif 238*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_READ 239*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 240*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 241*a8f7f3fcSMatthias Ringwald #endif 242*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_WRITE 243*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 244*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 245*a8f7f3fcSMatthias Ringwald #endif 246*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_READ 247*a8f7f3fcSMatthias Ringwald __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 248*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 249*a8f7f3fcSMatthias Ringwald #endif 250*a8f7f3fcSMatthias Ringwald #ifndef __ALIGNED 251*a8f7f3fcSMatthias Ringwald #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 252*a8f7f3fcSMatthias Ringwald #define __ALIGNED(x) 253*a8f7f3fcSMatthias Ringwald #endif 254*a8f7f3fcSMatthias Ringwald #ifndef __RESTRICT 255*a8f7f3fcSMatthias Ringwald #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 256*a8f7f3fcSMatthias Ringwald #define __RESTRICT 257*a8f7f3fcSMatthias Ringwald #endif 258*a8f7f3fcSMatthias Ringwald 259*a8f7f3fcSMatthias Ringwald 260*a8f7f3fcSMatthias Ringwald #else 261*a8f7f3fcSMatthias Ringwald #error Unknown compiler. 262*a8f7f3fcSMatthias Ringwald #endif 263*a8f7f3fcSMatthias Ringwald 264*a8f7f3fcSMatthias Ringwald 265*a8f7f3fcSMatthias Ringwald #endif /* __CMSIS_COMPILER_H */ 266*a8f7f3fcSMatthias Ringwald 267