1*a8f7f3fcSMatthias Ringwald /**************************************************************************//**
2*a8f7f3fcSMatthias Ringwald * @file cmsis_armcc.h
3*a8f7f3fcSMatthias Ringwald * @brief CMSIS compiler ARMCC (Arm Compiler 5) 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_ARMCC_H
26*a8f7f3fcSMatthias Ringwald #define __CMSIS_ARMCC_H
27*a8f7f3fcSMatthias Ringwald
28*a8f7f3fcSMatthias Ringwald
29*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
30*a8f7f3fcSMatthias Ringwald #error "Please use Arm Compiler Toolchain V4.0.677 or later!"
31*a8f7f3fcSMatthias Ringwald #endif
32*a8f7f3fcSMatthias Ringwald
33*a8f7f3fcSMatthias Ringwald /* CMSIS compiler control architecture macros */
34*a8f7f3fcSMatthias Ringwald #if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \
35*a8f7f3fcSMatthias Ringwald (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) )
36*a8f7f3fcSMatthias Ringwald #define __ARM_ARCH_6M__ 1
37*a8f7f3fcSMatthias Ringwald #endif
38*a8f7f3fcSMatthias Ringwald
39*a8f7f3fcSMatthias Ringwald #if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1))
40*a8f7f3fcSMatthias Ringwald #define __ARM_ARCH_7M__ 1
41*a8f7f3fcSMatthias Ringwald #endif
42*a8f7f3fcSMatthias Ringwald
43*a8f7f3fcSMatthias Ringwald #if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
44*a8f7f3fcSMatthias Ringwald #define __ARM_ARCH_7EM__ 1
45*a8f7f3fcSMatthias Ringwald #endif
46*a8f7f3fcSMatthias Ringwald
47*a8f7f3fcSMatthias Ringwald /* __ARM_ARCH_8M_BASE__ not applicable */
48*a8f7f3fcSMatthias Ringwald /* __ARM_ARCH_8M_MAIN__ not applicable */
49*a8f7f3fcSMatthias Ringwald
50*a8f7f3fcSMatthias Ringwald
51*a8f7f3fcSMatthias Ringwald /* CMSIS compiler specific defines */
52*a8f7f3fcSMatthias Ringwald #ifndef __ASM
53*a8f7f3fcSMatthias Ringwald #define __ASM __asm
54*a8f7f3fcSMatthias Ringwald #endif
55*a8f7f3fcSMatthias Ringwald #ifndef __INLINE
56*a8f7f3fcSMatthias Ringwald #define __INLINE __inline
57*a8f7f3fcSMatthias Ringwald #endif
58*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_INLINE
59*a8f7f3fcSMatthias Ringwald #define __STATIC_INLINE static __inline
60*a8f7f3fcSMatthias Ringwald #endif
61*a8f7f3fcSMatthias Ringwald #ifndef __STATIC_FORCEINLINE
62*a8f7f3fcSMatthias Ringwald #define __STATIC_FORCEINLINE static __forceinline
63*a8f7f3fcSMatthias Ringwald #endif
64*a8f7f3fcSMatthias Ringwald #ifndef __NO_RETURN
65*a8f7f3fcSMatthias Ringwald #define __NO_RETURN __declspec(noreturn)
66*a8f7f3fcSMatthias Ringwald #endif
67*a8f7f3fcSMatthias Ringwald #ifndef __USED
68*a8f7f3fcSMatthias Ringwald #define __USED __attribute__((used))
69*a8f7f3fcSMatthias Ringwald #endif
70*a8f7f3fcSMatthias Ringwald #ifndef __WEAK
71*a8f7f3fcSMatthias Ringwald #define __WEAK __attribute__((weak))
72*a8f7f3fcSMatthias Ringwald #endif
73*a8f7f3fcSMatthias Ringwald #ifndef __PACKED
74*a8f7f3fcSMatthias Ringwald #define __PACKED __attribute__((packed))
75*a8f7f3fcSMatthias Ringwald #endif
76*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_STRUCT
77*a8f7f3fcSMatthias Ringwald #define __PACKED_STRUCT __packed struct
78*a8f7f3fcSMatthias Ringwald #endif
79*a8f7f3fcSMatthias Ringwald #ifndef __PACKED_UNION
80*a8f7f3fcSMatthias Ringwald #define __PACKED_UNION __packed union
81*a8f7f3fcSMatthias Ringwald #endif
82*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32 /* deprecated */
83*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
84*a8f7f3fcSMatthias Ringwald #endif
85*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_WRITE
86*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val))
87*a8f7f3fcSMatthias Ringwald #endif
88*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT16_READ
89*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr)))
90*a8f7f3fcSMatthias Ringwald #endif
91*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_WRITE
92*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
93*a8f7f3fcSMatthias Ringwald #endif
94*a8f7f3fcSMatthias Ringwald #ifndef __UNALIGNED_UINT32_READ
95*a8f7f3fcSMatthias Ringwald #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
96*a8f7f3fcSMatthias Ringwald #endif
97*a8f7f3fcSMatthias Ringwald #ifndef __ALIGNED
98*a8f7f3fcSMatthias Ringwald #define __ALIGNED(x) __attribute__((aligned(x)))
99*a8f7f3fcSMatthias Ringwald #endif
100*a8f7f3fcSMatthias Ringwald #ifndef __RESTRICT
101*a8f7f3fcSMatthias Ringwald #define __RESTRICT __restrict
102*a8f7f3fcSMatthias Ringwald #endif
103*a8f7f3fcSMatthias Ringwald
104*a8f7f3fcSMatthias Ringwald /* ########################### Core Function Access ########################### */
105*a8f7f3fcSMatthias Ringwald /** \ingroup CMSIS_Core_FunctionInterface
106*a8f7f3fcSMatthias Ringwald \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
107*a8f7f3fcSMatthias Ringwald @{
108*a8f7f3fcSMatthias Ringwald */
109*a8f7f3fcSMatthias Ringwald
110*a8f7f3fcSMatthias Ringwald /**
111*a8f7f3fcSMatthias Ringwald \brief Enable IRQ Interrupts
112*a8f7f3fcSMatthias Ringwald \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
113*a8f7f3fcSMatthias Ringwald Can only be executed in Privileged modes.
114*a8f7f3fcSMatthias Ringwald */
115*a8f7f3fcSMatthias Ringwald /* intrinsic void __enable_irq(); */
116*a8f7f3fcSMatthias Ringwald
117*a8f7f3fcSMatthias Ringwald
118*a8f7f3fcSMatthias Ringwald /**
119*a8f7f3fcSMatthias Ringwald \brief Disable IRQ Interrupts
120*a8f7f3fcSMatthias Ringwald \details Disables IRQ interrupts by setting the I-bit in the CPSR.
121*a8f7f3fcSMatthias Ringwald Can only be executed in Privileged modes.
122*a8f7f3fcSMatthias Ringwald */
123*a8f7f3fcSMatthias Ringwald /* intrinsic void __disable_irq(); */
124*a8f7f3fcSMatthias Ringwald
125*a8f7f3fcSMatthias Ringwald /**
126*a8f7f3fcSMatthias Ringwald \brief Get Control Register
127*a8f7f3fcSMatthias Ringwald \details Returns the content of the Control Register.
128*a8f7f3fcSMatthias Ringwald \return Control Register value
129*a8f7f3fcSMatthias Ringwald */
__get_CONTROL(void)130*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_CONTROL(void)
131*a8f7f3fcSMatthias Ringwald {
132*a8f7f3fcSMatthias Ringwald register uint32_t __regControl __ASM("control");
133*a8f7f3fcSMatthias Ringwald return(__regControl);
134*a8f7f3fcSMatthias Ringwald }
135*a8f7f3fcSMatthias Ringwald
136*a8f7f3fcSMatthias Ringwald
137*a8f7f3fcSMatthias Ringwald /**
138*a8f7f3fcSMatthias Ringwald \brief Set Control Register
139*a8f7f3fcSMatthias Ringwald \details Writes the given value to the Control Register.
140*a8f7f3fcSMatthias Ringwald \param [in] control Control Register value to set
141*a8f7f3fcSMatthias Ringwald */
__set_CONTROL(uint32_t control)142*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_CONTROL(uint32_t control)
143*a8f7f3fcSMatthias Ringwald {
144*a8f7f3fcSMatthias Ringwald register uint32_t __regControl __ASM("control");
145*a8f7f3fcSMatthias Ringwald __regControl = control;
146*a8f7f3fcSMatthias Ringwald }
147*a8f7f3fcSMatthias Ringwald
148*a8f7f3fcSMatthias Ringwald
149*a8f7f3fcSMatthias Ringwald /**
150*a8f7f3fcSMatthias Ringwald \brief Get IPSR Register
151*a8f7f3fcSMatthias Ringwald \details Returns the content of the IPSR Register.
152*a8f7f3fcSMatthias Ringwald \return IPSR Register value
153*a8f7f3fcSMatthias Ringwald */
__get_IPSR(void)154*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_IPSR(void)
155*a8f7f3fcSMatthias Ringwald {
156*a8f7f3fcSMatthias Ringwald register uint32_t __regIPSR __ASM("ipsr");
157*a8f7f3fcSMatthias Ringwald return(__regIPSR);
158*a8f7f3fcSMatthias Ringwald }
159*a8f7f3fcSMatthias Ringwald
160*a8f7f3fcSMatthias Ringwald
161*a8f7f3fcSMatthias Ringwald /**
162*a8f7f3fcSMatthias Ringwald \brief Get APSR Register
163*a8f7f3fcSMatthias Ringwald \details Returns the content of the APSR Register.
164*a8f7f3fcSMatthias Ringwald \return APSR Register value
165*a8f7f3fcSMatthias Ringwald */
__get_APSR(void)166*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_APSR(void)
167*a8f7f3fcSMatthias Ringwald {
168*a8f7f3fcSMatthias Ringwald register uint32_t __regAPSR __ASM("apsr");
169*a8f7f3fcSMatthias Ringwald return(__regAPSR);
170*a8f7f3fcSMatthias Ringwald }
171*a8f7f3fcSMatthias Ringwald
172*a8f7f3fcSMatthias Ringwald
173*a8f7f3fcSMatthias Ringwald /**
174*a8f7f3fcSMatthias Ringwald \brief Get xPSR Register
175*a8f7f3fcSMatthias Ringwald \details Returns the content of the xPSR Register.
176*a8f7f3fcSMatthias Ringwald \return xPSR Register value
177*a8f7f3fcSMatthias Ringwald */
__get_xPSR(void)178*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_xPSR(void)
179*a8f7f3fcSMatthias Ringwald {
180*a8f7f3fcSMatthias Ringwald register uint32_t __regXPSR __ASM("xpsr");
181*a8f7f3fcSMatthias Ringwald return(__regXPSR);
182*a8f7f3fcSMatthias Ringwald }
183*a8f7f3fcSMatthias Ringwald
184*a8f7f3fcSMatthias Ringwald
185*a8f7f3fcSMatthias Ringwald /**
186*a8f7f3fcSMatthias Ringwald \brief Get Process Stack Pointer
187*a8f7f3fcSMatthias Ringwald \details Returns the current value of the Process Stack Pointer (PSP).
188*a8f7f3fcSMatthias Ringwald \return PSP Register value
189*a8f7f3fcSMatthias Ringwald */
__get_PSP(void)190*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_PSP(void)
191*a8f7f3fcSMatthias Ringwald {
192*a8f7f3fcSMatthias Ringwald register uint32_t __regProcessStackPointer __ASM("psp");
193*a8f7f3fcSMatthias Ringwald return(__regProcessStackPointer);
194*a8f7f3fcSMatthias Ringwald }
195*a8f7f3fcSMatthias Ringwald
196*a8f7f3fcSMatthias Ringwald
197*a8f7f3fcSMatthias Ringwald /**
198*a8f7f3fcSMatthias Ringwald \brief Set Process Stack Pointer
199*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Process Stack Pointer (PSP).
200*a8f7f3fcSMatthias Ringwald \param [in] topOfProcStack Process Stack Pointer value to set
201*a8f7f3fcSMatthias Ringwald */
__set_PSP(uint32_t topOfProcStack)202*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
203*a8f7f3fcSMatthias Ringwald {
204*a8f7f3fcSMatthias Ringwald register uint32_t __regProcessStackPointer __ASM("psp");
205*a8f7f3fcSMatthias Ringwald __regProcessStackPointer = topOfProcStack;
206*a8f7f3fcSMatthias Ringwald }
207*a8f7f3fcSMatthias Ringwald
208*a8f7f3fcSMatthias Ringwald
209*a8f7f3fcSMatthias Ringwald /**
210*a8f7f3fcSMatthias Ringwald \brief Get Main Stack Pointer
211*a8f7f3fcSMatthias Ringwald \details Returns the current value of the Main Stack Pointer (MSP).
212*a8f7f3fcSMatthias Ringwald \return MSP Register value
213*a8f7f3fcSMatthias Ringwald */
__get_MSP(void)214*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_MSP(void)
215*a8f7f3fcSMatthias Ringwald {
216*a8f7f3fcSMatthias Ringwald register uint32_t __regMainStackPointer __ASM("msp");
217*a8f7f3fcSMatthias Ringwald return(__regMainStackPointer);
218*a8f7f3fcSMatthias Ringwald }
219*a8f7f3fcSMatthias Ringwald
220*a8f7f3fcSMatthias Ringwald
221*a8f7f3fcSMatthias Ringwald /**
222*a8f7f3fcSMatthias Ringwald \brief Set Main Stack Pointer
223*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Main Stack Pointer (MSP).
224*a8f7f3fcSMatthias Ringwald \param [in] topOfMainStack Main Stack Pointer value to set
225*a8f7f3fcSMatthias Ringwald */
__set_MSP(uint32_t topOfMainStack)226*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
227*a8f7f3fcSMatthias Ringwald {
228*a8f7f3fcSMatthias Ringwald register uint32_t __regMainStackPointer __ASM("msp");
229*a8f7f3fcSMatthias Ringwald __regMainStackPointer = topOfMainStack;
230*a8f7f3fcSMatthias Ringwald }
231*a8f7f3fcSMatthias Ringwald
232*a8f7f3fcSMatthias Ringwald
233*a8f7f3fcSMatthias Ringwald /**
234*a8f7f3fcSMatthias Ringwald \brief Get Priority Mask
235*a8f7f3fcSMatthias Ringwald \details Returns the current state of the priority mask bit from the Priority Mask Register.
236*a8f7f3fcSMatthias Ringwald \return Priority Mask value
237*a8f7f3fcSMatthias Ringwald */
__get_PRIMASK(void)238*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_PRIMASK(void)
239*a8f7f3fcSMatthias Ringwald {
240*a8f7f3fcSMatthias Ringwald register uint32_t __regPriMask __ASM("primask");
241*a8f7f3fcSMatthias Ringwald return(__regPriMask);
242*a8f7f3fcSMatthias Ringwald }
243*a8f7f3fcSMatthias Ringwald
244*a8f7f3fcSMatthias Ringwald
245*a8f7f3fcSMatthias Ringwald /**
246*a8f7f3fcSMatthias Ringwald \brief Set Priority Mask
247*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Priority Mask Register.
248*a8f7f3fcSMatthias Ringwald \param [in] priMask Priority Mask
249*a8f7f3fcSMatthias Ringwald */
__set_PRIMASK(uint32_t priMask)250*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
251*a8f7f3fcSMatthias Ringwald {
252*a8f7f3fcSMatthias Ringwald register uint32_t __regPriMask __ASM("primask");
253*a8f7f3fcSMatthias Ringwald __regPriMask = (priMask);
254*a8f7f3fcSMatthias Ringwald }
255*a8f7f3fcSMatthias Ringwald
256*a8f7f3fcSMatthias Ringwald
257*a8f7f3fcSMatthias Ringwald #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
258*a8f7f3fcSMatthias Ringwald (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
259*a8f7f3fcSMatthias Ringwald
260*a8f7f3fcSMatthias Ringwald /**
261*a8f7f3fcSMatthias Ringwald \brief Enable FIQ
262*a8f7f3fcSMatthias Ringwald \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
263*a8f7f3fcSMatthias Ringwald Can only be executed in Privileged modes.
264*a8f7f3fcSMatthias Ringwald */
265*a8f7f3fcSMatthias Ringwald #define __enable_fault_irq __enable_fiq
266*a8f7f3fcSMatthias Ringwald
267*a8f7f3fcSMatthias Ringwald
268*a8f7f3fcSMatthias Ringwald /**
269*a8f7f3fcSMatthias Ringwald \brief Disable FIQ
270*a8f7f3fcSMatthias Ringwald \details Disables FIQ interrupts by setting the F-bit in the CPSR.
271*a8f7f3fcSMatthias Ringwald Can only be executed in Privileged modes.
272*a8f7f3fcSMatthias Ringwald */
273*a8f7f3fcSMatthias Ringwald #define __disable_fault_irq __disable_fiq
274*a8f7f3fcSMatthias Ringwald
275*a8f7f3fcSMatthias Ringwald
276*a8f7f3fcSMatthias Ringwald /**
277*a8f7f3fcSMatthias Ringwald \brief Get Base Priority
278*a8f7f3fcSMatthias Ringwald \details Returns the current value of the Base Priority register.
279*a8f7f3fcSMatthias Ringwald \return Base Priority register value
280*a8f7f3fcSMatthias Ringwald */
__get_BASEPRI(void)281*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_BASEPRI(void)
282*a8f7f3fcSMatthias Ringwald {
283*a8f7f3fcSMatthias Ringwald register uint32_t __regBasePri __ASM("basepri");
284*a8f7f3fcSMatthias Ringwald return(__regBasePri);
285*a8f7f3fcSMatthias Ringwald }
286*a8f7f3fcSMatthias Ringwald
287*a8f7f3fcSMatthias Ringwald
288*a8f7f3fcSMatthias Ringwald /**
289*a8f7f3fcSMatthias Ringwald \brief Set Base Priority
290*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Base Priority register.
291*a8f7f3fcSMatthias Ringwald \param [in] basePri Base Priority value to set
292*a8f7f3fcSMatthias Ringwald */
__set_BASEPRI(uint32_t basePri)293*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
294*a8f7f3fcSMatthias Ringwald {
295*a8f7f3fcSMatthias Ringwald register uint32_t __regBasePri __ASM("basepri");
296*a8f7f3fcSMatthias Ringwald __regBasePri = (basePri & 0xFFU);
297*a8f7f3fcSMatthias Ringwald }
298*a8f7f3fcSMatthias Ringwald
299*a8f7f3fcSMatthias Ringwald
300*a8f7f3fcSMatthias Ringwald /**
301*a8f7f3fcSMatthias Ringwald \brief Set Base Priority with condition
302*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
303*a8f7f3fcSMatthias Ringwald or the new value increases the BASEPRI priority level.
304*a8f7f3fcSMatthias Ringwald \param [in] basePri Base Priority value to set
305*a8f7f3fcSMatthias Ringwald */
__set_BASEPRI_MAX(uint32_t basePri)306*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
307*a8f7f3fcSMatthias Ringwald {
308*a8f7f3fcSMatthias Ringwald register uint32_t __regBasePriMax __ASM("basepri_max");
309*a8f7f3fcSMatthias Ringwald __regBasePriMax = (basePri & 0xFFU);
310*a8f7f3fcSMatthias Ringwald }
311*a8f7f3fcSMatthias Ringwald
312*a8f7f3fcSMatthias Ringwald
313*a8f7f3fcSMatthias Ringwald /**
314*a8f7f3fcSMatthias Ringwald \brief Get Fault Mask
315*a8f7f3fcSMatthias Ringwald \details Returns the current value of the Fault Mask register.
316*a8f7f3fcSMatthias Ringwald \return Fault Mask register value
317*a8f7f3fcSMatthias Ringwald */
__get_FAULTMASK(void)318*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_FAULTMASK(void)
319*a8f7f3fcSMatthias Ringwald {
320*a8f7f3fcSMatthias Ringwald register uint32_t __regFaultMask __ASM("faultmask");
321*a8f7f3fcSMatthias Ringwald return(__regFaultMask);
322*a8f7f3fcSMatthias Ringwald }
323*a8f7f3fcSMatthias Ringwald
324*a8f7f3fcSMatthias Ringwald
325*a8f7f3fcSMatthias Ringwald /**
326*a8f7f3fcSMatthias Ringwald \brief Set Fault Mask
327*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Fault Mask register.
328*a8f7f3fcSMatthias Ringwald \param [in] faultMask Fault Mask value to set
329*a8f7f3fcSMatthias Ringwald */
__set_FAULTMASK(uint32_t faultMask)330*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
331*a8f7f3fcSMatthias Ringwald {
332*a8f7f3fcSMatthias Ringwald register uint32_t __regFaultMask __ASM("faultmask");
333*a8f7f3fcSMatthias Ringwald __regFaultMask = (faultMask & (uint32_t)1U);
334*a8f7f3fcSMatthias Ringwald }
335*a8f7f3fcSMatthias Ringwald
336*a8f7f3fcSMatthias Ringwald #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
337*a8f7f3fcSMatthias Ringwald (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
338*a8f7f3fcSMatthias Ringwald
339*a8f7f3fcSMatthias Ringwald
340*a8f7f3fcSMatthias Ringwald /**
341*a8f7f3fcSMatthias Ringwald \brief Get FPSCR
342*a8f7f3fcSMatthias Ringwald \details Returns the current value of the Floating Point Status/Control register.
343*a8f7f3fcSMatthias Ringwald \return Floating Point Status/Control register value
344*a8f7f3fcSMatthias Ringwald */
__get_FPSCR(void)345*a8f7f3fcSMatthias Ringwald __STATIC_INLINE uint32_t __get_FPSCR(void)
346*a8f7f3fcSMatthias Ringwald {
347*a8f7f3fcSMatthias Ringwald #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
348*a8f7f3fcSMatthias Ringwald (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
349*a8f7f3fcSMatthias Ringwald register uint32_t __regfpscr __ASM("fpscr");
350*a8f7f3fcSMatthias Ringwald return(__regfpscr);
351*a8f7f3fcSMatthias Ringwald #else
352*a8f7f3fcSMatthias Ringwald return(0U);
353*a8f7f3fcSMatthias Ringwald #endif
354*a8f7f3fcSMatthias Ringwald }
355*a8f7f3fcSMatthias Ringwald
356*a8f7f3fcSMatthias Ringwald
357*a8f7f3fcSMatthias Ringwald /**
358*a8f7f3fcSMatthias Ringwald \brief Set FPSCR
359*a8f7f3fcSMatthias Ringwald \details Assigns the given value to the Floating Point Status/Control register.
360*a8f7f3fcSMatthias Ringwald \param [in] fpscr Floating Point Status/Control value to set
361*a8f7f3fcSMatthias Ringwald */
__set_FPSCR(uint32_t fpscr)362*a8f7f3fcSMatthias Ringwald __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
363*a8f7f3fcSMatthias Ringwald {
364*a8f7f3fcSMatthias Ringwald #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
365*a8f7f3fcSMatthias Ringwald (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
366*a8f7f3fcSMatthias Ringwald register uint32_t __regfpscr __ASM("fpscr");
367*a8f7f3fcSMatthias Ringwald __regfpscr = (fpscr);
368*a8f7f3fcSMatthias Ringwald #else
369*a8f7f3fcSMatthias Ringwald (void)fpscr;
370*a8f7f3fcSMatthias Ringwald #endif
371*a8f7f3fcSMatthias Ringwald }
372*a8f7f3fcSMatthias Ringwald
373*a8f7f3fcSMatthias Ringwald
374*a8f7f3fcSMatthias Ringwald /*@} end of CMSIS_Core_RegAccFunctions */
375*a8f7f3fcSMatthias Ringwald
376*a8f7f3fcSMatthias Ringwald
377*a8f7f3fcSMatthias Ringwald /* ########################## Core Instruction Access ######################### */
378*a8f7f3fcSMatthias Ringwald /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
379*a8f7f3fcSMatthias Ringwald Access to dedicated instructions
380*a8f7f3fcSMatthias Ringwald @{
381*a8f7f3fcSMatthias Ringwald */
382*a8f7f3fcSMatthias Ringwald
383*a8f7f3fcSMatthias Ringwald /**
384*a8f7f3fcSMatthias Ringwald \brief No Operation
385*a8f7f3fcSMatthias Ringwald \details No Operation does nothing. This instruction can be used for code alignment purposes.
386*a8f7f3fcSMatthias Ringwald */
387*a8f7f3fcSMatthias Ringwald #define __NOP __nop
388*a8f7f3fcSMatthias Ringwald
389*a8f7f3fcSMatthias Ringwald
390*a8f7f3fcSMatthias Ringwald /**
391*a8f7f3fcSMatthias Ringwald \brief Wait For Interrupt
392*a8f7f3fcSMatthias Ringwald \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
393*a8f7f3fcSMatthias Ringwald */
394*a8f7f3fcSMatthias Ringwald #define __WFI __wfi
395*a8f7f3fcSMatthias Ringwald
396*a8f7f3fcSMatthias Ringwald
397*a8f7f3fcSMatthias Ringwald /**
398*a8f7f3fcSMatthias Ringwald \brief Wait For Event
399*a8f7f3fcSMatthias Ringwald \details Wait For Event is a hint instruction that permits the processor to enter
400*a8f7f3fcSMatthias Ringwald a low-power state until one of a number of events occurs.
401*a8f7f3fcSMatthias Ringwald */
402*a8f7f3fcSMatthias Ringwald #define __WFE __wfe
403*a8f7f3fcSMatthias Ringwald
404*a8f7f3fcSMatthias Ringwald
405*a8f7f3fcSMatthias Ringwald /**
406*a8f7f3fcSMatthias Ringwald \brief Send Event
407*a8f7f3fcSMatthias Ringwald \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
408*a8f7f3fcSMatthias Ringwald */
409*a8f7f3fcSMatthias Ringwald #define __SEV __sev
410*a8f7f3fcSMatthias Ringwald
411*a8f7f3fcSMatthias Ringwald
412*a8f7f3fcSMatthias Ringwald /**
413*a8f7f3fcSMatthias Ringwald \brief Instruction Synchronization Barrier
414*a8f7f3fcSMatthias Ringwald \details Instruction Synchronization Barrier flushes the pipeline in the processor,
415*a8f7f3fcSMatthias Ringwald so that all instructions following the ISB are fetched from cache or memory,
416*a8f7f3fcSMatthias Ringwald after the instruction has been completed.
417*a8f7f3fcSMatthias Ringwald */
418*a8f7f3fcSMatthias Ringwald #define __ISB() do {\
419*a8f7f3fcSMatthias Ringwald __schedule_barrier();\
420*a8f7f3fcSMatthias Ringwald __isb(0xF);\
421*a8f7f3fcSMatthias Ringwald __schedule_barrier();\
422*a8f7f3fcSMatthias Ringwald } while (0U)
423*a8f7f3fcSMatthias Ringwald
424*a8f7f3fcSMatthias Ringwald /**
425*a8f7f3fcSMatthias Ringwald \brief Data Synchronization Barrier
426*a8f7f3fcSMatthias Ringwald \details Acts as a special kind of Data Memory Barrier.
427*a8f7f3fcSMatthias Ringwald It completes when all explicit memory accesses before this instruction complete.
428*a8f7f3fcSMatthias Ringwald */
429*a8f7f3fcSMatthias Ringwald #define __DSB() do {\
430*a8f7f3fcSMatthias Ringwald __schedule_barrier();\
431*a8f7f3fcSMatthias Ringwald __dsb(0xF);\
432*a8f7f3fcSMatthias Ringwald __schedule_barrier();\
433*a8f7f3fcSMatthias Ringwald } while (0U)
434*a8f7f3fcSMatthias Ringwald
435*a8f7f3fcSMatthias Ringwald /**
436*a8f7f3fcSMatthias Ringwald \brief Data Memory Barrier
437*a8f7f3fcSMatthias Ringwald \details Ensures the apparent order of the explicit memory operations before
438*a8f7f3fcSMatthias Ringwald and after the instruction, without ensuring their completion.
439*a8f7f3fcSMatthias Ringwald */
440*a8f7f3fcSMatthias Ringwald #define __DMB() do {\
441*a8f7f3fcSMatthias Ringwald __schedule_barrier();\
442*a8f7f3fcSMatthias Ringwald __dmb(0xF);\
443*a8f7f3fcSMatthias Ringwald __schedule_barrier();\
444*a8f7f3fcSMatthias Ringwald } while (0U)
445*a8f7f3fcSMatthias Ringwald
446*a8f7f3fcSMatthias Ringwald
447*a8f7f3fcSMatthias Ringwald /**
448*a8f7f3fcSMatthias Ringwald \brief Reverse byte order (32 bit)
449*a8f7f3fcSMatthias Ringwald \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
450*a8f7f3fcSMatthias Ringwald \param [in] value Value to reverse
451*a8f7f3fcSMatthias Ringwald \return Reversed value
452*a8f7f3fcSMatthias Ringwald */
453*a8f7f3fcSMatthias Ringwald #define __REV __rev
454*a8f7f3fcSMatthias Ringwald
455*a8f7f3fcSMatthias Ringwald
456*a8f7f3fcSMatthias Ringwald /**
457*a8f7f3fcSMatthias Ringwald \brief Reverse byte order (16 bit)
458*a8f7f3fcSMatthias Ringwald \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
459*a8f7f3fcSMatthias Ringwald \param [in] value Value to reverse
460*a8f7f3fcSMatthias Ringwald \return Reversed value
461*a8f7f3fcSMatthias Ringwald */
462*a8f7f3fcSMatthias Ringwald #ifndef __NO_EMBEDDED_ASM
__REV16(uint32_t value)463*a8f7f3fcSMatthias Ringwald __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
464*a8f7f3fcSMatthias Ringwald {
465*a8f7f3fcSMatthias Ringwald rev16 r0, r0
466*a8f7f3fcSMatthias Ringwald bx lr
467*a8f7f3fcSMatthias Ringwald }
468*a8f7f3fcSMatthias Ringwald #endif
469*a8f7f3fcSMatthias Ringwald
470*a8f7f3fcSMatthias Ringwald
471*a8f7f3fcSMatthias Ringwald /**
472*a8f7f3fcSMatthias Ringwald \brief Reverse byte order (16 bit)
473*a8f7f3fcSMatthias Ringwald \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
474*a8f7f3fcSMatthias Ringwald \param [in] value Value to reverse
475*a8f7f3fcSMatthias Ringwald \return Reversed value
476*a8f7f3fcSMatthias Ringwald */
477*a8f7f3fcSMatthias Ringwald #ifndef __NO_EMBEDDED_ASM
__REVSH(int16_t value)478*a8f7f3fcSMatthias Ringwald __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
479*a8f7f3fcSMatthias Ringwald {
480*a8f7f3fcSMatthias Ringwald revsh r0, r0
481*a8f7f3fcSMatthias Ringwald bx lr
482*a8f7f3fcSMatthias Ringwald }
483*a8f7f3fcSMatthias Ringwald #endif
484*a8f7f3fcSMatthias Ringwald
485*a8f7f3fcSMatthias Ringwald
486*a8f7f3fcSMatthias Ringwald /**
487*a8f7f3fcSMatthias Ringwald \brief Rotate Right in unsigned value (32 bit)
488*a8f7f3fcSMatthias Ringwald \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
489*a8f7f3fcSMatthias Ringwald \param [in] op1 Value to rotate
490*a8f7f3fcSMatthias Ringwald \param [in] op2 Number of Bits to rotate
491*a8f7f3fcSMatthias Ringwald \return Rotated value
492*a8f7f3fcSMatthias Ringwald */
493*a8f7f3fcSMatthias Ringwald #define __ROR __ror
494*a8f7f3fcSMatthias Ringwald
495*a8f7f3fcSMatthias Ringwald
496*a8f7f3fcSMatthias Ringwald /**
497*a8f7f3fcSMatthias Ringwald \brief Breakpoint
498*a8f7f3fcSMatthias Ringwald \details Causes the processor to enter Debug state.
499*a8f7f3fcSMatthias Ringwald Debug tools can use this to investigate system state when the instruction at a particular address is reached.
500*a8f7f3fcSMatthias Ringwald \param [in] value is ignored by the processor.
501*a8f7f3fcSMatthias Ringwald If required, a debugger can use it to store additional information about the breakpoint.
502*a8f7f3fcSMatthias Ringwald */
503*a8f7f3fcSMatthias Ringwald #define __BKPT(value) __breakpoint(value)
504*a8f7f3fcSMatthias Ringwald
505*a8f7f3fcSMatthias Ringwald
506*a8f7f3fcSMatthias Ringwald /**
507*a8f7f3fcSMatthias Ringwald \brief Reverse bit order of value
508*a8f7f3fcSMatthias Ringwald \details Reverses the bit order of the given value.
509*a8f7f3fcSMatthias Ringwald \param [in] value Value to reverse
510*a8f7f3fcSMatthias Ringwald \return Reversed value
511*a8f7f3fcSMatthias Ringwald */
512*a8f7f3fcSMatthias Ringwald #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
513*a8f7f3fcSMatthias Ringwald (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
514*a8f7f3fcSMatthias Ringwald #define __RBIT __rbit
515*a8f7f3fcSMatthias Ringwald #else
__RBIT(uint32_t value)516*a8f7f3fcSMatthias Ringwald __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
517*a8f7f3fcSMatthias Ringwald {
518*a8f7f3fcSMatthias Ringwald uint32_t result;
519*a8f7f3fcSMatthias Ringwald uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
520*a8f7f3fcSMatthias Ringwald
521*a8f7f3fcSMatthias Ringwald result = value; /* r will be reversed bits of v; first get LSB of v */
522*a8f7f3fcSMatthias Ringwald for (value >>= 1U; value != 0U; value >>= 1U)
523*a8f7f3fcSMatthias Ringwald {
524*a8f7f3fcSMatthias Ringwald result <<= 1U;
525*a8f7f3fcSMatthias Ringwald result |= value & 1U;
526*a8f7f3fcSMatthias Ringwald s--;
527*a8f7f3fcSMatthias Ringwald }
528*a8f7f3fcSMatthias Ringwald result <<= s; /* shift when v's highest bits are zero */
529*a8f7f3fcSMatthias Ringwald return result;
530*a8f7f3fcSMatthias Ringwald }
531*a8f7f3fcSMatthias Ringwald #endif
532*a8f7f3fcSMatthias Ringwald
533*a8f7f3fcSMatthias Ringwald
534*a8f7f3fcSMatthias Ringwald /**
535*a8f7f3fcSMatthias Ringwald \brief Count leading zeros
536*a8f7f3fcSMatthias Ringwald \details Counts the number of leading zeros of a data value.
537*a8f7f3fcSMatthias Ringwald \param [in] value Value to count the leading zeros
538*a8f7f3fcSMatthias Ringwald \return number of leading zeros in value
539*a8f7f3fcSMatthias Ringwald */
540*a8f7f3fcSMatthias Ringwald #define __CLZ __clz
541*a8f7f3fcSMatthias Ringwald
542*a8f7f3fcSMatthias Ringwald
543*a8f7f3fcSMatthias Ringwald #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
544*a8f7f3fcSMatthias Ringwald (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
545*a8f7f3fcSMatthias Ringwald
546*a8f7f3fcSMatthias Ringwald /**
547*a8f7f3fcSMatthias Ringwald \brief LDR Exclusive (8 bit)
548*a8f7f3fcSMatthias Ringwald \details Executes a exclusive LDR instruction for 8 bit value.
549*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to data
550*a8f7f3fcSMatthias Ringwald \return value of type uint8_t at (*ptr)
551*a8f7f3fcSMatthias Ringwald */
552*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
553*a8f7f3fcSMatthias Ringwald #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
554*a8f7f3fcSMatthias Ringwald #else
555*a8f7f3fcSMatthias Ringwald #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
556*a8f7f3fcSMatthias Ringwald #endif
557*a8f7f3fcSMatthias Ringwald
558*a8f7f3fcSMatthias Ringwald
559*a8f7f3fcSMatthias Ringwald /**
560*a8f7f3fcSMatthias Ringwald \brief LDR Exclusive (16 bit)
561*a8f7f3fcSMatthias Ringwald \details Executes a exclusive LDR instruction for 16 bit values.
562*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to data
563*a8f7f3fcSMatthias Ringwald \return value of type uint16_t at (*ptr)
564*a8f7f3fcSMatthias Ringwald */
565*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
566*a8f7f3fcSMatthias Ringwald #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
567*a8f7f3fcSMatthias Ringwald #else
568*a8f7f3fcSMatthias Ringwald #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
569*a8f7f3fcSMatthias Ringwald #endif
570*a8f7f3fcSMatthias Ringwald
571*a8f7f3fcSMatthias Ringwald
572*a8f7f3fcSMatthias Ringwald /**
573*a8f7f3fcSMatthias Ringwald \brief LDR Exclusive (32 bit)
574*a8f7f3fcSMatthias Ringwald \details Executes a exclusive LDR instruction for 32 bit values.
575*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to data
576*a8f7f3fcSMatthias Ringwald \return value of type uint32_t at (*ptr)
577*a8f7f3fcSMatthias Ringwald */
578*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
579*a8f7f3fcSMatthias Ringwald #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
580*a8f7f3fcSMatthias Ringwald #else
581*a8f7f3fcSMatthias Ringwald #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
582*a8f7f3fcSMatthias Ringwald #endif
583*a8f7f3fcSMatthias Ringwald
584*a8f7f3fcSMatthias Ringwald
585*a8f7f3fcSMatthias Ringwald /**
586*a8f7f3fcSMatthias Ringwald \brief STR Exclusive (8 bit)
587*a8f7f3fcSMatthias Ringwald \details Executes a exclusive STR instruction for 8 bit values.
588*a8f7f3fcSMatthias Ringwald \param [in] value Value to store
589*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to location
590*a8f7f3fcSMatthias Ringwald \return 0 Function succeeded
591*a8f7f3fcSMatthias Ringwald \return 1 Function failed
592*a8f7f3fcSMatthias Ringwald */
593*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
594*a8f7f3fcSMatthias Ringwald #define __STREXB(value, ptr) __strex(value, ptr)
595*a8f7f3fcSMatthias Ringwald #else
596*a8f7f3fcSMatthias Ringwald #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
597*a8f7f3fcSMatthias Ringwald #endif
598*a8f7f3fcSMatthias Ringwald
599*a8f7f3fcSMatthias Ringwald
600*a8f7f3fcSMatthias Ringwald /**
601*a8f7f3fcSMatthias Ringwald \brief STR Exclusive (16 bit)
602*a8f7f3fcSMatthias Ringwald \details Executes a exclusive STR instruction for 16 bit values.
603*a8f7f3fcSMatthias Ringwald \param [in] value Value to store
604*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to location
605*a8f7f3fcSMatthias Ringwald \return 0 Function succeeded
606*a8f7f3fcSMatthias Ringwald \return 1 Function failed
607*a8f7f3fcSMatthias Ringwald */
608*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
609*a8f7f3fcSMatthias Ringwald #define __STREXH(value, ptr) __strex(value, ptr)
610*a8f7f3fcSMatthias Ringwald #else
611*a8f7f3fcSMatthias Ringwald #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
612*a8f7f3fcSMatthias Ringwald #endif
613*a8f7f3fcSMatthias Ringwald
614*a8f7f3fcSMatthias Ringwald
615*a8f7f3fcSMatthias Ringwald /**
616*a8f7f3fcSMatthias Ringwald \brief STR Exclusive (32 bit)
617*a8f7f3fcSMatthias Ringwald \details Executes a exclusive STR instruction for 32 bit values.
618*a8f7f3fcSMatthias Ringwald \param [in] value Value to store
619*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to location
620*a8f7f3fcSMatthias Ringwald \return 0 Function succeeded
621*a8f7f3fcSMatthias Ringwald \return 1 Function failed
622*a8f7f3fcSMatthias Ringwald */
623*a8f7f3fcSMatthias Ringwald #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
624*a8f7f3fcSMatthias Ringwald #define __STREXW(value, ptr) __strex(value, ptr)
625*a8f7f3fcSMatthias Ringwald #else
626*a8f7f3fcSMatthias Ringwald #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
627*a8f7f3fcSMatthias Ringwald #endif
628*a8f7f3fcSMatthias Ringwald
629*a8f7f3fcSMatthias Ringwald
630*a8f7f3fcSMatthias Ringwald /**
631*a8f7f3fcSMatthias Ringwald \brief Remove the exclusive lock
632*a8f7f3fcSMatthias Ringwald \details Removes the exclusive lock which is created by LDREX.
633*a8f7f3fcSMatthias Ringwald */
634*a8f7f3fcSMatthias Ringwald #define __CLREX __clrex
635*a8f7f3fcSMatthias Ringwald
636*a8f7f3fcSMatthias Ringwald
637*a8f7f3fcSMatthias Ringwald /**
638*a8f7f3fcSMatthias Ringwald \brief Signed Saturate
639*a8f7f3fcSMatthias Ringwald \details Saturates a signed value.
640*a8f7f3fcSMatthias Ringwald \param [in] value Value to be saturated
641*a8f7f3fcSMatthias Ringwald \param [in] sat Bit position to saturate to (1..32)
642*a8f7f3fcSMatthias Ringwald \return Saturated value
643*a8f7f3fcSMatthias Ringwald */
644*a8f7f3fcSMatthias Ringwald #define __SSAT __ssat
645*a8f7f3fcSMatthias Ringwald
646*a8f7f3fcSMatthias Ringwald
647*a8f7f3fcSMatthias Ringwald /**
648*a8f7f3fcSMatthias Ringwald \brief Unsigned Saturate
649*a8f7f3fcSMatthias Ringwald \details Saturates an unsigned value.
650*a8f7f3fcSMatthias Ringwald \param [in] value Value to be saturated
651*a8f7f3fcSMatthias Ringwald \param [in] sat Bit position to saturate to (0..31)
652*a8f7f3fcSMatthias Ringwald \return Saturated value
653*a8f7f3fcSMatthias Ringwald */
654*a8f7f3fcSMatthias Ringwald #define __USAT __usat
655*a8f7f3fcSMatthias Ringwald
656*a8f7f3fcSMatthias Ringwald
657*a8f7f3fcSMatthias Ringwald /**
658*a8f7f3fcSMatthias Ringwald \brief Rotate Right with Extend (32 bit)
659*a8f7f3fcSMatthias Ringwald \details Moves each bit of a bitstring right by one bit.
660*a8f7f3fcSMatthias Ringwald The carry input is shifted in at the left end of the bitstring.
661*a8f7f3fcSMatthias Ringwald \param [in] value Value to rotate
662*a8f7f3fcSMatthias Ringwald \return Rotated value
663*a8f7f3fcSMatthias Ringwald */
664*a8f7f3fcSMatthias Ringwald #ifndef __NO_EMBEDDED_ASM
__RRX(uint32_t value)665*a8f7f3fcSMatthias Ringwald __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
666*a8f7f3fcSMatthias Ringwald {
667*a8f7f3fcSMatthias Ringwald rrx r0, r0
668*a8f7f3fcSMatthias Ringwald bx lr
669*a8f7f3fcSMatthias Ringwald }
670*a8f7f3fcSMatthias Ringwald #endif
671*a8f7f3fcSMatthias Ringwald
672*a8f7f3fcSMatthias Ringwald
673*a8f7f3fcSMatthias Ringwald /**
674*a8f7f3fcSMatthias Ringwald \brief LDRT Unprivileged (8 bit)
675*a8f7f3fcSMatthias Ringwald \details Executes a Unprivileged LDRT instruction for 8 bit value.
676*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to data
677*a8f7f3fcSMatthias Ringwald \return value of type uint8_t at (*ptr)
678*a8f7f3fcSMatthias Ringwald */
679*a8f7f3fcSMatthias Ringwald #define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
680*a8f7f3fcSMatthias Ringwald
681*a8f7f3fcSMatthias Ringwald
682*a8f7f3fcSMatthias Ringwald /**
683*a8f7f3fcSMatthias Ringwald \brief LDRT Unprivileged (16 bit)
684*a8f7f3fcSMatthias Ringwald \details Executes a Unprivileged LDRT instruction for 16 bit values.
685*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to data
686*a8f7f3fcSMatthias Ringwald \return value of type uint16_t at (*ptr)
687*a8f7f3fcSMatthias Ringwald */
688*a8f7f3fcSMatthias Ringwald #define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
689*a8f7f3fcSMatthias Ringwald
690*a8f7f3fcSMatthias Ringwald
691*a8f7f3fcSMatthias Ringwald /**
692*a8f7f3fcSMatthias Ringwald \brief LDRT Unprivileged (32 bit)
693*a8f7f3fcSMatthias Ringwald \details Executes a Unprivileged LDRT instruction for 32 bit values.
694*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to data
695*a8f7f3fcSMatthias Ringwald \return value of type uint32_t at (*ptr)
696*a8f7f3fcSMatthias Ringwald */
697*a8f7f3fcSMatthias Ringwald #define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
698*a8f7f3fcSMatthias Ringwald
699*a8f7f3fcSMatthias Ringwald
700*a8f7f3fcSMatthias Ringwald /**
701*a8f7f3fcSMatthias Ringwald \brief STRT Unprivileged (8 bit)
702*a8f7f3fcSMatthias Ringwald \details Executes a Unprivileged STRT instruction for 8 bit values.
703*a8f7f3fcSMatthias Ringwald \param [in] value Value to store
704*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to location
705*a8f7f3fcSMatthias Ringwald */
706*a8f7f3fcSMatthias Ringwald #define __STRBT(value, ptr) __strt(value, ptr)
707*a8f7f3fcSMatthias Ringwald
708*a8f7f3fcSMatthias Ringwald
709*a8f7f3fcSMatthias Ringwald /**
710*a8f7f3fcSMatthias Ringwald \brief STRT Unprivileged (16 bit)
711*a8f7f3fcSMatthias Ringwald \details Executes a Unprivileged STRT instruction for 16 bit values.
712*a8f7f3fcSMatthias Ringwald \param [in] value Value to store
713*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to location
714*a8f7f3fcSMatthias Ringwald */
715*a8f7f3fcSMatthias Ringwald #define __STRHT(value, ptr) __strt(value, ptr)
716*a8f7f3fcSMatthias Ringwald
717*a8f7f3fcSMatthias Ringwald
718*a8f7f3fcSMatthias Ringwald /**
719*a8f7f3fcSMatthias Ringwald \brief STRT Unprivileged (32 bit)
720*a8f7f3fcSMatthias Ringwald \details Executes a Unprivileged STRT instruction for 32 bit values.
721*a8f7f3fcSMatthias Ringwald \param [in] value Value to store
722*a8f7f3fcSMatthias Ringwald \param [in] ptr Pointer to location
723*a8f7f3fcSMatthias Ringwald */
724*a8f7f3fcSMatthias Ringwald #define __STRT(value, ptr) __strt(value, ptr)
725*a8f7f3fcSMatthias Ringwald
726*a8f7f3fcSMatthias Ringwald #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
727*a8f7f3fcSMatthias Ringwald (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
728*a8f7f3fcSMatthias Ringwald
729*a8f7f3fcSMatthias Ringwald /**
730*a8f7f3fcSMatthias Ringwald \brief Signed Saturate
731*a8f7f3fcSMatthias Ringwald \details Saturates a signed value.
732*a8f7f3fcSMatthias Ringwald \param [in] value Value to be saturated
733*a8f7f3fcSMatthias Ringwald \param [in] sat Bit position to saturate to (1..32)
734*a8f7f3fcSMatthias Ringwald \return Saturated value
735*a8f7f3fcSMatthias Ringwald */
__SSAT(int32_t val,uint32_t sat)736*a8f7f3fcSMatthias Ringwald __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
737*a8f7f3fcSMatthias Ringwald {
738*a8f7f3fcSMatthias Ringwald if ((sat >= 1U) && (sat <= 32U))
739*a8f7f3fcSMatthias Ringwald {
740*a8f7f3fcSMatthias Ringwald const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
741*a8f7f3fcSMatthias Ringwald const int32_t min = -1 - max ;
742*a8f7f3fcSMatthias Ringwald if (val > max)
743*a8f7f3fcSMatthias Ringwald {
744*a8f7f3fcSMatthias Ringwald return max;
745*a8f7f3fcSMatthias Ringwald }
746*a8f7f3fcSMatthias Ringwald else if (val < min)
747*a8f7f3fcSMatthias Ringwald {
748*a8f7f3fcSMatthias Ringwald return min;
749*a8f7f3fcSMatthias Ringwald }
750*a8f7f3fcSMatthias Ringwald }
751*a8f7f3fcSMatthias Ringwald return val;
752*a8f7f3fcSMatthias Ringwald }
753*a8f7f3fcSMatthias Ringwald
754*a8f7f3fcSMatthias Ringwald /**
755*a8f7f3fcSMatthias Ringwald \brief Unsigned Saturate
756*a8f7f3fcSMatthias Ringwald \details Saturates an unsigned value.
757*a8f7f3fcSMatthias Ringwald \param [in] value Value to be saturated
758*a8f7f3fcSMatthias Ringwald \param [in] sat Bit position to saturate to (0..31)
759*a8f7f3fcSMatthias Ringwald \return Saturated value
760*a8f7f3fcSMatthias Ringwald */
__USAT(int32_t val,uint32_t sat)761*a8f7f3fcSMatthias Ringwald __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
762*a8f7f3fcSMatthias Ringwald {
763*a8f7f3fcSMatthias Ringwald if (sat <= 31U)
764*a8f7f3fcSMatthias Ringwald {
765*a8f7f3fcSMatthias Ringwald const uint32_t max = ((1U << sat) - 1U);
766*a8f7f3fcSMatthias Ringwald if (val > (int32_t)max)
767*a8f7f3fcSMatthias Ringwald {
768*a8f7f3fcSMatthias Ringwald return max;
769*a8f7f3fcSMatthias Ringwald }
770*a8f7f3fcSMatthias Ringwald else if (val < 0)
771*a8f7f3fcSMatthias Ringwald {
772*a8f7f3fcSMatthias Ringwald return 0U;
773*a8f7f3fcSMatthias Ringwald }
774*a8f7f3fcSMatthias Ringwald }
775*a8f7f3fcSMatthias Ringwald return (uint32_t)val;
776*a8f7f3fcSMatthias Ringwald }
777*a8f7f3fcSMatthias Ringwald
778*a8f7f3fcSMatthias Ringwald #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
779*a8f7f3fcSMatthias Ringwald (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
780*a8f7f3fcSMatthias Ringwald
781*a8f7f3fcSMatthias Ringwald /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
782*a8f7f3fcSMatthias Ringwald
783*a8f7f3fcSMatthias Ringwald
784*a8f7f3fcSMatthias Ringwald /* ################### Compiler specific Intrinsics ########################### */
785*a8f7f3fcSMatthias Ringwald /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
786*a8f7f3fcSMatthias Ringwald Access to dedicated SIMD instructions
787*a8f7f3fcSMatthias Ringwald @{
788*a8f7f3fcSMatthias Ringwald */
789*a8f7f3fcSMatthias Ringwald
790*a8f7f3fcSMatthias Ringwald #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
791*a8f7f3fcSMatthias Ringwald
792*a8f7f3fcSMatthias Ringwald #define __SADD8 __sadd8
793*a8f7f3fcSMatthias Ringwald #define __QADD8 __qadd8
794*a8f7f3fcSMatthias Ringwald #define __SHADD8 __shadd8
795*a8f7f3fcSMatthias Ringwald #define __UADD8 __uadd8
796*a8f7f3fcSMatthias Ringwald #define __UQADD8 __uqadd8
797*a8f7f3fcSMatthias Ringwald #define __UHADD8 __uhadd8
798*a8f7f3fcSMatthias Ringwald #define __SSUB8 __ssub8
799*a8f7f3fcSMatthias Ringwald #define __QSUB8 __qsub8
800*a8f7f3fcSMatthias Ringwald #define __SHSUB8 __shsub8
801*a8f7f3fcSMatthias Ringwald #define __USUB8 __usub8
802*a8f7f3fcSMatthias Ringwald #define __UQSUB8 __uqsub8
803*a8f7f3fcSMatthias Ringwald #define __UHSUB8 __uhsub8
804*a8f7f3fcSMatthias Ringwald #define __SADD16 __sadd16
805*a8f7f3fcSMatthias Ringwald #define __QADD16 __qadd16
806*a8f7f3fcSMatthias Ringwald #define __SHADD16 __shadd16
807*a8f7f3fcSMatthias Ringwald #define __UADD16 __uadd16
808*a8f7f3fcSMatthias Ringwald #define __UQADD16 __uqadd16
809*a8f7f3fcSMatthias Ringwald #define __UHADD16 __uhadd16
810*a8f7f3fcSMatthias Ringwald #define __SSUB16 __ssub16
811*a8f7f3fcSMatthias Ringwald #define __QSUB16 __qsub16
812*a8f7f3fcSMatthias Ringwald #define __SHSUB16 __shsub16
813*a8f7f3fcSMatthias Ringwald #define __USUB16 __usub16
814*a8f7f3fcSMatthias Ringwald #define __UQSUB16 __uqsub16
815*a8f7f3fcSMatthias Ringwald #define __UHSUB16 __uhsub16
816*a8f7f3fcSMatthias Ringwald #define __SASX __sasx
817*a8f7f3fcSMatthias Ringwald #define __QASX __qasx
818*a8f7f3fcSMatthias Ringwald #define __SHASX __shasx
819*a8f7f3fcSMatthias Ringwald #define __UASX __uasx
820*a8f7f3fcSMatthias Ringwald #define __UQASX __uqasx
821*a8f7f3fcSMatthias Ringwald #define __UHASX __uhasx
822*a8f7f3fcSMatthias Ringwald #define __SSAX __ssax
823*a8f7f3fcSMatthias Ringwald #define __QSAX __qsax
824*a8f7f3fcSMatthias Ringwald #define __SHSAX __shsax
825*a8f7f3fcSMatthias Ringwald #define __USAX __usax
826*a8f7f3fcSMatthias Ringwald #define __UQSAX __uqsax
827*a8f7f3fcSMatthias Ringwald #define __UHSAX __uhsax
828*a8f7f3fcSMatthias Ringwald #define __USAD8 __usad8
829*a8f7f3fcSMatthias Ringwald #define __USADA8 __usada8
830*a8f7f3fcSMatthias Ringwald #define __SSAT16 __ssat16
831*a8f7f3fcSMatthias Ringwald #define __USAT16 __usat16
832*a8f7f3fcSMatthias Ringwald #define __UXTB16 __uxtb16
833*a8f7f3fcSMatthias Ringwald #define __UXTAB16 __uxtab16
834*a8f7f3fcSMatthias Ringwald #define __SXTB16 __sxtb16
835*a8f7f3fcSMatthias Ringwald #define __SXTAB16 __sxtab16
836*a8f7f3fcSMatthias Ringwald #define __SMUAD __smuad
837*a8f7f3fcSMatthias Ringwald #define __SMUADX __smuadx
838*a8f7f3fcSMatthias Ringwald #define __SMLAD __smlad
839*a8f7f3fcSMatthias Ringwald #define __SMLADX __smladx
840*a8f7f3fcSMatthias Ringwald #define __SMLALD __smlald
841*a8f7f3fcSMatthias Ringwald #define __SMLALDX __smlaldx
842*a8f7f3fcSMatthias Ringwald #define __SMUSD __smusd
843*a8f7f3fcSMatthias Ringwald #define __SMUSDX __smusdx
844*a8f7f3fcSMatthias Ringwald #define __SMLSD __smlsd
845*a8f7f3fcSMatthias Ringwald #define __SMLSDX __smlsdx
846*a8f7f3fcSMatthias Ringwald #define __SMLSLD __smlsld
847*a8f7f3fcSMatthias Ringwald #define __SMLSLDX __smlsldx
848*a8f7f3fcSMatthias Ringwald #define __SEL __sel
849*a8f7f3fcSMatthias Ringwald #define __QADD __qadd
850*a8f7f3fcSMatthias Ringwald #define __QSUB __qsub
851*a8f7f3fcSMatthias Ringwald
852*a8f7f3fcSMatthias Ringwald #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
853*a8f7f3fcSMatthias Ringwald ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
854*a8f7f3fcSMatthias Ringwald
855*a8f7f3fcSMatthias Ringwald #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
856*a8f7f3fcSMatthias Ringwald ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
857*a8f7f3fcSMatthias Ringwald
858*a8f7f3fcSMatthias Ringwald #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
859*a8f7f3fcSMatthias Ringwald ((int64_t)(ARG3) << 32U) ) >> 32U))
860*a8f7f3fcSMatthias Ringwald
861*a8f7f3fcSMatthias Ringwald #endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
862*a8f7f3fcSMatthias Ringwald /*@} end of group CMSIS_SIMD_intrinsics */
863*a8f7f3fcSMatthias Ringwald
864*a8f7f3fcSMatthias Ringwald
865*a8f7f3fcSMatthias Ringwald #endif /* __CMSIS_ARMCC_H */
866