xref: /btstack/port/stm32-f4discovery-usb/Drivers/CMSIS/Include/cmsis_iccarm.h (revision a8f7f3fcbcd51f8d2e92aca076b6a9f812db358c)
1*a8f7f3fcSMatthias Ringwald /**************************************************************************//**
2*a8f7f3fcSMatthias Ringwald  * @file     cmsis_iccarm.h
3*a8f7f3fcSMatthias Ringwald  * @brief    CMSIS compiler ICCARM (IAR Compiler for Arm) header file
4*a8f7f3fcSMatthias Ringwald  * @version  V5.0.7
5*a8f7f3fcSMatthias Ringwald  * @date     19. June 2018
6*a8f7f3fcSMatthias Ringwald  ******************************************************************************/
7*a8f7f3fcSMatthias Ringwald 
8*a8f7f3fcSMatthias Ringwald //------------------------------------------------------------------------------
9*a8f7f3fcSMatthias Ringwald //
10*a8f7f3fcSMatthias Ringwald // Copyright (c) 2017-2018 IAR Systems
11*a8f7f3fcSMatthias Ringwald //
12*a8f7f3fcSMatthias Ringwald // Licensed under the Apache License, Version 2.0 (the "License")
13*a8f7f3fcSMatthias Ringwald // you may 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 //     http://www.apache.org/licenses/LICENSE-2.0
16*a8f7f3fcSMatthias Ringwald //
17*a8f7f3fcSMatthias Ringwald // Unless required by applicable law or agreed to in writing, software
18*a8f7f3fcSMatthias Ringwald // distributed under the License is distributed on an "AS IS" BASIS,
19*a8f7f3fcSMatthias Ringwald // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20*a8f7f3fcSMatthias Ringwald // See the License for the specific language governing permissions and
21*a8f7f3fcSMatthias Ringwald // limitations under the License.
22*a8f7f3fcSMatthias Ringwald //
23*a8f7f3fcSMatthias Ringwald //------------------------------------------------------------------------------
24*a8f7f3fcSMatthias Ringwald 
25*a8f7f3fcSMatthias Ringwald 
26*a8f7f3fcSMatthias Ringwald #ifndef __CMSIS_ICCARM_H__
27*a8f7f3fcSMatthias Ringwald #define __CMSIS_ICCARM_H__
28*a8f7f3fcSMatthias Ringwald 
29*a8f7f3fcSMatthias Ringwald #ifndef __ICCARM__
30*a8f7f3fcSMatthias Ringwald   #error This file should only be compiled by ICCARM
31*a8f7f3fcSMatthias Ringwald #endif
32*a8f7f3fcSMatthias Ringwald 
33*a8f7f3fcSMatthias Ringwald #pragma system_include
34*a8f7f3fcSMatthias Ringwald 
35*a8f7f3fcSMatthias Ringwald #define __IAR_FT _Pragma("inline=forced") __intrinsic
36*a8f7f3fcSMatthias Ringwald 
37*a8f7f3fcSMatthias Ringwald #if (__VER__ >= 8000000)
38*a8f7f3fcSMatthias Ringwald   #define __ICCARM_V8 1
39*a8f7f3fcSMatthias Ringwald #else
40*a8f7f3fcSMatthias Ringwald   #define __ICCARM_V8 0
41*a8f7f3fcSMatthias Ringwald #endif
42*a8f7f3fcSMatthias Ringwald 
43*a8f7f3fcSMatthias Ringwald #ifndef __ALIGNED
44*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
45*a8f7f3fcSMatthias Ringwald     #define __ALIGNED(x) __attribute__((aligned(x)))
46*a8f7f3fcSMatthias Ringwald   #elif (__VER__ >= 7080000)
47*a8f7f3fcSMatthias Ringwald     /* Needs IAR language extensions */
48*a8f7f3fcSMatthias Ringwald     #define __ALIGNED(x) __attribute__((aligned(x)))
49*a8f7f3fcSMatthias Ringwald   #else
50*a8f7f3fcSMatthias Ringwald     #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
51*a8f7f3fcSMatthias Ringwald     #define __ALIGNED(x)
52*a8f7f3fcSMatthias Ringwald   #endif
53*a8f7f3fcSMatthias Ringwald #endif
54*a8f7f3fcSMatthias Ringwald 
55*a8f7f3fcSMatthias Ringwald 
56*a8f7f3fcSMatthias Ringwald /* Define compiler macros for CPU architecture, used in CMSIS 5.
57*a8f7f3fcSMatthias Ringwald  */
58*a8f7f3fcSMatthias Ringwald #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
59*a8f7f3fcSMatthias Ringwald /* Macros already defined */
60*a8f7f3fcSMatthias Ringwald #else
61*a8f7f3fcSMatthias Ringwald   #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
62*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_8M_MAIN__ 1
63*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM8M_BASELINE__)
64*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_8M_BASE__ 1
65*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
66*a8f7f3fcSMatthias Ringwald     #if __ARM_ARCH == 6
67*a8f7f3fcSMatthias Ringwald       #define __ARM_ARCH_6M__ 1
68*a8f7f3fcSMatthias Ringwald     #elif __ARM_ARCH == 7
69*a8f7f3fcSMatthias Ringwald       #if __ARM_FEATURE_DSP
70*a8f7f3fcSMatthias Ringwald         #define __ARM_ARCH_7EM__ 1
71*a8f7f3fcSMatthias Ringwald       #else
72*a8f7f3fcSMatthias Ringwald         #define __ARM_ARCH_7M__ 1
73*a8f7f3fcSMatthias Ringwald       #endif
74*a8f7f3fcSMatthias Ringwald     #endif /* __ARM_ARCH */
75*a8f7f3fcSMatthias Ringwald   #endif /* __ARM_ARCH_PROFILE == 'M' */
76*a8f7f3fcSMatthias Ringwald #endif
77*a8f7f3fcSMatthias Ringwald 
78*a8f7f3fcSMatthias Ringwald /* Alternativ core deduction for older ICCARM's */
79*a8f7f3fcSMatthias Ringwald #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
80*a8f7f3fcSMatthias Ringwald     !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
81*a8f7f3fcSMatthias Ringwald   #if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
82*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_6M__ 1
83*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
84*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_7M__ 1
85*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
86*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_7EM__  1
87*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
88*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_8M_BASE__ 1
89*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
90*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_8M_MAIN__ 1
91*a8f7f3fcSMatthias Ringwald   #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
92*a8f7f3fcSMatthias Ringwald     #define __ARM_ARCH_8M_MAIN__ 1
93*a8f7f3fcSMatthias Ringwald   #else
94*a8f7f3fcSMatthias Ringwald     #error "Unknown target."
95*a8f7f3fcSMatthias Ringwald   #endif
96*a8f7f3fcSMatthias Ringwald #endif
97*a8f7f3fcSMatthias Ringwald 
98*a8f7f3fcSMatthias Ringwald 
99*a8f7f3fcSMatthias Ringwald 
100*a8f7f3fcSMatthias Ringwald #if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
101*a8f7f3fcSMatthias Ringwald   #define __IAR_M0_FAMILY  1
102*a8f7f3fcSMatthias Ringwald #elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
103*a8f7f3fcSMatthias Ringwald   #define __IAR_M0_FAMILY  1
104*a8f7f3fcSMatthias Ringwald #else
105*a8f7f3fcSMatthias Ringwald   #define __IAR_M0_FAMILY  0
106*a8f7f3fcSMatthias Ringwald #endif
107*a8f7f3fcSMatthias Ringwald 
108*a8f7f3fcSMatthias Ringwald 
109*a8f7f3fcSMatthias Ringwald #ifndef __ASM
110*a8f7f3fcSMatthias Ringwald   #define __ASM __asm
111*a8f7f3fcSMatthias Ringwald #endif
112*a8f7f3fcSMatthias Ringwald 
113*a8f7f3fcSMatthias Ringwald #ifndef __INLINE
114*a8f7f3fcSMatthias Ringwald   #define __INLINE inline
115*a8f7f3fcSMatthias Ringwald #endif
116*a8f7f3fcSMatthias Ringwald 
117*a8f7f3fcSMatthias Ringwald #ifndef   __NO_RETURN
118*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
119*a8f7f3fcSMatthias Ringwald     #define __NO_RETURN __attribute__((__noreturn__))
120*a8f7f3fcSMatthias Ringwald   #else
121*a8f7f3fcSMatthias Ringwald     #define __NO_RETURN _Pragma("object_attribute=__noreturn")
122*a8f7f3fcSMatthias Ringwald   #endif
123*a8f7f3fcSMatthias Ringwald #endif
124*a8f7f3fcSMatthias Ringwald 
125*a8f7f3fcSMatthias Ringwald #ifndef   __PACKED
126*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
127*a8f7f3fcSMatthias Ringwald     #define __PACKED __attribute__((packed, aligned(1)))
128*a8f7f3fcSMatthias Ringwald   #else
129*a8f7f3fcSMatthias Ringwald     /* Needs IAR language extensions */
130*a8f7f3fcSMatthias Ringwald     #define __PACKED __packed
131*a8f7f3fcSMatthias Ringwald   #endif
132*a8f7f3fcSMatthias Ringwald #endif
133*a8f7f3fcSMatthias Ringwald 
134*a8f7f3fcSMatthias Ringwald #ifndef   __PACKED_STRUCT
135*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
136*a8f7f3fcSMatthias Ringwald     #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
137*a8f7f3fcSMatthias Ringwald   #else
138*a8f7f3fcSMatthias Ringwald     /* Needs IAR language extensions */
139*a8f7f3fcSMatthias Ringwald     #define __PACKED_STRUCT __packed struct
140*a8f7f3fcSMatthias Ringwald   #endif
141*a8f7f3fcSMatthias Ringwald #endif
142*a8f7f3fcSMatthias Ringwald 
143*a8f7f3fcSMatthias Ringwald #ifndef   __PACKED_UNION
144*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
145*a8f7f3fcSMatthias Ringwald     #define __PACKED_UNION union __attribute__((packed, aligned(1)))
146*a8f7f3fcSMatthias Ringwald   #else
147*a8f7f3fcSMatthias Ringwald     /* Needs IAR language extensions */
148*a8f7f3fcSMatthias Ringwald     #define __PACKED_UNION __packed union
149*a8f7f3fcSMatthias Ringwald   #endif
150*a8f7f3fcSMatthias Ringwald #endif
151*a8f7f3fcSMatthias Ringwald 
152*a8f7f3fcSMatthias Ringwald #ifndef   __RESTRICT
153*a8f7f3fcSMatthias Ringwald   #define __RESTRICT            __restrict
154*a8f7f3fcSMatthias Ringwald #endif
155*a8f7f3fcSMatthias Ringwald 
156*a8f7f3fcSMatthias Ringwald #ifndef   __STATIC_INLINE
157*a8f7f3fcSMatthias Ringwald   #define __STATIC_INLINE       static inline
158*a8f7f3fcSMatthias Ringwald #endif
159*a8f7f3fcSMatthias Ringwald 
160*a8f7f3fcSMatthias Ringwald #ifndef   __FORCEINLINE
161*a8f7f3fcSMatthias Ringwald   #define __FORCEINLINE         _Pragma("inline=forced")
162*a8f7f3fcSMatthias Ringwald #endif
163*a8f7f3fcSMatthias Ringwald 
164*a8f7f3fcSMatthias Ringwald #ifndef   __STATIC_FORCEINLINE
165*a8f7f3fcSMatthias Ringwald   #define __STATIC_FORCEINLINE  __FORCEINLINE __STATIC_INLINE
166*a8f7f3fcSMatthias Ringwald #endif
167*a8f7f3fcSMatthias Ringwald 
168*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_READ
169*a8f7f3fcSMatthias Ringwald #pragma language=save
170*a8f7f3fcSMatthias Ringwald #pragma language=extended
__iar_uint16_read(void const * ptr)171*a8f7f3fcSMatthias Ringwald __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
172*a8f7f3fcSMatthias Ringwald {
173*a8f7f3fcSMatthias Ringwald   return *(__packed uint16_t*)(ptr);
174*a8f7f3fcSMatthias Ringwald }
175*a8f7f3fcSMatthias Ringwald #pragma language=restore
176*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
177*a8f7f3fcSMatthias Ringwald #endif
178*a8f7f3fcSMatthias Ringwald 
179*a8f7f3fcSMatthias Ringwald 
180*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_WRITE
181*a8f7f3fcSMatthias Ringwald #pragma language=save
182*a8f7f3fcSMatthias Ringwald #pragma language=extended
__iar_uint16_write(void const * ptr,uint16_t val)183*a8f7f3fcSMatthias Ringwald __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
184*a8f7f3fcSMatthias Ringwald {
185*a8f7f3fcSMatthias Ringwald   *(__packed uint16_t*)(ptr) = val;;
186*a8f7f3fcSMatthias Ringwald }
187*a8f7f3fcSMatthias Ringwald #pragma language=restore
188*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
189*a8f7f3fcSMatthias Ringwald #endif
190*a8f7f3fcSMatthias Ringwald 
191*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_READ
192*a8f7f3fcSMatthias Ringwald #pragma language=save
193*a8f7f3fcSMatthias Ringwald #pragma language=extended
__iar_uint32_read(void const * ptr)194*a8f7f3fcSMatthias Ringwald __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
195*a8f7f3fcSMatthias Ringwald {
196*a8f7f3fcSMatthias Ringwald   return *(__packed uint32_t*)(ptr);
197*a8f7f3fcSMatthias Ringwald }
198*a8f7f3fcSMatthias Ringwald #pragma language=restore
199*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
200*a8f7f3fcSMatthias Ringwald #endif
201*a8f7f3fcSMatthias Ringwald 
202*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_WRITE
203*a8f7f3fcSMatthias Ringwald #pragma language=save
204*a8f7f3fcSMatthias Ringwald #pragma language=extended
__iar_uint32_write(void const * ptr,uint32_t val)205*a8f7f3fcSMatthias Ringwald __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
206*a8f7f3fcSMatthias Ringwald {
207*a8f7f3fcSMatthias Ringwald   *(__packed uint32_t*)(ptr) = val;;
208*a8f7f3fcSMatthias Ringwald }
209*a8f7f3fcSMatthias Ringwald #pragma language=restore
210*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
211*a8f7f3fcSMatthias Ringwald #endif
212*a8f7f3fcSMatthias Ringwald 
213*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32   /* deprecated */
214*a8f7f3fcSMatthias Ringwald #pragma language=save
215*a8f7f3fcSMatthias Ringwald #pragma language=extended
216*a8f7f3fcSMatthias Ringwald __packed struct  __iar_u32 { uint32_t v; };
217*a8f7f3fcSMatthias Ringwald #pragma language=restore
218*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
219*a8f7f3fcSMatthias Ringwald #endif
220*a8f7f3fcSMatthias Ringwald 
221*a8f7f3fcSMatthias Ringwald #ifndef   __USED
222*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
223*a8f7f3fcSMatthias Ringwald     #define __USED __attribute__((used))
224*a8f7f3fcSMatthias Ringwald   #else
225*a8f7f3fcSMatthias Ringwald     #define __USED _Pragma("__root")
226*a8f7f3fcSMatthias Ringwald   #endif
227*a8f7f3fcSMatthias Ringwald #endif
228*a8f7f3fcSMatthias Ringwald 
229*a8f7f3fcSMatthias Ringwald #ifndef   __WEAK
230*a8f7f3fcSMatthias Ringwald   #if __ICCARM_V8
231*a8f7f3fcSMatthias Ringwald     #define __WEAK __attribute__((weak))
232*a8f7f3fcSMatthias Ringwald   #else
233*a8f7f3fcSMatthias Ringwald     #define __WEAK _Pragma("__weak")
234*a8f7f3fcSMatthias Ringwald   #endif
235*a8f7f3fcSMatthias Ringwald #endif
236*a8f7f3fcSMatthias Ringwald 
237*a8f7f3fcSMatthias Ringwald 
238*a8f7f3fcSMatthias Ringwald #ifndef __ICCARM_INTRINSICS_VERSION__
239*a8f7f3fcSMatthias Ringwald   #define __ICCARM_INTRINSICS_VERSION__  0
240*a8f7f3fcSMatthias Ringwald #endif
241*a8f7f3fcSMatthias Ringwald 
242*a8f7f3fcSMatthias Ringwald #if __ICCARM_INTRINSICS_VERSION__ == 2
243*a8f7f3fcSMatthias Ringwald 
244*a8f7f3fcSMatthias Ringwald   #if defined(__CLZ)
245*a8f7f3fcSMatthias Ringwald     #undef __CLZ
246*a8f7f3fcSMatthias Ringwald   #endif
247*a8f7f3fcSMatthias Ringwald   #if defined(__REVSH)
248*a8f7f3fcSMatthias Ringwald     #undef __REVSH
249*a8f7f3fcSMatthias Ringwald   #endif
250*a8f7f3fcSMatthias Ringwald   #if defined(__RBIT)
251*a8f7f3fcSMatthias Ringwald     #undef __RBIT
252*a8f7f3fcSMatthias Ringwald   #endif
253*a8f7f3fcSMatthias Ringwald   #if defined(__SSAT)
254*a8f7f3fcSMatthias Ringwald     #undef __SSAT
255*a8f7f3fcSMatthias Ringwald   #endif
256*a8f7f3fcSMatthias Ringwald   #if defined(__USAT)
257*a8f7f3fcSMatthias Ringwald     #undef __USAT
258*a8f7f3fcSMatthias Ringwald   #endif
259*a8f7f3fcSMatthias Ringwald 
260*a8f7f3fcSMatthias Ringwald   #include "iccarm_builtin.h"
261*a8f7f3fcSMatthias Ringwald 
262*a8f7f3fcSMatthias Ringwald   #define __disable_fault_irq __iar_builtin_disable_fiq
263*a8f7f3fcSMatthias Ringwald   #define __disable_irq       __iar_builtin_disable_interrupt
264*a8f7f3fcSMatthias Ringwald   #define __enable_fault_irq  __iar_builtin_enable_fiq
265*a8f7f3fcSMatthias Ringwald   #define __enable_irq        __iar_builtin_enable_interrupt
266*a8f7f3fcSMatthias Ringwald   #define __arm_rsr           __iar_builtin_rsr
267*a8f7f3fcSMatthias Ringwald   #define __arm_wsr           __iar_builtin_wsr
268*a8f7f3fcSMatthias Ringwald 
269*a8f7f3fcSMatthias Ringwald 
270*a8f7f3fcSMatthias Ringwald   #define __get_APSR()                (__arm_rsr("APSR"))
271*a8f7f3fcSMatthias Ringwald   #define __get_BASEPRI()             (__arm_rsr("BASEPRI"))
272*a8f7f3fcSMatthias Ringwald   #define __get_CONTROL()             (__arm_rsr("CONTROL"))
273*a8f7f3fcSMatthias Ringwald   #define __get_FAULTMASK()           (__arm_rsr("FAULTMASK"))
274*a8f7f3fcSMatthias Ringwald 
275*a8f7f3fcSMatthias Ringwald   #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
276*a8f7f3fcSMatthias Ringwald        (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     )
277*a8f7f3fcSMatthias Ringwald     #define __get_FPSCR()             (__arm_rsr("FPSCR"))
278*a8f7f3fcSMatthias Ringwald     #define __set_FPSCR(VALUE)        (__arm_wsr("FPSCR", (VALUE)))
279*a8f7f3fcSMatthias Ringwald   #else
280*a8f7f3fcSMatthias Ringwald     #define __get_FPSCR()             ( 0 )
281*a8f7f3fcSMatthias Ringwald     #define __set_FPSCR(VALUE)        ((void)VALUE)
282*a8f7f3fcSMatthias Ringwald   #endif
283*a8f7f3fcSMatthias Ringwald 
284*a8f7f3fcSMatthias Ringwald   #define __get_IPSR()                (__arm_rsr("IPSR"))
285*a8f7f3fcSMatthias Ringwald   #define __get_MSP()                 (__arm_rsr("MSP"))
286*a8f7f3fcSMatthias Ringwald   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
287*a8f7f3fcSMatthias Ringwald        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
288*a8f7f3fcSMatthias Ringwald     // without main extensions, the non-secure MSPLIM is RAZ/WI
289*a8f7f3fcSMatthias Ringwald     #define __get_MSPLIM()            (0U)
290*a8f7f3fcSMatthias Ringwald   #else
291*a8f7f3fcSMatthias Ringwald     #define __get_MSPLIM()            (__arm_rsr("MSPLIM"))
292*a8f7f3fcSMatthias Ringwald   #endif
293*a8f7f3fcSMatthias Ringwald   #define __get_PRIMASK()             (__arm_rsr("PRIMASK"))
294*a8f7f3fcSMatthias Ringwald   #define __get_PSP()                 (__arm_rsr("PSP"))
295*a8f7f3fcSMatthias Ringwald 
296*a8f7f3fcSMatthias Ringwald   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
297*a8f7f3fcSMatthias Ringwald        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
298*a8f7f3fcSMatthias Ringwald     // without main extensions, the non-secure PSPLIM is RAZ/WI
299*a8f7f3fcSMatthias Ringwald     #define __get_PSPLIM()            (0U)
300*a8f7f3fcSMatthias Ringwald   #else
301*a8f7f3fcSMatthias Ringwald     #define __get_PSPLIM()            (__arm_rsr("PSPLIM"))
302*a8f7f3fcSMatthias Ringwald   #endif
303*a8f7f3fcSMatthias Ringwald 
304*a8f7f3fcSMatthias Ringwald   #define __get_xPSR()                (__arm_rsr("xPSR"))
305*a8f7f3fcSMatthias Ringwald 
306*a8f7f3fcSMatthias Ringwald   #define __set_BASEPRI(VALUE)        (__arm_wsr("BASEPRI", (VALUE)))
307*a8f7f3fcSMatthias Ringwald   #define __set_BASEPRI_MAX(VALUE)    (__arm_wsr("BASEPRI_MAX", (VALUE)))
308*a8f7f3fcSMatthias Ringwald   #define __set_CONTROL(VALUE)        (__arm_wsr("CONTROL", (VALUE)))
309*a8f7f3fcSMatthias Ringwald   #define __set_FAULTMASK(VALUE)      (__arm_wsr("FAULTMASK", (VALUE)))
310*a8f7f3fcSMatthias Ringwald   #define __set_MSP(VALUE)            (__arm_wsr("MSP", (VALUE)))
311*a8f7f3fcSMatthias Ringwald 
312*a8f7f3fcSMatthias Ringwald   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
313*a8f7f3fcSMatthias Ringwald        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
314*a8f7f3fcSMatthias Ringwald     // without main extensions, the non-secure MSPLIM is RAZ/WI
315*a8f7f3fcSMatthias Ringwald     #define __set_MSPLIM(VALUE)       ((void)(VALUE))
316*a8f7f3fcSMatthias Ringwald   #else
317*a8f7f3fcSMatthias Ringwald     #define __set_MSPLIM(VALUE)       (__arm_wsr("MSPLIM", (VALUE)))
318*a8f7f3fcSMatthias Ringwald   #endif
319*a8f7f3fcSMatthias Ringwald   #define __set_PRIMASK(VALUE)        (__arm_wsr("PRIMASK", (VALUE)))
320*a8f7f3fcSMatthias Ringwald   #define __set_PSP(VALUE)            (__arm_wsr("PSP", (VALUE)))
321*a8f7f3fcSMatthias Ringwald   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
322*a8f7f3fcSMatthias Ringwald        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
323*a8f7f3fcSMatthias Ringwald     // without main extensions, the non-secure PSPLIM is RAZ/WI
324*a8f7f3fcSMatthias Ringwald     #define __set_PSPLIM(VALUE)       ((void)(VALUE))
325*a8f7f3fcSMatthias Ringwald   #else
326*a8f7f3fcSMatthias Ringwald     #define __set_PSPLIM(VALUE)       (__arm_wsr("PSPLIM", (VALUE)))
327*a8f7f3fcSMatthias Ringwald   #endif
328*a8f7f3fcSMatthias Ringwald 
329*a8f7f3fcSMatthias Ringwald   #define __TZ_get_CONTROL_NS()       (__arm_rsr("CONTROL_NS"))
330*a8f7f3fcSMatthias Ringwald   #define __TZ_set_CONTROL_NS(VALUE)  (__arm_wsr("CONTROL_NS", (VALUE)))
331*a8f7f3fcSMatthias Ringwald   #define __TZ_get_PSP_NS()           (__arm_rsr("PSP_NS"))
332*a8f7f3fcSMatthias Ringwald   #define __TZ_set_PSP_NS(VALUE)      (__arm_wsr("PSP_NS", (VALUE)))
333*a8f7f3fcSMatthias Ringwald   #define __TZ_get_MSP_NS()           (__arm_rsr("MSP_NS"))
334*a8f7f3fcSMatthias Ringwald   #define __TZ_set_MSP_NS(VALUE)      (__arm_wsr("MSP_NS", (VALUE)))
335*a8f7f3fcSMatthias Ringwald   #define __TZ_get_SP_NS()            (__arm_rsr("SP_NS"))
336*a8f7f3fcSMatthias Ringwald   #define __TZ_set_SP_NS(VALUE)       (__arm_wsr("SP_NS", (VALUE)))
337*a8f7f3fcSMatthias Ringwald   #define __TZ_get_PRIMASK_NS()       (__arm_rsr("PRIMASK_NS"))
338*a8f7f3fcSMatthias Ringwald   #define __TZ_set_PRIMASK_NS(VALUE)  (__arm_wsr("PRIMASK_NS", (VALUE)))
339*a8f7f3fcSMatthias Ringwald   #define __TZ_get_BASEPRI_NS()       (__arm_rsr("BASEPRI_NS"))
340*a8f7f3fcSMatthias Ringwald   #define __TZ_set_BASEPRI_NS(VALUE)  (__arm_wsr("BASEPRI_NS", (VALUE)))
341*a8f7f3fcSMatthias Ringwald   #define __TZ_get_FAULTMASK_NS()     (__arm_rsr("FAULTMASK_NS"))
342*a8f7f3fcSMatthias Ringwald   #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
343*a8f7f3fcSMatthias Ringwald 
344*a8f7f3fcSMatthias Ringwald   #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
345*a8f7f3fcSMatthias Ringwald        (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
346*a8f7f3fcSMatthias Ringwald     // without main extensions, the non-secure PSPLIM is RAZ/WI
347*a8f7f3fcSMatthias Ringwald     #define __TZ_get_PSPLIM_NS()      (0U)
348*a8f7f3fcSMatthias Ringwald     #define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE))
349*a8f7f3fcSMatthias Ringwald   #else
350*a8f7f3fcSMatthias Ringwald     #define __TZ_get_PSPLIM_NS()      (__arm_rsr("PSPLIM_NS"))
351*a8f7f3fcSMatthias Ringwald     #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE)))
352*a8f7f3fcSMatthias Ringwald   #endif
353*a8f7f3fcSMatthias Ringwald 
354*a8f7f3fcSMatthias Ringwald   #define __TZ_get_MSPLIM_NS()        (__arm_rsr("MSPLIM_NS"))
355*a8f7f3fcSMatthias Ringwald   #define __TZ_set_MSPLIM_NS(VALUE)   (__arm_wsr("MSPLIM_NS", (VALUE)))
356*a8f7f3fcSMatthias Ringwald 
357*a8f7f3fcSMatthias Ringwald   #define __NOP     __iar_builtin_no_operation
358*a8f7f3fcSMatthias Ringwald 
359*a8f7f3fcSMatthias Ringwald   #define __CLZ     __iar_builtin_CLZ
360*a8f7f3fcSMatthias Ringwald   #define __CLREX   __iar_builtin_CLREX
361*a8f7f3fcSMatthias Ringwald 
362*a8f7f3fcSMatthias Ringwald   #define __DMB     __iar_builtin_DMB
363*a8f7f3fcSMatthias Ringwald   #define __DSB     __iar_builtin_DSB
364*a8f7f3fcSMatthias Ringwald   #define __ISB     __iar_builtin_ISB
365*a8f7f3fcSMatthias Ringwald 
366*a8f7f3fcSMatthias Ringwald   #define __LDREXB  __iar_builtin_LDREXB
367*a8f7f3fcSMatthias Ringwald   #define __LDREXH  __iar_builtin_LDREXH
368*a8f7f3fcSMatthias Ringwald   #define __LDREXW  __iar_builtin_LDREX
369*a8f7f3fcSMatthias Ringwald 
370*a8f7f3fcSMatthias Ringwald   #define __RBIT    __iar_builtin_RBIT
371*a8f7f3fcSMatthias Ringwald   #define __REV     __iar_builtin_REV
372*a8f7f3fcSMatthias Ringwald   #define __REV16   __iar_builtin_REV16
373*a8f7f3fcSMatthias Ringwald 
__REVSH(int16_t val)374*a8f7f3fcSMatthias Ringwald   __IAR_FT int16_t __REVSH(int16_t val)
375*a8f7f3fcSMatthias Ringwald   {
376*a8f7f3fcSMatthias Ringwald     return (int16_t) __iar_builtin_REVSH(val);
377*a8f7f3fcSMatthias Ringwald   }
378*a8f7f3fcSMatthias Ringwald 
379*a8f7f3fcSMatthias Ringwald   #define __ROR     __iar_builtin_ROR
380*a8f7f3fcSMatthias Ringwald   #define __RRX     __iar_builtin_RRX
381*a8f7f3fcSMatthias Ringwald 
382*a8f7f3fcSMatthias Ringwald   #define __SEV     __iar_builtin_SEV
383*a8f7f3fcSMatthias Ringwald 
384*a8f7f3fcSMatthias Ringwald   #if !__IAR_M0_FAMILY
385*a8f7f3fcSMatthias Ringwald     #define __SSAT    __iar_builtin_SSAT
386*a8f7f3fcSMatthias Ringwald   #endif
387*a8f7f3fcSMatthias Ringwald 
388*a8f7f3fcSMatthias Ringwald   #define __STREXB  __iar_builtin_STREXB
389*a8f7f3fcSMatthias Ringwald   #define __STREXH  __iar_builtin_STREXH
390*a8f7f3fcSMatthias Ringwald   #define __STREXW  __iar_builtin_STREX
391*a8f7f3fcSMatthias Ringwald 
392*a8f7f3fcSMatthias Ringwald   #if !__IAR_M0_FAMILY
393*a8f7f3fcSMatthias Ringwald     #define __USAT    __iar_builtin_USAT
394*a8f7f3fcSMatthias Ringwald   #endif
395*a8f7f3fcSMatthias Ringwald 
396*a8f7f3fcSMatthias Ringwald   #define __WFE     __iar_builtin_WFE
397*a8f7f3fcSMatthias Ringwald   #define __WFI     __iar_builtin_WFI
398*a8f7f3fcSMatthias Ringwald 
399*a8f7f3fcSMatthias Ringwald   #if __ARM_MEDIA__
400*a8f7f3fcSMatthias Ringwald     #define __SADD8   __iar_builtin_SADD8
401*a8f7f3fcSMatthias Ringwald     #define __QADD8   __iar_builtin_QADD8
402*a8f7f3fcSMatthias Ringwald     #define __SHADD8  __iar_builtin_SHADD8
403*a8f7f3fcSMatthias Ringwald     #define __UADD8   __iar_builtin_UADD8
404*a8f7f3fcSMatthias Ringwald     #define __UQADD8  __iar_builtin_UQADD8
405*a8f7f3fcSMatthias Ringwald     #define __UHADD8  __iar_builtin_UHADD8
406*a8f7f3fcSMatthias Ringwald     #define __SSUB8   __iar_builtin_SSUB8
407*a8f7f3fcSMatthias Ringwald     #define __QSUB8   __iar_builtin_QSUB8
408*a8f7f3fcSMatthias Ringwald     #define __SHSUB8  __iar_builtin_SHSUB8
409*a8f7f3fcSMatthias Ringwald     #define __USUB8   __iar_builtin_USUB8
410*a8f7f3fcSMatthias Ringwald     #define __UQSUB8  __iar_builtin_UQSUB8
411*a8f7f3fcSMatthias Ringwald     #define __UHSUB8  __iar_builtin_UHSUB8
412*a8f7f3fcSMatthias Ringwald     #define __SADD16  __iar_builtin_SADD16
413*a8f7f3fcSMatthias Ringwald     #define __QADD16  __iar_builtin_QADD16
414*a8f7f3fcSMatthias Ringwald     #define __SHADD16 __iar_builtin_SHADD16
415*a8f7f3fcSMatthias Ringwald     #define __UADD16  __iar_builtin_UADD16
416*a8f7f3fcSMatthias Ringwald     #define __UQADD16 __iar_builtin_UQADD16
417*a8f7f3fcSMatthias Ringwald     #define __UHADD16 __iar_builtin_UHADD16
418*a8f7f3fcSMatthias Ringwald     #define __SSUB16  __iar_builtin_SSUB16
419*a8f7f3fcSMatthias Ringwald     #define __QSUB16  __iar_builtin_QSUB16
420*a8f7f3fcSMatthias Ringwald     #define __SHSUB16 __iar_builtin_SHSUB16
421*a8f7f3fcSMatthias Ringwald     #define __USUB16  __iar_builtin_USUB16
422*a8f7f3fcSMatthias Ringwald     #define __UQSUB16 __iar_builtin_UQSUB16
423*a8f7f3fcSMatthias Ringwald     #define __UHSUB16 __iar_builtin_UHSUB16
424*a8f7f3fcSMatthias Ringwald     #define __SASX    __iar_builtin_SASX
425*a8f7f3fcSMatthias Ringwald     #define __QASX    __iar_builtin_QASX
426*a8f7f3fcSMatthias Ringwald     #define __SHASX   __iar_builtin_SHASX
427*a8f7f3fcSMatthias Ringwald     #define __UASX    __iar_builtin_UASX
428*a8f7f3fcSMatthias Ringwald     #define __UQASX   __iar_builtin_UQASX
429*a8f7f3fcSMatthias Ringwald     #define __UHASX   __iar_builtin_UHASX
430*a8f7f3fcSMatthias Ringwald     #define __SSAX    __iar_builtin_SSAX
431*a8f7f3fcSMatthias Ringwald     #define __QSAX    __iar_builtin_QSAX
432*a8f7f3fcSMatthias Ringwald     #define __SHSAX   __iar_builtin_SHSAX
433*a8f7f3fcSMatthias Ringwald     #define __USAX    __iar_builtin_USAX
434*a8f7f3fcSMatthias Ringwald     #define __UQSAX   __iar_builtin_UQSAX
435*a8f7f3fcSMatthias Ringwald     #define __UHSAX   __iar_builtin_UHSAX
436*a8f7f3fcSMatthias Ringwald     #define __USAD8   __iar_builtin_USAD8
437*a8f7f3fcSMatthias Ringwald     #define __USADA8  __iar_builtin_USADA8
438*a8f7f3fcSMatthias Ringwald     #define __SSAT16  __iar_builtin_SSAT16
439*a8f7f3fcSMatthias Ringwald     #define __USAT16  __iar_builtin_USAT16
440*a8f7f3fcSMatthias Ringwald     #define __UXTB16  __iar_builtin_UXTB16
441*a8f7f3fcSMatthias Ringwald     #define __UXTAB16 __iar_builtin_UXTAB16
442*a8f7f3fcSMatthias Ringwald     #define __SXTB16  __iar_builtin_SXTB16
443*a8f7f3fcSMatthias Ringwald     #define __SXTAB16 __iar_builtin_SXTAB16
444*a8f7f3fcSMatthias Ringwald     #define __SMUAD   __iar_builtin_SMUAD
445*a8f7f3fcSMatthias Ringwald     #define __SMUADX  __iar_builtin_SMUADX
446*a8f7f3fcSMatthias Ringwald     #define __SMMLA   __iar_builtin_SMMLA
447*a8f7f3fcSMatthias Ringwald     #define __SMLAD   __iar_builtin_SMLAD
448*a8f7f3fcSMatthias Ringwald     #define __SMLADX  __iar_builtin_SMLADX
449*a8f7f3fcSMatthias Ringwald     #define __SMLALD  __iar_builtin_SMLALD
450*a8f7f3fcSMatthias Ringwald     #define __SMLALDX __iar_builtin_SMLALDX
451*a8f7f3fcSMatthias Ringwald     #define __SMUSD   __iar_builtin_SMUSD
452*a8f7f3fcSMatthias Ringwald     #define __SMUSDX  __iar_builtin_SMUSDX
453*a8f7f3fcSMatthias Ringwald     #define __SMLSD   __iar_builtin_SMLSD
454*a8f7f3fcSMatthias Ringwald     #define __SMLSDX  __iar_builtin_SMLSDX
455*a8f7f3fcSMatthias Ringwald     #define __SMLSLD  __iar_builtin_SMLSLD
456*a8f7f3fcSMatthias Ringwald     #define __SMLSLDX __iar_builtin_SMLSLDX
457*a8f7f3fcSMatthias Ringwald     #define __SEL     __iar_builtin_SEL
458*a8f7f3fcSMatthias Ringwald     #define __QADD    __iar_builtin_QADD
459*a8f7f3fcSMatthias Ringwald     #define __QSUB    __iar_builtin_QSUB
460*a8f7f3fcSMatthias Ringwald     #define __PKHBT   __iar_builtin_PKHBT
461*a8f7f3fcSMatthias Ringwald     #define __PKHTB   __iar_builtin_PKHTB
462*a8f7f3fcSMatthias Ringwald   #endif
463*a8f7f3fcSMatthias Ringwald 
464*a8f7f3fcSMatthias Ringwald #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
465*a8f7f3fcSMatthias Ringwald 
466*a8f7f3fcSMatthias Ringwald   #if __IAR_M0_FAMILY
467*a8f7f3fcSMatthias Ringwald    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
468*a8f7f3fcSMatthias Ringwald     #define __CLZ  __cmsis_iar_clz_not_active
469*a8f7f3fcSMatthias Ringwald     #define __SSAT __cmsis_iar_ssat_not_active
470*a8f7f3fcSMatthias Ringwald     #define __USAT __cmsis_iar_usat_not_active
471*a8f7f3fcSMatthias Ringwald     #define __RBIT __cmsis_iar_rbit_not_active
472*a8f7f3fcSMatthias Ringwald     #define __get_APSR  __cmsis_iar_get_APSR_not_active
473*a8f7f3fcSMatthias Ringwald   #endif
474*a8f7f3fcSMatthias Ringwald 
475*a8f7f3fcSMatthias Ringwald 
476*a8f7f3fcSMatthias Ringwald   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
477*a8f7f3fcSMatthias Ringwald          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
478*a8f7f3fcSMatthias Ringwald     #define __get_FPSCR __cmsis_iar_get_FPSR_not_active
479*a8f7f3fcSMatthias Ringwald     #define __set_FPSCR __cmsis_iar_set_FPSR_not_active
480*a8f7f3fcSMatthias Ringwald   #endif
481*a8f7f3fcSMatthias Ringwald 
482*a8f7f3fcSMatthias Ringwald   #ifdef __INTRINSICS_INCLUDED
483*a8f7f3fcSMatthias Ringwald   #error intrinsics.h is already included previously!
484*a8f7f3fcSMatthias Ringwald   #endif
485*a8f7f3fcSMatthias Ringwald 
486*a8f7f3fcSMatthias Ringwald   #include <intrinsics.h>
487*a8f7f3fcSMatthias Ringwald 
488*a8f7f3fcSMatthias Ringwald   #if __IAR_M0_FAMILY
489*a8f7f3fcSMatthias Ringwald    /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
490*a8f7f3fcSMatthias Ringwald     #undef __CLZ
491*a8f7f3fcSMatthias Ringwald     #undef __SSAT
492*a8f7f3fcSMatthias Ringwald     #undef __USAT
493*a8f7f3fcSMatthias Ringwald     #undef __RBIT
494*a8f7f3fcSMatthias Ringwald     #undef __get_APSR
495*a8f7f3fcSMatthias Ringwald 
__CLZ(uint32_t data)496*a8f7f3fcSMatthias Ringwald     __STATIC_INLINE uint8_t __CLZ(uint32_t data)
497*a8f7f3fcSMatthias Ringwald     {
498*a8f7f3fcSMatthias Ringwald       if (data == 0U) { return 32U; }
499*a8f7f3fcSMatthias Ringwald 
500*a8f7f3fcSMatthias Ringwald       uint32_t count = 0U;
501*a8f7f3fcSMatthias Ringwald       uint32_t mask = 0x80000000U;
502*a8f7f3fcSMatthias Ringwald 
503*a8f7f3fcSMatthias Ringwald       while ((data & mask) == 0U)
504*a8f7f3fcSMatthias Ringwald       {
505*a8f7f3fcSMatthias Ringwald         count += 1U;
506*a8f7f3fcSMatthias Ringwald         mask = mask >> 1U;
507*a8f7f3fcSMatthias Ringwald       }
508*a8f7f3fcSMatthias Ringwald       return count;
509*a8f7f3fcSMatthias Ringwald     }
510*a8f7f3fcSMatthias Ringwald 
__RBIT(uint32_t v)511*a8f7f3fcSMatthias Ringwald     __STATIC_INLINE uint32_t __RBIT(uint32_t v)
512*a8f7f3fcSMatthias Ringwald     {
513*a8f7f3fcSMatthias Ringwald       uint8_t sc = 31U;
514*a8f7f3fcSMatthias Ringwald       uint32_t r = v;
515*a8f7f3fcSMatthias Ringwald       for (v >>= 1U; v; v >>= 1U)
516*a8f7f3fcSMatthias Ringwald       {
517*a8f7f3fcSMatthias Ringwald         r <<= 1U;
518*a8f7f3fcSMatthias Ringwald         r |= v & 1U;
519*a8f7f3fcSMatthias Ringwald         sc--;
520*a8f7f3fcSMatthias Ringwald       }
521*a8f7f3fcSMatthias Ringwald       return (r << sc);
522*a8f7f3fcSMatthias Ringwald     }
523*a8f7f3fcSMatthias Ringwald 
__get_APSR(void)524*a8f7f3fcSMatthias Ringwald     __STATIC_INLINE  uint32_t __get_APSR(void)
525*a8f7f3fcSMatthias Ringwald     {
526*a8f7f3fcSMatthias Ringwald       uint32_t res;
527*a8f7f3fcSMatthias Ringwald       __asm("MRS      %0,APSR" : "=r" (res));
528*a8f7f3fcSMatthias Ringwald       return res;
529*a8f7f3fcSMatthias Ringwald     }
530*a8f7f3fcSMatthias Ringwald 
531*a8f7f3fcSMatthias Ringwald   #endif
532*a8f7f3fcSMatthias Ringwald 
533*a8f7f3fcSMatthias Ringwald   #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
534*a8f7f3fcSMatthias Ringwald          (defined (__FPU_USED   ) && (__FPU_USED    == 1U))     ))
535*a8f7f3fcSMatthias Ringwald     #undef __get_FPSCR
536*a8f7f3fcSMatthias Ringwald     #undef __set_FPSCR
537*a8f7f3fcSMatthias Ringwald     #define __get_FPSCR()       (0)
538*a8f7f3fcSMatthias Ringwald     #define __set_FPSCR(VALUE)  ((void)VALUE)
539*a8f7f3fcSMatthias Ringwald   #endif
540*a8f7f3fcSMatthias Ringwald 
541*a8f7f3fcSMatthias Ringwald   #pragma diag_suppress=Pe940
542*a8f7f3fcSMatthias Ringwald   #pragma diag_suppress=Pe177
543*a8f7f3fcSMatthias Ringwald 
544*a8f7f3fcSMatthias Ringwald   #define __enable_irq    __enable_interrupt
545*a8f7f3fcSMatthias Ringwald   #define __disable_irq   __disable_interrupt
546*a8f7f3fcSMatthias Ringwald   #define __NOP           __no_operation
547*a8f7f3fcSMatthias Ringwald 
548*a8f7f3fcSMatthias Ringwald   #define __get_xPSR      __get_PSR
549*a8f7f3fcSMatthias Ringwald 
550*a8f7f3fcSMatthias Ringwald   #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
551*a8f7f3fcSMatthias Ringwald 
__LDREXW(uint32_t volatile * ptr)552*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
553*a8f7f3fcSMatthias Ringwald     {
554*a8f7f3fcSMatthias Ringwald       return __LDREX((unsigned long *)ptr);
555*a8f7f3fcSMatthias Ringwald     }
556*a8f7f3fcSMatthias Ringwald 
__STREXW(uint32_t value,uint32_t volatile * ptr)557*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
558*a8f7f3fcSMatthias Ringwald     {
559*a8f7f3fcSMatthias Ringwald       return __STREX(value, (unsigned long *)ptr);
560*a8f7f3fcSMatthias Ringwald     }
561*a8f7f3fcSMatthias Ringwald   #endif
562*a8f7f3fcSMatthias Ringwald 
563*a8f7f3fcSMatthias Ringwald 
564*a8f7f3fcSMatthias Ringwald   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
565*a8f7f3fcSMatthias Ringwald   #if (__CORTEX_M >= 0x03)
566*a8f7f3fcSMatthias Ringwald 
__RRX(uint32_t value)567*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t __RRX(uint32_t value)
568*a8f7f3fcSMatthias Ringwald     {
569*a8f7f3fcSMatthias Ringwald       uint32_t result;
570*a8f7f3fcSMatthias Ringwald       __ASM("RRX      %0, %1" : "=r"(result) : "r" (value) : "cc");
571*a8f7f3fcSMatthias Ringwald       return(result);
572*a8f7f3fcSMatthias Ringwald     }
573*a8f7f3fcSMatthias Ringwald 
__set_BASEPRI_MAX(uint32_t value)574*a8f7f3fcSMatthias Ringwald     __IAR_FT void __set_BASEPRI_MAX(uint32_t value)
575*a8f7f3fcSMatthias Ringwald     {
576*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      BASEPRI_MAX,%0"::"r" (value));
577*a8f7f3fcSMatthias Ringwald     }
578*a8f7f3fcSMatthias Ringwald 
579*a8f7f3fcSMatthias Ringwald 
580*a8f7f3fcSMatthias Ringwald     #define __enable_fault_irq  __enable_fiq
581*a8f7f3fcSMatthias Ringwald     #define __disable_fault_irq __disable_fiq
582*a8f7f3fcSMatthias Ringwald 
583*a8f7f3fcSMatthias Ringwald 
584*a8f7f3fcSMatthias Ringwald   #endif /* (__CORTEX_M >= 0x03) */
585*a8f7f3fcSMatthias Ringwald 
__ROR(uint32_t op1,uint32_t op2)586*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
587*a8f7f3fcSMatthias Ringwald   {
588*a8f7f3fcSMatthias Ringwald     return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
589*a8f7f3fcSMatthias Ringwald   }
590*a8f7f3fcSMatthias Ringwald 
591*a8f7f3fcSMatthias Ringwald   #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
592*a8f7f3fcSMatthias Ringwald        (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
593*a8f7f3fcSMatthias Ringwald 
__get_MSPLIM(void)594*a8f7f3fcSMatthias Ringwald    __IAR_FT uint32_t __get_MSPLIM(void)
595*a8f7f3fcSMatthias Ringwald     {
596*a8f7f3fcSMatthias Ringwald       uint32_t res;
597*a8f7f3fcSMatthias Ringwald     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
598*a8f7f3fcSMatthias Ringwald          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
599*a8f7f3fcSMatthias Ringwald       // without main extensions, the non-secure MSPLIM is RAZ/WI
600*a8f7f3fcSMatthias Ringwald       res = 0U;
601*a8f7f3fcSMatthias Ringwald     #else
602*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,MSPLIM" : "=r" (res));
603*a8f7f3fcSMatthias Ringwald     #endif
604*a8f7f3fcSMatthias Ringwald       return res;
605*a8f7f3fcSMatthias Ringwald     }
606*a8f7f3fcSMatthias Ringwald 
__set_MSPLIM(uint32_t value)607*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __set_MSPLIM(uint32_t value)
608*a8f7f3fcSMatthias Ringwald     {
609*a8f7f3fcSMatthias Ringwald     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
610*a8f7f3fcSMatthias Ringwald          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
611*a8f7f3fcSMatthias Ringwald       // without main extensions, the non-secure MSPLIM is RAZ/WI
612*a8f7f3fcSMatthias Ringwald       (void)value;
613*a8f7f3fcSMatthias Ringwald     #else
614*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      MSPLIM,%0" :: "r" (value));
615*a8f7f3fcSMatthias Ringwald     #endif
616*a8f7f3fcSMatthias Ringwald     }
617*a8f7f3fcSMatthias Ringwald 
__get_PSPLIM(void)618*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t __get_PSPLIM(void)
619*a8f7f3fcSMatthias Ringwald     {
620*a8f7f3fcSMatthias Ringwald       uint32_t res;
621*a8f7f3fcSMatthias Ringwald     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
622*a8f7f3fcSMatthias Ringwald          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
623*a8f7f3fcSMatthias Ringwald       // without main extensions, the non-secure PSPLIM is RAZ/WI
624*a8f7f3fcSMatthias Ringwald       res = 0U;
625*a8f7f3fcSMatthias Ringwald     #else
626*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,PSPLIM" : "=r" (res));
627*a8f7f3fcSMatthias Ringwald     #endif
628*a8f7f3fcSMatthias Ringwald       return res;
629*a8f7f3fcSMatthias Ringwald     }
630*a8f7f3fcSMatthias Ringwald 
__set_PSPLIM(uint32_t value)631*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __set_PSPLIM(uint32_t value)
632*a8f7f3fcSMatthias Ringwald     {
633*a8f7f3fcSMatthias Ringwald     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
634*a8f7f3fcSMatthias Ringwald          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
635*a8f7f3fcSMatthias Ringwald       // without main extensions, the non-secure PSPLIM is RAZ/WI
636*a8f7f3fcSMatthias Ringwald       (void)value;
637*a8f7f3fcSMatthias Ringwald     #else
638*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      PSPLIM,%0" :: "r" (value));
639*a8f7f3fcSMatthias Ringwald     #endif
640*a8f7f3fcSMatthias Ringwald     }
641*a8f7f3fcSMatthias Ringwald 
__TZ_get_CONTROL_NS(void)642*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
643*a8f7f3fcSMatthias Ringwald     {
644*a8f7f3fcSMatthias Ringwald       uint32_t res;
645*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,CONTROL_NS" : "=r" (res));
646*a8f7f3fcSMatthias Ringwald       return res;
647*a8f7f3fcSMatthias Ringwald     }
648*a8f7f3fcSMatthias Ringwald 
__TZ_set_CONTROL_NS(uint32_t value)649*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_CONTROL_NS(uint32_t value)
650*a8f7f3fcSMatthias Ringwald     {
651*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      CONTROL_NS,%0" :: "r" (value));
652*a8f7f3fcSMatthias Ringwald     }
653*a8f7f3fcSMatthias Ringwald 
__TZ_get_PSP_NS(void)654*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_PSP_NS(void)
655*a8f7f3fcSMatthias Ringwald     {
656*a8f7f3fcSMatthias Ringwald       uint32_t res;
657*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,PSP_NS" : "=r" (res));
658*a8f7f3fcSMatthias Ringwald       return res;
659*a8f7f3fcSMatthias Ringwald     }
660*a8f7f3fcSMatthias Ringwald 
__TZ_set_PSP_NS(uint32_t value)661*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_PSP_NS(uint32_t value)
662*a8f7f3fcSMatthias Ringwald     {
663*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      PSP_NS,%0" :: "r" (value));
664*a8f7f3fcSMatthias Ringwald     }
665*a8f7f3fcSMatthias Ringwald 
__TZ_get_MSP_NS(void)666*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_MSP_NS(void)
667*a8f7f3fcSMatthias Ringwald     {
668*a8f7f3fcSMatthias Ringwald       uint32_t res;
669*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,MSP_NS" : "=r" (res));
670*a8f7f3fcSMatthias Ringwald       return res;
671*a8f7f3fcSMatthias Ringwald     }
672*a8f7f3fcSMatthias Ringwald 
__TZ_set_MSP_NS(uint32_t value)673*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_MSP_NS(uint32_t value)
674*a8f7f3fcSMatthias Ringwald     {
675*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      MSP_NS,%0" :: "r" (value));
676*a8f7f3fcSMatthias Ringwald     }
677*a8f7f3fcSMatthias Ringwald 
__TZ_get_SP_NS(void)678*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_SP_NS(void)
679*a8f7f3fcSMatthias Ringwald     {
680*a8f7f3fcSMatthias Ringwald       uint32_t res;
681*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,SP_NS" : "=r" (res));
682*a8f7f3fcSMatthias Ringwald       return res;
683*a8f7f3fcSMatthias Ringwald     }
__TZ_set_SP_NS(uint32_t value)684*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_SP_NS(uint32_t value)
685*a8f7f3fcSMatthias Ringwald     {
686*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      SP_NS,%0" :: "r" (value));
687*a8f7f3fcSMatthias Ringwald     }
688*a8f7f3fcSMatthias Ringwald 
__TZ_get_PRIMASK_NS(void)689*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_PRIMASK_NS(void)
690*a8f7f3fcSMatthias Ringwald     {
691*a8f7f3fcSMatthias Ringwald       uint32_t res;
692*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,PRIMASK_NS" : "=r" (res));
693*a8f7f3fcSMatthias Ringwald       return res;
694*a8f7f3fcSMatthias Ringwald     }
695*a8f7f3fcSMatthias Ringwald 
__TZ_set_PRIMASK_NS(uint32_t value)696*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_PRIMASK_NS(uint32_t value)
697*a8f7f3fcSMatthias Ringwald     {
698*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      PRIMASK_NS,%0" :: "r" (value));
699*a8f7f3fcSMatthias Ringwald     }
700*a8f7f3fcSMatthias Ringwald 
__TZ_get_BASEPRI_NS(void)701*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_BASEPRI_NS(void)
702*a8f7f3fcSMatthias Ringwald     {
703*a8f7f3fcSMatthias Ringwald       uint32_t res;
704*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,BASEPRI_NS" : "=r" (res));
705*a8f7f3fcSMatthias Ringwald       return res;
706*a8f7f3fcSMatthias Ringwald     }
707*a8f7f3fcSMatthias Ringwald 
__TZ_set_BASEPRI_NS(uint32_t value)708*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_BASEPRI_NS(uint32_t value)
709*a8f7f3fcSMatthias Ringwald     {
710*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      BASEPRI_NS,%0" :: "r" (value));
711*a8f7f3fcSMatthias Ringwald     }
712*a8f7f3fcSMatthias Ringwald 
__TZ_get_FAULTMASK_NS(void)713*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_FAULTMASK_NS(void)
714*a8f7f3fcSMatthias Ringwald     {
715*a8f7f3fcSMatthias Ringwald       uint32_t res;
716*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,FAULTMASK_NS" : "=r" (res));
717*a8f7f3fcSMatthias Ringwald       return res;
718*a8f7f3fcSMatthias Ringwald     }
719*a8f7f3fcSMatthias Ringwald 
__TZ_set_FAULTMASK_NS(uint32_t value)720*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_FAULTMASK_NS(uint32_t value)
721*a8f7f3fcSMatthias Ringwald     {
722*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      FAULTMASK_NS,%0" :: "r" (value));
723*a8f7f3fcSMatthias Ringwald     }
724*a8f7f3fcSMatthias Ringwald 
__TZ_get_PSPLIM_NS(void)725*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_PSPLIM_NS(void)
726*a8f7f3fcSMatthias Ringwald     {
727*a8f7f3fcSMatthias Ringwald       uint32_t res;
728*a8f7f3fcSMatthias Ringwald     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
729*a8f7f3fcSMatthias Ringwald          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
730*a8f7f3fcSMatthias Ringwald       // without main extensions, the non-secure PSPLIM is RAZ/WI
731*a8f7f3fcSMatthias Ringwald       res = 0U;
732*a8f7f3fcSMatthias Ringwald     #else
733*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,PSPLIM_NS" : "=r" (res));
734*a8f7f3fcSMatthias Ringwald     #endif
735*a8f7f3fcSMatthias Ringwald       return res;
736*a8f7f3fcSMatthias Ringwald     }
737*a8f7f3fcSMatthias Ringwald 
__TZ_set_PSPLIM_NS(uint32_t value)738*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_PSPLIM_NS(uint32_t value)
739*a8f7f3fcSMatthias Ringwald     {
740*a8f7f3fcSMatthias Ringwald     #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
741*a8f7f3fcSMatthias Ringwald          (!defined (__ARM_FEATURE_CMSE  ) || (__ARM_FEATURE_CMSE   < 3)))
742*a8f7f3fcSMatthias Ringwald       // without main extensions, the non-secure PSPLIM is RAZ/WI
743*a8f7f3fcSMatthias Ringwald       (void)value;
744*a8f7f3fcSMatthias Ringwald     #else
745*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      PSPLIM_NS,%0" :: "r" (value));
746*a8f7f3fcSMatthias Ringwald     #endif
747*a8f7f3fcSMatthias Ringwald     }
748*a8f7f3fcSMatthias Ringwald 
__TZ_get_MSPLIM_NS(void)749*a8f7f3fcSMatthias Ringwald     __IAR_FT uint32_t   __TZ_get_MSPLIM_NS(void)
750*a8f7f3fcSMatthias Ringwald     {
751*a8f7f3fcSMatthias Ringwald       uint32_t res;
752*a8f7f3fcSMatthias Ringwald       __asm volatile("MRS      %0,MSPLIM_NS" : "=r" (res));
753*a8f7f3fcSMatthias Ringwald       return res;
754*a8f7f3fcSMatthias Ringwald     }
755*a8f7f3fcSMatthias Ringwald 
__TZ_set_MSPLIM_NS(uint32_t value)756*a8f7f3fcSMatthias Ringwald     __IAR_FT void   __TZ_set_MSPLIM_NS(uint32_t value)
757*a8f7f3fcSMatthias Ringwald     {
758*a8f7f3fcSMatthias Ringwald       __asm volatile("MSR      MSPLIM_NS,%0" :: "r" (value));
759*a8f7f3fcSMatthias Ringwald     }
760*a8f7f3fcSMatthias Ringwald 
761*a8f7f3fcSMatthias Ringwald   #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
762*a8f7f3fcSMatthias Ringwald 
763*a8f7f3fcSMatthias Ringwald #endif   /* __ICCARM_INTRINSICS_VERSION__ == 2 */
764*a8f7f3fcSMatthias Ringwald 
765*a8f7f3fcSMatthias Ringwald #define __BKPT(value)    __asm volatile ("BKPT     %0" : : "i"(value))
766*a8f7f3fcSMatthias Ringwald 
767*a8f7f3fcSMatthias Ringwald #if __IAR_M0_FAMILY
__SSAT(int32_t val,uint32_t sat)768*a8f7f3fcSMatthias Ringwald   __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
769*a8f7f3fcSMatthias Ringwald   {
770*a8f7f3fcSMatthias Ringwald     if ((sat >= 1U) && (sat <= 32U))
771*a8f7f3fcSMatthias Ringwald     {
772*a8f7f3fcSMatthias Ringwald       const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
773*a8f7f3fcSMatthias Ringwald       const int32_t min = -1 - max ;
774*a8f7f3fcSMatthias Ringwald       if (val > max)
775*a8f7f3fcSMatthias Ringwald       {
776*a8f7f3fcSMatthias Ringwald         return max;
777*a8f7f3fcSMatthias Ringwald       }
778*a8f7f3fcSMatthias Ringwald       else if (val < min)
779*a8f7f3fcSMatthias Ringwald       {
780*a8f7f3fcSMatthias Ringwald         return min;
781*a8f7f3fcSMatthias Ringwald       }
782*a8f7f3fcSMatthias Ringwald     }
783*a8f7f3fcSMatthias Ringwald     return val;
784*a8f7f3fcSMatthias Ringwald   }
785*a8f7f3fcSMatthias Ringwald 
__USAT(int32_t val,uint32_t sat)786*a8f7f3fcSMatthias Ringwald   __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
787*a8f7f3fcSMatthias Ringwald   {
788*a8f7f3fcSMatthias Ringwald     if (sat <= 31U)
789*a8f7f3fcSMatthias Ringwald     {
790*a8f7f3fcSMatthias Ringwald       const uint32_t max = ((1U << sat) - 1U);
791*a8f7f3fcSMatthias Ringwald       if (val > (int32_t)max)
792*a8f7f3fcSMatthias Ringwald       {
793*a8f7f3fcSMatthias Ringwald         return max;
794*a8f7f3fcSMatthias Ringwald       }
795*a8f7f3fcSMatthias Ringwald       else if (val < 0)
796*a8f7f3fcSMatthias Ringwald       {
797*a8f7f3fcSMatthias Ringwald         return 0U;
798*a8f7f3fcSMatthias Ringwald       }
799*a8f7f3fcSMatthias Ringwald     }
800*a8f7f3fcSMatthias Ringwald     return (uint32_t)val;
801*a8f7f3fcSMatthias Ringwald   }
802*a8f7f3fcSMatthias Ringwald #endif
803*a8f7f3fcSMatthias Ringwald 
804*a8f7f3fcSMatthias Ringwald #if (__CORTEX_M >= 0x03)   /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
805*a8f7f3fcSMatthias Ringwald 
__LDRBT(volatile uint8_t * addr)806*a8f7f3fcSMatthias Ringwald   __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
807*a8f7f3fcSMatthias Ringwald   {
808*a8f7f3fcSMatthias Ringwald     uint32_t res;
809*a8f7f3fcSMatthias Ringwald     __ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
810*a8f7f3fcSMatthias Ringwald     return ((uint8_t)res);
811*a8f7f3fcSMatthias Ringwald   }
812*a8f7f3fcSMatthias Ringwald 
__LDRHT(volatile uint16_t * addr)813*a8f7f3fcSMatthias Ringwald   __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
814*a8f7f3fcSMatthias Ringwald   {
815*a8f7f3fcSMatthias Ringwald     uint32_t res;
816*a8f7f3fcSMatthias Ringwald     __ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
817*a8f7f3fcSMatthias Ringwald     return ((uint16_t)res);
818*a8f7f3fcSMatthias Ringwald   }
819*a8f7f3fcSMatthias Ringwald 
__LDRT(volatile uint32_t * addr)820*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
821*a8f7f3fcSMatthias Ringwald   {
822*a8f7f3fcSMatthias Ringwald     uint32_t res;
823*a8f7f3fcSMatthias Ringwald     __ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
824*a8f7f3fcSMatthias Ringwald     return res;
825*a8f7f3fcSMatthias Ringwald   }
826*a8f7f3fcSMatthias Ringwald 
__STRBT(uint8_t value,volatile uint8_t * addr)827*a8f7f3fcSMatthias Ringwald   __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
828*a8f7f3fcSMatthias Ringwald   {
829*a8f7f3fcSMatthias Ringwald     __ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
830*a8f7f3fcSMatthias Ringwald   }
831*a8f7f3fcSMatthias Ringwald 
__STRHT(uint16_t value,volatile uint16_t * addr)832*a8f7f3fcSMatthias Ringwald   __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
833*a8f7f3fcSMatthias Ringwald   {
834*a8f7f3fcSMatthias Ringwald     __ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
835*a8f7f3fcSMatthias Ringwald   }
836*a8f7f3fcSMatthias Ringwald 
__STRT(uint32_t value,volatile uint32_t * addr)837*a8f7f3fcSMatthias Ringwald   __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
838*a8f7f3fcSMatthias Ringwald   {
839*a8f7f3fcSMatthias Ringwald     __ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
840*a8f7f3fcSMatthias Ringwald   }
841*a8f7f3fcSMatthias Ringwald 
842*a8f7f3fcSMatthias Ringwald #endif /* (__CORTEX_M >= 0x03) */
843*a8f7f3fcSMatthias Ringwald 
844*a8f7f3fcSMatthias Ringwald #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
845*a8f7f3fcSMatthias Ringwald      (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1))    )
846*a8f7f3fcSMatthias Ringwald 
847*a8f7f3fcSMatthias Ringwald 
__LDAB(volatile uint8_t * ptr)848*a8f7f3fcSMatthias Ringwald   __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
849*a8f7f3fcSMatthias Ringwald   {
850*a8f7f3fcSMatthias Ringwald     uint32_t res;
851*a8f7f3fcSMatthias Ringwald     __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
852*a8f7f3fcSMatthias Ringwald     return ((uint8_t)res);
853*a8f7f3fcSMatthias Ringwald   }
854*a8f7f3fcSMatthias Ringwald 
__LDAH(volatile uint16_t * ptr)855*a8f7f3fcSMatthias Ringwald   __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
856*a8f7f3fcSMatthias Ringwald   {
857*a8f7f3fcSMatthias Ringwald     uint32_t res;
858*a8f7f3fcSMatthias Ringwald     __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
859*a8f7f3fcSMatthias Ringwald     return ((uint16_t)res);
860*a8f7f3fcSMatthias Ringwald   }
861*a8f7f3fcSMatthias Ringwald 
__LDA(volatile uint32_t * ptr)862*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
863*a8f7f3fcSMatthias Ringwald   {
864*a8f7f3fcSMatthias Ringwald     uint32_t res;
865*a8f7f3fcSMatthias Ringwald     __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
866*a8f7f3fcSMatthias Ringwald     return res;
867*a8f7f3fcSMatthias Ringwald   }
868*a8f7f3fcSMatthias Ringwald 
__STLB(uint8_t value,volatile uint8_t * ptr)869*a8f7f3fcSMatthias Ringwald   __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
870*a8f7f3fcSMatthias Ringwald   {
871*a8f7f3fcSMatthias Ringwald     __ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
872*a8f7f3fcSMatthias Ringwald   }
873*a8f7f3fcSMatthias Ringwald 
__STLH(uint16_t value,volatile uint16_t * ptr)874*a8f7f3fcSMatthias Ringwald   __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
875*a8f7f3fcSMatthias Ringwald   {
876*a8f7f3fcSMatthias Ringwald     __ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
877*a8f7f3fcSMatthias Ringwald   }
878*a8f7f3fcSMatthias Ringwald 
__STL(uint32_t value,volatile uint32_t * ptr)879*a8f7f3fcSMatthias Ringwald   __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
880*a8f7f3fcSMatthias Ringwald   {
881*a8f7f3fcSMatthias Ringwald     __ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
882*a8f7f3fcSMatthias Ringwald   }
883*a8f7f3fcSMatthias Ringwald 
__LDAEXB(volatile uint8_t * ptr)884*a8f7f3fcSMatthias Ringwald   __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
885*a8f7f3fcSMatthias Ringwald   {
886*a8f7f3fcSMatthias Ringwald     uint32_t res;
887*a8f7f3fcSMatthias Ringwald     __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
888*a8f7f3fcSMatthias Ringwald     return ((uint8_t)res);
889*a8f7f3fcSMatthias Ringwald   }
890*a8f7f3fcSMatthias Ringwald 
__LDAEXH(volatile uint16_t * ptr)891*a8f7f3fcSMatthias Ringwald   __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
892*a8f7f3fcSMatthias Ringwald   {
893*a8f7f3fcSMatthias Ringwald     uint32_t res;
894*a8f7f3fcSMatthias Ringwald     __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
895*a8f7f3fcSMatthias Ringwald     return ((uint16_t)res);
896*a8f7f3fcSMatthias Ringwald   }
897*a8f7f3fcSMatthias Ringwald 
__LDAEX(volatile uint32_t * ptr)898*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
899*a8f7f3fcSMatthias Ringwald   {
900*a8f7f3fcSMatthias Ringwald     uint32_t res;
901*a8f7f3fcSMatthias Ringwald     __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
902*a8f7f3fcSMatthias Ringwald     return res;
903*a8f7f3fcSMatthias Ringwald   }
904*a8f7f3fcSMatthias Ringwald 
__STLEXB(uint8_t value,volatile uint8_t * ptr)905*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
906*a8f7f3fcSMatthias Ringwald   {
907*a8f7f3fcSMatthias Ringwald     uint32_t res;
908*a8f7f3fcSMatthias Ringwald     __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
909*a8f7f3fcSMatthias Ringwald     return res;
910*a8f7f3fcSMatthias Ringwald   }
911*a8f7f3fcSMatthias Ringwald 
__STLEXH(uint16_t value,volatile uint16_t * ptr)912*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
913*a8f7f3fcSMatthias Ringwald   {
914*a8f7f3fcSMatthias Ringwald     uint32_t res;
915*a8f7f3fcSMatthias Ringwald     __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
916*a8f7f3fcSMatthias Ringwald     return res;
917*a8f7f3fcSMatthias Ringwald   }
918*a8f7f3fcSMatthias Ringwald 
__STLEX(uint32_t value,volatile uint32_t * ptr)919*a8f7f3fcSMatthias Ringwald   __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
920*a8f7f3fcSMatthias Ringwald   {
921*a8f7f3fcSMatthias Ringwald     uint32_t res;
922*a8f7f3fcSMatthias Ringwald     __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
923*a8f7f3fcSMatthias Ringwald     return res;
924*a8f7f3fcSMatthias Ringwald   }
925*a8f7f3fcSMatthias Ringwald 
926*a8f7f3fcSMatthias Ringwald #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
927*a8f7f3fcSMatthias Ringwald 
928*a8f7f3fcSMatthias Ringwald #undef __IAR_FT
929*a8f7f3fcSMatthias Ringwald #undef __IAR_M0_FAMILY
930*a8f7f3fcSMatthias Ringwald #undef __ICCARM_V8
931*a8f7f3fcSMatthias Ringwald 
932*a8f7f3fcSMatthias Ringwald #pragma diag_default=Pe940
933*a8f7f3fcSMatthias Ringwald #pragma diag_default=Pe177
934*a8f7f3fcSMatthias Ringwald 
935*a8f7f3fcSMatthias Ringwald #endif /* __CMSIS_ICCARM_H__ */
936