1 /**************************************************************************//**
3 * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file
6 ******************************************************************************/
8 //------------------------------------------------------------------------------
10 // Copyright (c) 2017-2018 IAR Systems
12 // Licensed under the Apache License, Version 2.0 (the "License")
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
15 // http://www.apache.org/licenses/LICENSE-2.0
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the License is distributed on an "AS IS" BASIS,
19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 // See the License for the specific language governing permissions and
21 // limitations under the License.
23 //------------------------------------------------------------------------------
26 #ifndef __CMSIS_ICCARM_H__
27 #define __CMSIS_ICCARM_H__
30 #error This file should only be compiled by ICCARM
33 #pragma system_include
35 #define __IAR_FT _Pragma("inline=forced") __intrinsic
37 #if (__VER__ >= 8000000)
43 #pragma language=extended
47 #define __ALIGNED(x) __attribute__((aligned(x)))
48 #elif (__VER__ >= 7080000)
49 /* Needs IAR language extensions */
50 #define __ALIGNED(x) __attribute__((aligned(x)))
52 #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
58 /* Define compiler macros for CPU architecture, used in CMSIS 5.
61 /* Macro already defined */
63 #if defined(__ARM7A__)
64 #define __ARM_ARCH_7A__ 1
73 #define __INLINE inline
78 #define __NO_RETURN __attribute__((__noreturn__))
80 #define __NO_RETURN _Pragma("object_attribute=__noreturn")
85 /* Needs IAR language extensions */
87 #define __PACKED __attribute__((packed, aligned(1)))
89 #define __PACKED __packed
93 #ifndef __PACKED_STRUCT
94 /* Needs IAR language extensions */
96 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
98 #define __PACKED_STRUCT __packed struct
102 #ifndef __PACKED_UNION
103 /* Needs IAR language extensions */
105 #define __PACKED_UNION union __attribute__((packed, aligned(1)))
107 #define __PACKED_UNION __packed union
113 #define __RESTRICT __restrict
115 /* Needs IAR language extensions */
116 #define __RESTRICT restrict
120 #ifndef __STATIC_INLINE
121 #define __STATIC_INLINE static inline
124 #ifndef __FORCEINLINE
125 #define __FORCEINLINE _Pragma("inline=forced")
128 #ifndef __STATIC_FORCEINLINE
129 #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
132 #ifndef CMSIS_DEPRECATED
133 #define CMSIS_DEPRECATED __attribute__((deprecated))
136 #ifndef __UNALIGNED_UINT16_READ
137 #pragma language=save
138 #pragma language=extended
139 __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
141 return *(__packed uint16_t*)(ptr);
143 #pragma language=restore
144 #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
148 #ifndef __UNALIGNED_UINT16_WRITE
149 #pragma language=save
150 #pragma language=extended
151 __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
153 *(__packed uint16_t*)(ptr) = val;;
155 #pragma language=restore
156 #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
159 #ifndef __UNALIGNED_UINT32_READ
160 #pragma language=save
161 #pragma language=extended
162 __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
164 return *(__packed uint32_t*)(ptr);
166 #pragma language=restore
167 #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
170 #ifndef __UNALIGNED_UINT32_WRITE
171 #pragma language=save
172 #pragma language=extended
173 __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
175 *(__packed uint32_t*)(ptr) = val;;
177 #pragma language=restore
178 #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
182 #ifndef __UNALIGNED_UINT32 /* deprecated */
183 #pragma language=save
184 #pragma language=extended
185 __packed struct __iar_u32 { uint32_t v; };
186 #pragma language=restore
187 #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
193 #define __USED __attribute__((used))
195 #define __USED _Pragma("__root")
201 #define __WEAK __attribute__((weak))
203 #define __WEAK _Pragma("__weak")
208 #ifndef __ICCARM_INTRINSICS_VERSION__
209 #define __ICCARM_INTRINSICS_VERSION__ 0
212 #if __ICCARM_INTRINSICS_VERSION__ == 2
230 #include "iccarm_builtin.h"
232 #define __enable_irq __iar_builtin_enable_interrupt
233 #define __disable_irq __iar_builtin_disable_interrupt
234 #define __enable_fault_irq __iar_builtin_enable_fiq
235 #define __disable_fault_irq __iar_builtin_disable_fiq
236 #define __arm_rsr __iar_builtin_rsr
237 #define __arm_wsr __iar_builtin_wsr
240 #define __get_FPSCR() (__arm_rsr("FPSCR"))
242 #define __get_FPSCR() ( 0 )
245 #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", VALUE))
247 #define __get_CPSR() (__arm_rsr("CPSR"))
248 #define __get_mode() (__get_CPSR() & 0x1FU)
250 #define __set_CPSR(VALUE) (__arm_wsr("CPSR", (VALUE)))
251 #define __set_mode(VALUE) (__arm_wsr("CPSR_c", (VALUE)))
254 #define __get_FPEXC() (__arm_rsr("FPEXC"))
255 #define __set_FPEXC(VALUE) (__arm_wsr("FPEXC", VALUE))
257 #define __get_CP(cp, op1, RT, CRn, CRm, op2) \
258 ((RT) = __arm_rsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2))
260 #define __set_CP(cp, op1, RT, CRn, CRm, op2) \
261 (__arm_wsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2, (RT)))
263 #define __get_CP64(cp, op1, Rt, CRm) \
264 __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
266 #define __set_CP64(cp, op1, Rt, CRm) \
267 __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
269 #include "cmsis_cp15.h"
271 #define __NOP __iar_builtin_no_operation
273 #define __CLZ __iar_builtin_CLZ
274 #define __CLREX __iar_builtin_CLREX
276 #define __DMB __iar_builtin_DMB
277 #define __DSB __iar_builtin_DSB
278 #define __ISB __iar_builtin_ISB
280 #define __LDREXB __iar_builtin_LDREXB
281 #define __LDREXH __iar_builtin_LDREXH
282 #define __LDREXW __iar_builtin_LDREX
284 #define __RBIT __iar_builtin_RBIT
285 #define __REV __iar_builtin_REV
286 #define __REV16 __iar_builtin_REV16
288 __IAR_FT int16_t __REVSH(int16_t val)
290 return (int16_t) __iar_builtin_REVSH(val);
293 #define __ROR __iar_builtin_ROR
294 #define __RRX __iar_builtin_RRX
296 #define __SEV __iar_builtin_SEV
298 #define __SSAT __iar_builtin_SSAT
300 #define __STREXB __iar_builtin_STREXB
301 #define __STREXH __iar_builtin_STREXH
302 #define __STREXW __iar_builtin_STREX
304 #define __USAT __iar_builtin_USAT
306 #define __WFE __iar_builtin_WFE
307 #define __WFI __iar_builtin_WFI
309 #define __SADD8 __iar_builtin_SADD8
310 #define __QADD8 __iar_builtin_QADD8
311 #define __SHADD8 __iar_builtin_SHADD8
312 #define __UADD8 __iar_builtin_UADD8
313 #define __UQADD8 __iar_builtin_UQADD8
314 #define __UHADD8 __iar_builtin_UHADD8
315 #define __SSUB8 __iar_builtin_SSUB8
316 #define __QSUB8 __iar_builtin_QSUB8
317 #define __SHSUB8 __iar_builtin_SHSUB8
318 #define __USUB8 __iar_builtin_USUB8
319 #define __UQSUB8 __iar_builtin_UQSUB8
320 #define __UHSUB8 __iar_builtin_UHSUB8
321 #define __SADD16 __iar_builtin_SADD16
322 #define __QADD16 __iar_builtin_QADD16
323 #define __SHADD16 __iar_builtin_SHADD16
324 #define __UADD16 __iar_builtin_UADD16
325 #define __UQADD16 __iar_builtin_UQADD16
326 #define __UHADD16 __iar_builtin_UHADD16
327 #define __SSUB16 __iar_builtin_SSUB16
328 #define __QSUB16 __iar_builtin_QSUB16
329 #define __SHSUB16 __iar_builtin_SHSUB16
330 #define __USUB16 __iar_builtin_USUB16
331 #define __UQSUB16 __iar_builtin_UQSUB16
332 #define __UHSUB16 __iar_builtin_UHSUB16
333 #define __SASX __iar_builtin_SASX
334 #define __QASX __iar_builtin_QASX
335 #define __SHASX __iar_builtin_SHASX
336 #define __UASX __iar_builtin_UASX
337 #define __UQASX __iar_builtin_UQASX
338 #define __UHASX __iar_builtin_UHASX
339 #define __SSAX __iar_builtin_SSAX
340 #define __QSAX __iar_builtin_QSAX
341 #define __SHSAX __iar_builtin_SHSAX
342 #define __USAX __iar_builtin_USAX
343 #define __UQSAX __iar_builtin_UQSAX
344 #define __UHSAX __iar_builtin_UHSAX
345 #define __USAD8 __iar_builtin_USAD8
346 #define __USADA8 __iar_builtin_USADA8
347 #define __SSAT16 __iar_builtin_SSAT16
348 #define __USAT16 __iar_builtin_USAT16
349 #define __UXTB16 __iar_builtin_UXTB16
350 #define __UXTAB16 __iar_builtin_UXTAB16
351 #define __SXTB16 __iar_builtin_SXTB16
352 #define __SXTAB16 __iar_builtin_SXTAB16
353 #define __SMUAD __iar_builtin_SMUAD
354 #define __SMUADX __iar_builtin_SMUADX
355 #define __SMMLA __iar_builtin_SMMLA
356 #define __SMLAD __iar_builtin_SMLAD
357 #define __SMLADX __iar_builtin_SMLADX
358 #define __SMLALD __iar_builtin_SMLALD
359 #define __SMLALDX __iar_builtin_SMLALDX
360 #define __SMUSD __iar_builtin_SMUSD
361 #define __SMUSDX __iar_builtin_SMUSDX
362 #define __SMLSD __iar_builtin_SMLSD
363 #define __SMLSDX __iar_builtin_SMLSDX
364 #define __SMLSLD __iar_builtin_SMLSLD
365 #define __SMLSLDX __iar_builtin_SMLSLDX
366 #define __SEL __iar_builtin_SEL
367 #define __QADD __iar_builtin_QADD
368 #define __QSUB __iar_builtin_QSUB
369 #define __PKHBT __iar_builtin_PKHBT
370 #define __PKHTB __iar_builtin_PKHTB
372 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
375 #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
378 #ifdef __INTRINSICS_INCLUDED
379 #error intrinsics.h is already included previously!
382 #include <intrinsics.h>
385 #define __get_FPSCR() (0)
388 #pragma diag_suppress=Pe940
389 #pragma diag_suppress=Pe177
391 #define __enable_irq __enable_interrupt
392 #define __disable_irq __disable_interrupt
393 #define __enable_fault_irq __enable_fiq
394 #define __disable_fault_irq __disable_fiq
395 #define __NOP __no_operation
397 #define __get_xPSR __get_PSR
399 __IAR_FT void __set_mode(uint32_t mode)
401 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
404 __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
406 return __LDREX((unsigned long *)ptr);
409 __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
411 return __STREX(value, (unsigned long *)ptr);
415 __IAR_FT uint32_t __RRX(uint32_t value)
418 __ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc");
423 __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
425 return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
428 __IAR_FT uint32_t __get_FPEXC(void)
430 #if (__FPU_PRESENT == 1)
432 __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
439 __IAR_FT void __set_FPEXC(uint32_t fpexc)
441 #if (__FPU_PRESENT == 1)
442 __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
447 #define __get_CP(cp, op1, Rt, CRn, CRm, op2) \
448 __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
449 #define __set_CP(cp, op1, Rt, CRn, CRm, op2) \
450 __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
451 #define __get_CP64(cp, op1, Rt, CRm) \
452 __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
453 #define __set_CP64(cp, op1, Rt, CRm) \
454 __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
456 #include "cmsis_cp15.h"
458 #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
460 #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
463 __IAR_FT uint32_t __get_SP_usr(void)
469 "CPS #0x1F \n" // no effect in USR mode
471 "MSR cpsr_c, %2 \n" // no effect in USR mode
472 "ISB" : "=r"(cpsr), "=r"(result) : "r"(cpsr) : "memory"
477 __IAR_FT void __set_SP_usr(uint32_t topOfProcStack)
482 "CPS #0x1F \n" // no effect in USR mode
484 "MSR cpsr_c, %2 \n" // no effect in USR mode
485 "ISB" : "=r"(cpsr) : "r" (topOfProcStack), "r"(cpsr) : "memory"
489 #define __get_mode() (__get_CPSR() & 0x1FU)
492 void __FPU_Enable(void)
495 //Permit access to VFP/NEON, registers by modifying CPACR
496 " MRC p15,0,R1,c1,c0,2 \n"
497 " ORR R1,R1,#0x00F00000 \n"
498 " MCR p15,0,R1,c1,c0,2 \n"
500 //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
505 " ORR R1,R1,#0x40000000 \n"
508 //Initialise VFP/NEON registers to 0
511 //Initialise D16 registers to 0
529 #ifdef __ARM_ADVANCED_SIMD__
530 //Initialise D32 registers to 0
549 //Initialise FPSCR to a known state
551 " MOV32 R3,#0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
553 " VMSR FPSCR,R2 \n");
561 #pragma diag_default=Pe940
562 #pragma diag_default=Pe177
564 #endif /* __CMSIS_ICCARM_H__ */