1 /**************************************************************************//**
3 * @brief CMSIS compiler GCC header file
5 * @date 13. February 2017
6 ******************************************************************************/
8 * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the License); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
28 /* ignore some GCC warnings */
29 #pragma GCC diagnostic push
30 #pragma GCC diagnostic ignored "-Wsign-conversion"
31 #pragma GCC diagnostic ignored "-Wconversion"
32 #pragma GCC diagnostic ignored "-Wunused-parameter"
34 /* Fallback for __has_builtin */
36 #define __has_builtin(x) (0)
39 /* CMSIS compiler specific defines */
44 #define __INLINE inline
46 #ifndef __STATIC_INLINE
47 #define __STATIC_INLINE static inline
50 #define __NO_RETURN __attribute__((noreturn))
53 #define __USED __attribute__((used))
56 #define __WEAK __attribute__((weak))
59 #define __PACKED __attribute__((packed, aligned(1)))
61 #ifndef __PACKED_STRUCT
62 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
64 #ifndef __PACKED_UNION
65 #define __PACKED_UNION union __attribute__((packed, aligned(1)))
67 #ifndef __UNALIGNED_UINT32 /* deprecated */
68 #pragma GCC diagnostic push
69 #pragma GCC diagnostic ignored "-Wpacked"
70 #pragma GCC diagnostic ignored "-Wattributes"
71 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
72 #pragma GCC diagnostic pop
73 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
75 #ifndef __UNALIGNED_UINT16_WRITE
76 #pragma GCC diagnostic push
77 #pragma GCC diagnostic ignored "-Wpacked"
78 #pragma GCC diagnostic ignored "-Wattributes"
79 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
80 #pragma GCC diagnostic pop
81 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
83 #ifndef __UNALIGNED_UINT16_READ
84 #pragma GCC diagnostic push
85 #pragma GCC diagnostic ignored "-Wpacked"
86 #pragma GCC diagnostic ignored "-Wattributes"
87 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
88 #pragma GCC diagnostic pop
89 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
91 #ifndef __UNALIGNED_UINT32_WRITE
92 #pragma GCC diagnostic push
93 #pragma GCC diagnostic ignored "-Wpacked"
94 #pragma GCC diagnostic ignored "-Wattributes"
95 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
96 #pragma GCC diagnostic pop
97 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
99 #ifndef __UNALIGNED_UINT32_READ
100 #pragma GCC diagnostic push
101 #pragma GCC diagnostic ignored "-Wpacked"
102 #pragma GCC diagnostic ignored "-Wattributes"
103 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
104 #pragma GCC diagnostic pop
105 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
108 #define __ALIGNED(x) __attribute__((aligned(x)))
111 #define __RESTRICT __restrict
115 /* ########################### Core Function Access ########################### */
116 /** \ingroup CMSIS_Core_FunctionInterface
117 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
122 \brief Enable IRQ Interrupts
123 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
124 Can only be executed in Privileged modes.
126 __attribute__((always_inline)) __STATIC_INLINE void __enable_irq(void)
128 __ASM volatile ("cpsie i" : : : "memory");
133 \brief Disable IRQ Interrupts
134 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
135 Can only be executed in Privileged modes.
137 __attribute__((always_inline)) __STATIC_INLINE void __disable_irq(void)
139 __ASM volatile ("cpsid i" : : : "memory");
144 \brief Get Control Register
145 \details Returns the content of the Control Register.
146 \return Control Register value
148 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_CONTROL(void)
152 __ASM volatile ("MRS %0, control" : "=r" (result) );
157 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
159 \brief Get Control Register (non-secure)
160 \details Returns the content of the non-secure Control Register when in secure mode.
161 \return non-secure Control Register value
163 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_CONTROL_NS(void)
167 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
174 \brief Set Control Register
175 \details Writes the given value to the Control Register.
176 \param [in] control Control Register value to set
178 __attribute__((always_inline)) __STATIC_INLINE void __set_CONTROL(uint32_t control)
180 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
184 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
186 \brief Set Control Register (non-secure)
187 \details Writes the given value to the non-secure Control Register when in secure state.
188 \param [in] control Control Register value to set
190 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_CONTROL_NS(uint32_t control)
192 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
198 \brief Get IPSR Register
199 \details Returns the content of the IPSR Register.
200 \return IPSR Register value
202 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_IPSR(void)
206 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
212 \brief Get APSR Register
213 \details Returns the content of the APSR Register.
214 \return APSR Register value
216 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_APSR(void)
220 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
226 \brief Get xPSR Register
227 \details Returns the content of the xPSR Register.
228 \return xPSR Register value
230 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_xPSR(void)
234 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
240 \brief Get Process Stack Pointer
241 \details Returns the current value of the Process Stack Pointer (PSP).
242 \return PSP Register value
244 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSP(void)
246 register uint32_t result;
248 __ASM volatile ("MRS %0, psp" : "=r" (result) );
253 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
255 \brief Get Process Stack Pointer (non-secure)
256 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
257 \return PSP Register value
259 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PSP_NS(void)
261 register uint32_t result;
263 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
270 \brief Set Process Stack Pointer
271 \details Assigns the given value to the Process Stack Pointer (PSP).
272 \param [in] topOfProcStack Process Stack Pointer value to set
274 __attribute__((always_inline)) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
276 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
280 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
282 \brief Set Process Stack Pointer (non-secure)
283 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
284 \param [in] topOfProcStack Process Stack Pointer value to set
286 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
288 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
294 \brief Get Main Stack Pointer
295 \details Returns the current value of the Main Stack Pointer (MSP).
296 \return MSP Register value
298 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSP(void)
300 register uint32_t result;
302 __ASM volatile ("MRS %0, msp" : "=r" (result) );
307 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
309 \brief Get Main Stack Pointer (non-secure)
310 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
311 \return MSP Register value
313 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_MSP_NS(void)
315 register uint32_t result;
317 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
324 \brief Set Main Stack Pointer
325 \details Assigns the given value to the Main Stack Pointer (MSP).
326 \param [in] topOfMainStack Main Stack Pointer value to set
328 __attribute__((always_inline)) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
330 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
334 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
336 \brief Set Main Stack Pointer (non-secure)
337 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
338 \param [in] topOfMainStack Main Stack Pointer value to set
340 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
342 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
347 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
349 \brief Get Stack Pointer (non-secure)
350 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
351 \return SP Register value
353 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_SP_NS(void)
355 register uint32_t result;
357 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
363 \brief Set Stack Pointer (non-secure)
364 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
365 \param [in] topOfStack Stack Pointer value to set
367 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_SP_NS(uint32_t topOfStack)
369 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
375 \brief Get Priority Mask
376 \details Returns the current state of the priority mask bit from the Priority Mask Register.
377 \return Priority Mask value
379 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PRIMASK(void)
383 __ASM volatile ("MRS %0, primask" : "=r" (result) );
388 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
390 \brief Get Priority Mask (non-secure)
391 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
392 \return Priority Mask value
394 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PRIMASK_NS(void)
398 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
405 \brief Set Priority Mask
406 \details Assigns the given value to the Priority Mask Register.
407 \param [in] priMask Priority Mask
409 __attribute__((always_inline)) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
411 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
415 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
417 \brief Set Priority Mask (non-secure)
418 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
419 \param [in] priMask Priority Mask
421 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
423 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
428 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
429 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
430 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
433 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
434 Can only be executed in Privileged modes.
436 __attribute__((always_inline)) __STATIC_INLINE void __enable_fault_irq(void)
438 __ASM volatile ("cpsie f" : : : "memory");
444 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
445 Can only be executed in Privileged modes.
447 __attribute__((always_inline)) __STATIC_INLINE void __disable_fault_irq(void)
449 __ASM volatile ("cpsid f" : : : "memory");
454 \brief Get Base Priority
455 \details Returns the current value of the Base Priority register.
456 \return Base Priority register value
458 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_BASEPRI(void)
462 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
467 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
469 \brief Get Base Priority (non-secure)
470 \details Returns the current value of the non-secure Base Priority register when in secure state.
471 \return Base Priority register value
473 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_BASEPRI_NS(void)
477 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
484 \brief Set Base Priority
485 \details Assigns the given value to the Base Priority register.
486 \param [in] basePri Base Priority value to set
488 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
490 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
494 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
496 \brief Set Base Priority (non-secure)
497 \details Assigns the given value to the non-secure Base Priority register when in secure state.
498 \param [in] basePri Base Priority value to set
500 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
502 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
508 \brief Set Base Priority with condition
509 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
510 or the new value increases the BASEPRI priority level.
511 \param [in] basePri Base Priority value to set
513 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
515 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
520 \brief Get Fault Mask
521 \details Returns the current value of the Fault Mask register.
522 \return Fault Mask register value
524 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
528 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
533 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
535 \brief Get Fault Mask (non-secure)
536 \details Returns the current value of the non-secure Fault Mask register when in secure state.
537 \return Fault Mask register value
539 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_FAULTMASK_NS(void)
543 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
550 \brief Set Fault Mask
551 \details Assigns the given value to the Fault Mask register.
552 \param [in] faultMask Fault Mask value to set
554 __attribute__((always_inline)) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
556 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
560 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
562 \brief Set Fault Mask (non-secure)
563 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
564 \param [in] faultMask Fault Mask value to set
566 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
568 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
572 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
573 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
574 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
577 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
578 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
581 \brief Get Process Stack Pointer Limit
582 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
583 \return PSPLIM Register value
585 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSPLIM(void)
587 register uint32_t result;
589 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
594 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
595 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
597 \brief Get Process Stack Pointer Limit (non-secure)
598 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
599 \return PSPLIM Register value
601 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PSPLIM_NS(void)
603 register uint32_t result;
605 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
612 \brief Set Process Stack Pointer Limit
613 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
614 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
616 __attribute__((always_inline)) __STATIC_INLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
618 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
622 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
623 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
625 \brief Set Process Stack Pointer (non-secure)
626 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
627 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
629 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
631 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
637 \brief Get Main Stack Pointer Limit
638 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
639 \return MSPLIM Register value
641 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSPLIM(void)
643 register uint32_t result;
645 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
651 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
652 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
654 \brief Get Main Stack Pointer Limit (non-secure)
655 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
656 \return MSPLIM Register value
658 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_MSPLIM_NS(void)
660 register uint32_t result;
662 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
669 \brief Set Main Stack Pointer Limit
670 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
671 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
673 __attribute__((always_inline)) __STATIC_INLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
675 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
679 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
680 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
682 \brief Set Main Stack Pointer Limit (non-secure)
683 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
684 \param [in] MainStackPtrLimit Main Stack Pointer value to set
686 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
688 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
692 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
693 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
696 #if ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
697 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
701 \details Returns the current value of the Floating Point Status/Control register.
702 \return Floating Point Status/Control register value
704 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FPSCR(void)
706 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
707 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
708 #if __has_builtin(__builtin_arm_get_fpscr) || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
709 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
710 return __builtin_arm_get_fpscr();
714 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
725 \details Assigns the given value to the Floating Point Status/Control register.
726 \param [in] fpscr Floating Point Status/Control value to set
728 __attribute__((always_inline)) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
730 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
731 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
732 #if __has_builtin(__builtin_arm_set_fpscr) || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
733 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
734 __builtin_arm_set_fpscr(fpscr);
736 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
743 #endif /* ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
744 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
748 /*@} end of CMSIS_Core_RegAccFunctions */
751 /* ########################## Core Instruction Access ######################### */
752 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
753 Access to dedicated instructions
757 /* Define macros for porting to both thumb1 and thumb2.
758 * For thumb1, use low register (r0-r7), specified by constraint "l"
759 * Otherwise, use general registers, specified by constraint "r" */
760 #if defined (__thumb__) && !defined (__thumb2__)
761 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
762 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
763 #define __CMSIS_GCC_USE_REG(r) "l" (r)
765 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
766 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
767 #define __CMSIS_GCC_USE_REG(r) "r" (r)
772 \details No Operation does nothing. This instruction can be used for code alignment purposes.
774 //__attribute__((always_inline)) __STATIC_INLINE void __NOP(void)
776 // __ASM volatile ("nop");
778 #define __NOP() __ASM volatile ("nop") /* This implementation generates debug information */
781 \brief Wait For Interrupt
782 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
784 //__attribute__((always_inline)) __STATIC_INLINE void __WFI(void)
786 // __ASM volatile ("wfi");
788 #define __WFI() __ASM volatile ("wfi") /* This implementation generates debug information */
792 \brief Wait For Event
793 \details Wait For Event is a hint instruction that permits the processor to enter
794 a low-power state until one of a number of events occurs.
796 //__attribute__((always_inline)) __STATIC_INLINE void __WFE(void)
798 // __ASM volatile ("wfe");
800 #define __WFE() __ASM volatile ("wfe") /* This implementation generates debug information */
805 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
807 //__attribute__((always_inline)) __STATIC_INLINE void __SEV(void)
809 // __ASM volatile ("sev");
811 #define __SEV() __ASM volatile ("sev") /* This implementation generates debug information */
815 \brief Instruction Synchronization Barrier
816 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
817 so that all instructions following the ISB are fetched from cache or memory,
818 after the instruction has been completed.
820 __attribute__((always_inline)) __STATIC_INLINE void __ISB(void)
822 __ASM volatile ("isb 0xF":::"memory");
827 \brief Data Synchronization Barrier
828 \details Acts as a special kind of Data Memory Barrier.
829 It completes when all explicit memory accesses before this instruction complete.
831 __attribute__((always_inline)) __STATIC_INLINE void __DSB(void)
833 __ASM volatile ("dsb 0xF":::"memory");
838 \brief Data Memory Barrier
839 \details Ensures the apparent order of the explicit memory operations before
840 and after the instruction, without ensuring their completion.
842 __attribute__((always_inline)) __STATIC_INLINE void __DMB(void)
844 __ASM volatile ("dmb 0xF":::"memory");
849 \brief Reverse byte order (32 bit)
850 \details Reverses the byte order in unsigned integer value.
851 \param [in] value Value to reverse
852 \return Reversed value
854 __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value)
856 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
857 return __builtin_bswap32(value);
861 __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
868 \brief Reverse byte order (16 bit)
869 \details Reverses the byte order in unsigned short value.
870 \param [in] value Value to reverse
871 \return Reversed value
873 __attribute__((always_inline)) __STATIC_INLINE uint16_t __REV16(uint16_t value)
877 __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
883 \brief Reverse byte order in signed short value
884 \details Reverses the byte order in a signed short value with sign extension to integer.
885 \param [in] value Value to reverse
886 \return Reversed value
888 __attribute__((always_inline)) __STATIC_INLINE int16_t __REVSH(int16_t value)
890 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
891 return (int16_t)__builtin_bswap16(value);
895 __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
902 \brief Rotate Right in unsigned value (32 bit)
903 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
904 \param [in] op1 Value to rotate
905 \param [in] op2 Number of Bits to rotate
906 \return Rotated value
908 __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
910 return (op1 >> op2) | (op1 << (32U - op2));
916 \details Causes the processor to enter Debug state.
917 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
918 \param [in] value is ignored by the processor.
919 If required, a debugger can use it to store additional information about the breakpoint.
921 #define __BKPT(value) __ASM volatile ("bkpt "#value)
925 \brief Reverse bit order of value
926 \details Reverses the bit order of the given value.
927 \param [in] value Value to reverse
928 \return Reversed value
930 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
934 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
935 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
936 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
937 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
939 uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
941 result = value; /* r will be reversed bits of v; first get LSB of v */
942 for (value >>= 1U; value != 0U; value >>= 1U)
945 result |= value & 1U;
948 result <<= s; /* shift when v's highest bits are zero */
955 \brief Count leading zeros
956 \details Counts the number of leading zeros of a data value.
957 \param [in] value Value to count the leading zeros
958 \return number of leading zeros in value
960 #define __CLZ __builtin_clz
963 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
964 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
965 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
966 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
968 \brief LDR Exclusive (8 bit)
969 \details Executes a exclusive LDR instruction for 8 bit value.
970 \param [in] ptr Pointer to data
971 \return value of type uint8_t at (*ptr)
973 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
977 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
978 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
980 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
981 accepted by assembler. So has to use following less efficient pattern.
983 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
985 return ((uint8_t) result); /* Add explicit type cast here */
990 \brief LDR Exclusive (16 bit)
991 \details Executes a exclusive LDR instruction for 16 bit values.
992 \param [in] ptr Pointer to data
993 \return value of type uint16_t at (*ptr)
995 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
999 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1000 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
1002 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1003 accepted by assembler. So has to use following less efficient pattern.
1005 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1007 return ((uint16_t) result); /* Add explicit type cast here */
1012 \brief LDR Exclusive (32 bit)
1013 \details Executes a exclusive LDR instruction for 32 bit values.
1014 \param [in] ptr Pointer to data
1015 \return value of type uint32_t at (*ptr)
1017 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
1021 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
1027 \brief STR Exclusive (8 bit)
1028 \details Executes a exclusive STR instruction for 8 bit values.
1029 \param [in] value Value to store
1030 \param [in] ptr Pointer to location
1031 \return 0 Function succeeded
1032 \return 1 Function failed
1034 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
1038 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1044 \brief STR Exclusive (16 bit)
1045 \details Executes a exclusive STR instruction for 16 bit values.
1046 \param [in] value Value to store
1047 \param [in] ptr Pointer to location
1048 \return 0 Function succeeded
1049 \return 1 Function failed
1051 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
1055 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1061 \brief STR Exclusive (32 bit)
1062 \details Executes a exclusive STR instruction for 32 bit values.
1063 \param [in] value Value to store
1064 \param [in] ptr Pointer to location
1065 \return 0 Function succeeded
1066 \return 1 Function failed
1068 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
1072 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
1078 \brief Remove the exclusive lock
1079 \details Removes the exclusive lock which is created by LDREX.
1081 __attribute__((always_inline)) __STATIC_INLINE void __CLREX(void)
1083 __ASM volatile ("clrex" ::: "memory");
1086 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1087 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1088 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1089 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1092 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1093 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1094 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1096 \brief Signed Saturate
1097 \details Saturates a signed value.
1098 \param [in] ARG1 Value to be saturated
1099 \param [in] ARG2 Bit position to saturate to (1..32)
1100 \return Saturated value
1102 #define __SSAT(ARG1,ARG2) \
1105 int32_t __RES, __ARG1 = (ARG1); \
1106 __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1112 \brief Unsigned Saturate
1113 \details Saturates an unsigned value.
1114 \param [in] ARG1 Value to be saturated
1115 \param [in] ARG2 Bit position to saturate to (0..31)
1116 \return Saturated value
1118 #define __USAT(ARG1,ARG2) \
1121 uint32_t __RES, __ARG1 = (ARG1); \
1122 __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1128 \brief Rotate Right with Extend (32 bit)
1129 \details Moves each bit of a bitstring right by one bit.
1130 The carry input is shifted in at the left end of the bitstring.
1131 \param [in] value Value to rotate
1132 \return Rotated value
1134 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value)
1138 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1144 \brief LDRT Unprivileged (8 bit)
1145 \details Executes a Unprivileged LDRT instruction for 8 bit value.
1146 \param [in] ptr Pointer to data
1147 \return value of type uint8_t at (*ptr)
1149 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *ptr)
1153 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1154 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
1156 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1157 accepted by assembler. So has to use following less efficient pattern.
1159 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1161 return ((uint8_t) result); /* Add explicit type cast here */
1166 \brief LDRT Unprivileged (16 bit)
1167 \details Executes a Unprivileged LDRT instruction for 16 bit values.
1168 \param [in] ptr Pointer to data
1169 \return value of type uint16_t at (*ptr)
1171 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *ptr)
1175 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1176 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
1178 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1179 accepted by assembler. So has to use following less efficient pattern.
1181 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1183 return ((uint16_t) result); /* Add explicit type cast here */
1188 \brief LDRT Unprivileged (32 bit)
1189 \details Executes a Unprivileged LDRT instruction for 32 bit values.
1190 \param [in] ptr Pointer to data
1191 \return value of type uint32_t at (*ptr)
1193 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *ptr)
1197 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1203 \brief STRT Unprivileged (8 bit)
1204 \details Executes a Unprivileged STRT instruction for 8 bit values.
1205 \param [in] value Value to store
1206 \param [in] ptr Pointer to location
1208 __attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1210 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1215 \brief STRT Unprivileged (16 bit)
1216 \details Executes a Unprivileged STRT instruction for 16 bit values.
1217 \param [in] value Value to store
1218 \param [in] ptr Pointer to location
1220 __attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1222 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1227 \brief STRT Unprivileged (32 bit)
1228 \details Executes a Unprivileged STRT instruction for 32 bit values.
1229 \param [in] value Value to store
1230 \param [in] ptr Pointer to location
1232 __attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1234 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1237 #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1238 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1239 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1242 \brief Signed Saturate
1243 \details Saturates a signed value.
1244 \param [in] value Value to be saturated
1245 \param [in] sat Bit position to saturate to (1..32)
1246 \return Saturated value
1248 __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
1250 if ((sat >= 1U) && (sat <= 32U)) {
1251 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
1252 const int32_t min = -1 - max ;
1255 } else if (val < min) {
1263 \brief Unsigned Saturate
1264 \details Saturates an unsigned value.
1265 \param [in] value Value to be saturated
1266 \param [in] sat Bit position to saturate to (0..31)
1267 \return Saturated value
1269 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
1272 const uint32_t max = ((1U << sat) - 1U);
1273 if (val > (int32_t)max) {
1275 } else if (val < 0) {
1282 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1283 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1284 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1287 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1288 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1290 \brief Load-Acquire (8 bit)
1291 \details Executes a LDAB instruction for 8 bit value.
1292 \param [in] ptr Pointer to data
1293 \return value of type uint8_t at (*ptr)
1295 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDAB(volatile uint8_t *ptr)
1299 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) );
1300 return ((uint8_t) result);
1305 \brief Load-Acquire (16 bit)
1306 \details Executes a LDAH instruction for 16 bit values.
1307 \param [in] ptr Pointer to data
1308 \return value of type uint16_t at (*ptr)
1310 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDAH(volatile uint16_t *ptr)
1314 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) );
1315 return ((uint16_t) result);
1320 \brief Load-Acquire (32 bit)
1321 \details Executes a LDA instruction for 32 bit values.
1322 \param [in] ptr Pointer to data
1323 \return value of type uint32_t at (*ptr)
1325 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDA(volatile uint32_t *ptr)
1329 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) );
1335 \brief Store-Release (8 bit)
1336 \details Executes a STLB instruction for 8 bit values.
1337 \param [in] value Value to store
1338 \param [in] ptr Pointer to location
1340 __attribute__((always_inline)) __STATIC_INLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1342 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1347 \brief Store-Release (16 bit)
1348 \details Executes a STLH instruction for 16 bit values.
1349 \param [in] value Value to store
1350 \param [in] ptr Pointer to location
1352 __attribute__((always_inline)) __STATIC_INLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1354 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1359 \brief Store-Release (32 bit)
1360 \details Executes a STL instruction for 32 bit values.
1361 \param [in] value Value to store
1362 \param [in] ptr Pointer to location
1364 __attribute__((always_inline)) __STATIC_INLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1366 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1371 \brief Load-Acquire Exclusive (8 bit)
1372 \details Executes a LDAB exclusive instruction for 8 bit value.
1373 \param [in] ptr Pointer to data
1374 \return value of type uint8_t at (*ptr)
1376 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
1380 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) );
1381 return ((uint8_t) result);
1386 \brief Load-Acquire Exclusive (16 bit)
1387 \details Executes a LDAH exclusive instruction for 16 bit values.
1388 \param [in] ptr Pointer to data
1389 \return value of type uint16_t at (*ptr)
1391 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
1395 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) );
1396 return ((uint16_t) result);
1401 \brief Load-Acquire Exclusive (32 bit)
1402 \details Executes a LDA exclusive instruction for 32 bit values.
1403 \param [in] ptr Pointer to data
1404 \return value of type uint32_t at (*ptr)
1406 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDAEX(volatile uint32_t *ptr)
1410 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) );
1416 \brief Store-Release Exclusive (8 bit)
1417 \details Executes a STLB exclusive instruction for 8 bit values.
1418 \param [in] value Value to store
1419 \param [in] ptr Pointer to location
1420 \return 0 Function succeeded
1421 \return 1 Function failed
1423 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
1427 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) );
1433 \brief Store-Release Exclusive (16 bit)
1434 \details Executes a STLH exclusive instruction for 16 bit values.
1435 \param [in] value Value to store
1436 \param [in] ptr Pointer to location
1437 \return 0 Function succeeded
1438 \return 1 Function failed
1440 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
1444 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) );
1450 \brief Store-Release Exclusive (32 bit)
1451 \details Executes a STL exclusive instruction for 32 bit values.
1452 \param [in] value Value to store
1453 \param [in] ptr Pointer to location
1454 \return 0 Function succeeded
1455 \return 1 Function failed
1457 __attribute__((always_inline)) __STATIC_INLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
1461 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) );
1465 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1466 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1468 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1471 /* ################### Compiler specific Intrinsics ########################### */
1472 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1473 Access to dedicated SIMD instructions
1477 #if (__ARM_FEATURE_DSP == 1) /* ToDo ARMCLANG: This should be ARCH >= ARMv7-M + SIMD */
1479 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1483 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1487 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1491 __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1495 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1499 __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1503 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1507 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1511 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1515 __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1519 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1523 __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1528 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1532 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1536 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1540 __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1544 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1548 __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1552 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1556 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1560 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1564 __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1568 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1572 __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1577 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1581 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1585 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1589 __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1593 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1597 __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1601 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1605 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1609 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1613 __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1617 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1621 __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1625 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1629 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1633 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1637 __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1641 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1645 __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1649 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1653 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1657 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1661 __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1665 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1669 __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1673 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1677 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1681 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1685 __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1689 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1693 __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1697 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1701 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1705 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1709 __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1713 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1717 __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1721 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1725 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1729 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1733 __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1737 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1741 __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1745 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1749 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1753 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1757 __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1761 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1765 __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1769 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1773 __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1777 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1781 __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1785 #define __SSAT16(ARG1,ARG2) \
1787 int32_t __RES, __ARG1 = (ARG1); \
1788 __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1792 #define __USAT16(ARG1,ARG2) \
1794 uint32_t __RES, __ARG1 = (ARG1); \
1795 __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1799 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
1803 __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1807 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1811 __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1815 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
1819 __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1823 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
1827 __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1831 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
1835 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1839 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
1843 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1847 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
1851 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1855 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
1859 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1863 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
1871 #ifndef __ARMEB__ /* Little endian */
1872 __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1873 #else /* Big endian */
1874 __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1880 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
1888 #ifndef __ARMEB__ /* Little endian */
1889 __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1890 #else /* Big endian */
1891 __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1897 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
1901 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1905 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
1909 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1913 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
1917 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1921 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
1925 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1929 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
1937 #ifndef __ARMEB__ /* Little endian */
1938 __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1939 #else /* Big endian */
1940 __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1946 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
1954 #ifndef __ARMEB__ /* Little endian */
1955 __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1956 #else /* Big endian */
1957 __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1963 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
1967 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1971 __attribute__((always_inline)) __STATIC_INLINE int32_t __QADD( int32_t op1, int32_t op2)
1975 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1979 __attribute__((always_inline)) __STATIC_INLINE int32_t __QSUB( int32_t op1, int32_t op2)
1983 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1988 #define __PKHBT(ARG1,ARG2,ARG3) \
1990 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1991 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1995 #define __PKHTB(ARG1,ARG2,ARG3) \
1997 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1999 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
2001 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2006 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
2007 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
2009 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
2010 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
2012 __attribute__((always_inline)) __STATIC_INLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
2016 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
2020 #endif /* (__ARM_FEATURE_DSP == 1) */
2021 /*@} end of group CMSIS_SIMD_intrinsics */
2024 #pragma GCC diagnostic pop
2026 #endif /* __CMSIS_GCC_H */