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
112 #define __RESTRICT __restrict
115 #ifndef __STATIC_INLINE
116 #define __STATIC_INLINE static inline
119 #ifndef __FORCEINLINE
120 #define __FORCEINLINE _Pragma("inline=forced")
123 #ifndef __STATIC_FORCEINLINE
124 #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
127 #ifndef CMSIS_DEPRECATED
128 #define CMSIS_DEPRECATED __attribute__((deprecated))
131 #ifndef __UNALIGNED_UINT16_READ
132 #pragma language=save
133 #pragma language=extended
134 __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
136 return *(__packed uint16_t*)(ptr);
138 #pragma language=restore
139 #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
143 #ifndef __UNALIGNED_UINT16_WRITE
144 #pragma language=save
145 #pragma language=extended
146 __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
148 *(__packed uint16_t*)(ptr) = val;;
150 #pragma language=restore
151 #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
154 #ifndef __UNALIGNED_UINT32_READ
155 #pragma language=save
156 #pragma language=extended
157 __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
159 return *(__packed uint32_t*)(ptr);
161 #pragma language=restore
162 #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
165 #ifndef __UNALIGNED_UINT32_WRITE
166 #pragma language=save
167 #pragma language=extended
168 __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
170 *(__packed uint32_t*)(ptr) = val;;
172 #pragma language=restore
173 #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
177 #ifndef __UNALIGNED_UINT32 /* deprecated */
178 #pragma language=save
179 #pragma language=extended
180 __packed struct __iar_u32 { uint32_t v; };
181 #pragma language=restore
182 #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
188 #define __USED __attribute__((used))
190 #define __USED _Pragma("__root")
196 #define __WEAK __attribute__((weak))
198 #define __WEAK _Pragma("__weak")
203 #ifndef __ICCARM_INTRINSICS_VERSION__
204 #define __ICCARM_INTRINSICS_VERSION__ 0
207 #if __ICCARM_INTRINSICS_VERSION__ == 2
225 #include "iccarm_builtin.h"
227 #define __enable_irq __iar_builtin_enable_interrupt
228 #define __disable_irq __iar_builtin_disable_interrupt
229 #define __enable_fault_irq __iar_builtin_enable_fiq
230 #define __disable_fault_irq __iar_builtin_disable_fiq
231 #define __arm_rsr __iar_builtin_rsr
232 #define __arm_wsr __iar_builtin_wsr
235 #define __get_FPSCR() (__arm_rsr("FPSCR"))
237 #define __get_FPSCR() ( 0 )
240 #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", VALUE))
242 #define __get_CPSR() (__arm_rsr("CPSR"))
243 #define __get_mode() (__get_CPSR() & 0x1FU)
245 #define __set_CPSR(VALUE) (__arm_wsr("CPSR", (VALUE)))
246 #define __set_mode(VALUE) (__arm_wsr("CPSR_c", (VALUE)))
249 #define __get_FPEXC() (__arm_rsr("FPEXC"))
250 #define __set_FPEXC(VALUE) (__arm_wsr("FPEXC", VALUE))
252 #define __get_CP(cp, op1, RT, CRn, CRm, op2) \
253 ((RT) = __arm_rsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2))
255 #define __set_CP(cp, op1, RT, CRn, CRm, op2) \
256 (__arm_wsr("p" # cp ":" # op1 ":c" # CRn ":c" # CRm ":" # op2, (RT)))
258 #define __get_CP64(cp, op1, Rt, CRm) \
259 __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
261 #define __set_CP64(cp, op1, Rt, CRm) \
262 __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
264 #include "cmsis_cp15.h"
266 #define __NOP __iar_builtin_no_operation
268 #define __CLZ __iar_builtin_CLZ
269 #define __CLREX __iar_builtin_CLREX
271 #define __DMB __iar_builtin_DMB
272 #define __DSB __iar_builtin_DSB
273 #define __ISB __iar_builtin_ISB
275 #define __LDREXB __iar_builtin_LDREXB
276 #define __LDREXH __iar_builtin_LDREXH
277 #define __LDREXW __iar_builtin_LDREX
279 #define __RBIT __iar_builtin_RBIT
280 #define __REV __iar_builtin_REV
281 #define __REV16 __iar_builtin_REV16
283 __IAR_FT int16_t __REVSH(int16_t val)
285 return (int16_t) __iar_builtin_REVSH(val);
288 #define __ROR __iar_builtin_ROR
289 #define __RRX __iar_builtin_RRX
291 #define __SEV __iar_builtin_SEV
293 #define __SSAT __iar_builtin_SSAT
295 #define __STREXB __iar_builtin_STREXB
296 #define __STREXH __iar_builtin_STREXH
297 #define __STREXW __iar_builtin_STREX
299 #define __USAT __iar_builtin_USAT
301 #define __WFE __iar_builtin_WFE
302 #define __WFI __iar_builtin_WFI
304 #define __SADD8 __iar_builtin_SADD8
305 #define __QADD8 __iar_builtin_QADD8
306 #define __SHADD8 __iar_builtin_SHADD8
307 #define __UADD8 __iar_builtin_UADD8
308 #define __UQADD8 __iar_builtin_UQADD8
309 #define __UHADD8 __iar_builtin_UHADD8
310 #define __SSUB8 __iar_builtin_SSUB8
311 #define __QSUB8 __iar_builtin_QSUB8
312 #define __SHSUB8 __iar_builtin_SHSUB8
313 #define __USUB8 __iar_builtin_USUB8
314 #define __UQSUB8 __iar_builtin_UQSUB8
315 #define __UHSUB8 __iar_builtin_UHSUB8
316 #define __SADD16 __iar_builtin_SADD16
317 #define __QADD16 __iar_builtin_QADD16
318 #define __SHADD16 __iar_builtin_SHADD16
319 #define __UADD16 __iar_builtin_UADD16
320 #define __UQADD16 __iar_builtin_UQADD16
321 #define __UHADD16 __iar_builtin_UHADD16
322 #define __SSUB16 __iar_builtin_SSUB16
323 #define __QSUB16 __iar_builtin_QSUB16
324 #define __SHSUB16 __iar_builtin_SHSUB16
325 #define __USUB16 __iar_builtin_USUB16
326 #define __UQSUB16 __iar_builtin_UQSUB16
327 #define __UHSUB16 __iar_builtin_UHSUB16
328 #define __SASX __iar_builtin_SASX
329 #define __QASX __iar_builtin_QASX
330 #define __SHASX __iar_builtin_SHASX
331 #define __UASX __iar_builtin_UASX
332 #define __UQASX __iar_builtin_UQASX
333 #define __UHASX __iar_builtin_UHASX
334 #define __SSAX __iar_builtin_SSAX
335 #define __QSAX __iar_builtin_QSAX
336 #define __SHSAX __iar_builtin_SHSAX
337 #define __USAX __iar_builtin_USAX
338 #define __UQSAX __iar_builtin_UQSAX
339 #define __UHSAX __iar_builtin_UHSAX
340 #define __USAD8 __iar_builtin_USAD8
341 #define __USADA8 __iar_builtin_USADA8
342 #define __SSAT16 __iar_builtin_SSAT16
343 #define __USAT16 __iar_builtin_USAT16
344 #define __UXTB16 __iar_builtin_UXTB16
345 #define __UXTAB16 __iar_builtin_UXTAB16
346 #define __SXTB16 __iar_builtin_SXTB16
347 #define __SXTAB16 __iar_builtin_SXTAB16
348 #define __SMUAD __iar_builtin_SMUAD
349 #define __SMUADX __iar_builtin_SMUADX
350 #define __SMMLA __iar_builtin_SMMLA
351 #define __SMLAD __iar_builtin_SMLAD
352 #define __SMLADX __iar_builtin_SMLADX
353 #define __SMLALD __iar_builtin_SMLALD
354 #define __SMLALDX __iar_builtin_SMLALDX
355 #define __SMUSD __iar_builtin_SMUSD
356 #define __SMUSDX __iar_builtin_SMUSDX
357 #define __SMLSD __iar_builtin_SMLSD
358 #define __SMLSDX __iar_builtin_SMLSDX
359 #define __SMLSLD __iar_builtin_SMLSLD
360 #define __SMLSLDX __iar_builtin_SMLSLDX
361 #define __SEL __iar_builtin_SEL
362 #define __QADD __iar_builtin_QADD
363 #define __QSUB __iar_builtin_QSUB
364 #define __PKHBT __iar_builtin_PKHBT
365 #define __PKHTB __iar_builtin_PKHTB
367 #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
370 #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
373 #ifdef __INTRINSICS_INCLUDED
374 #error intrinsics.h is already included previously!
377 #include <intrinsics.h>
380 #define __get_FPSCR() (0)
383 #pragma diag_suppress=Pe940
384 #pragma diag_suppress=Pe177
386 #define __enable_irq __enable_interrupt
387 #define __disable_irq __disable_interrupt
388 #define __enable_fault_irq __enable_fiq
389 #define __disable_fault_irq __disable_fiq
390 #define __NOP __no_operation
392 #define __get_xPSR __get_PSR
394 __IAR_FT void __set_mode(uint32_t mode)
396 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
399 __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
401 return __LDREX((unsigned long *)ptr);
404 __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
406 return __STREX(value, (unsigned long *)ptr);
410 __IAR_FT uint32_t __RRX(uint32_t value)
413 __ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc");
418 __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
420 return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
423 __IAR_FT uint32_t __get_FPEXC(void)
425 #if (__FPU_PRESENT == 1)
427 __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
434 __IAR_FT void __set_FPEXC(uint32_t fpexc)
436 #if (__FPU_PRESENT == 1)
437 __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
442 #define __get_CP(cp, op1, Rt, CRn, CRm, op2) \
443 __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
444 #define __set_CP(cp, op1, Rt, CRn, CRm, op2) \
445 __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
446 #define __get_CP64(cp, op1, Rt, CRm) \
447 __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
448 #define __set_CP64(cp, op1, Rt, CRm) \
449 __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
451 #include "cmsis_cp15.h"
453 #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
455 #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
458 __IAR_FT uint32_t __get_SP_usr(void)
464 "CPS #0x1F \n" // no effect in USR mode
466 "MSR cpsr_c, %2 \n" // no effect in USR mode
467 "ISB" : "=r"(cpsr), "=r"(result) : "r"(cpsr) : "memory"
472 __IAR_FT void __set_SP_usr(uint32_t topOfProcStack)
477 "CPS #0x1F \n" // no effect in USR mode
479 "MSR cpsr_c, %2 \n" // no effect in USR mode
480 "ISB" : "=r"(cpsr) : "r" (topOfProcStack), "r"(cpsr) : "memory"
484 #define __get_mode() (__get_CPSR() & 0x1FU)
487 void __FPU_Enable(void)
490 //Permit access to VFP/NEON, registers by modifying CPACR
491 " MRC p15,0,R1,c1,c0,2 \n"
492 " ORR R1,R1,#0x00F00000 \n"
493 " MCR p15,0,R1,c1,c0,2 \n"
495 //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
500 " ORR R1,R1,#0x40000000 \n"
503 //Initialise VFP/NEON registers to 0
506 //Initialise D16 registers to 0
524 #ifdef __ARM_ADVANCED_SIMD__
525 //Initialise D32 registers to 0
544 //Initialise FPSCR to a known state
546 " MOV32 R3,#0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
548 " VMSR FPSCR,R2 \n");
556 #pragma diag_default=Pe940
557 #pragma diag_default=Pe177
559 #endif /* __CMSIS_ICCARM_H__ */