1 /**************************************************************************//**
3 * @brief CMSIS compiler GCC header file
5 * @date 28. January 2020
6 ******************************************************************************/
8 * Copyright (c) 2009-2019 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
49 #ifndef __STATIC_FORCEINLINE
50 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
53 #define __NO_RETURN __attribute__((__noreturn__))
56 #define __USED __attribute__((used))
59 #define __WEAK __attribute__((weak))
62 #define __PACKED __attribute__((packed, aligned(1)))
64 #ifndef __PACKED_STRUCT
65 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
67 #ifndef __PACKED_UNION
68 #define __PACKED_UNION union __attribute__((packed, aligned(1)))
70 #ifndef __UNALIGNED_UINT32 /* deprecated */
71 #pragma GCC diagnostic push
72 #pragma GCC diagnostic ignored "-Wpacked"
73 #pragma GCC diagnostic ignored "-Wattributes"
74 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
75 #pragma GCC diagnostic pop
76 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
78 #ifndef __UNALIGNED_UINT16_WRITE
79 #pragma GCC diagnostic push
80 #pragma GCC diagnostic ignored "-Wpacked"
81 #pragma GCC diagnostic ignored "-Wattributes"
82 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
83 #pragma GCC diagnostic pop
84 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
86 #ifndef __UNALIGNED_UINT16_READ
87 #pragma GCC diagnostic push
88 #pragma GCC diagnostic ignored "-Wpacked"
89 #pragma GCC diagnostic ignored "-Wattributes"
90 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
91 #pragma GCC diagnostic pop
92 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
94 #ifndef __UNALIGNED_UINT32_WRITE
95 #pragma GCC diagnostic push
96 #pragma GCC diagnostic ignored "-Wpacked"
97 #pragma GCC diagnostic ignored "-Wattributes"
98 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
99 #pragma GCC diagnostic pop
100 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
102 #ifndef __UNALIGNED_UINT32_READ
103 #pragma GCC diagnostic push
104 #pragma GCC diagnostic ignored "-Wpacked"
105 #pragma GCC diagnostic ignored "-Wattributes"
106 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
107 #pragma GCC diagnostic pop
108 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
111 #define __ALIGNED(x) __attribute__((aligned(x)))
114 #define __RESTRICT __restrict
116 #ifndef __COMPILER_BARRIER
117 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
120 /* ######################### Startup and Lowlevel Init ######################## */
122 #ifndef __PROGRAM_START
125 \brief Initializes data and bss sections
126 \details This default implementations initialized all data and additional bss
127 sections relying on .copy.table and .zero.table specified properly
128 in the used linker script.
131 __STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void)
133 extern void _start(void) __NO_RETURN;
146 extern const __copy_table_t __copy_table_start__;
147 extern const __copy_table_t __copy_table_end__;
148 extern const __zero_table_t __zero_table_start__;
149 extern const __zero_table_t __zero_table_end__;
151 for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
152 for(uint32_t i=0u; i<pTable->wlen; ++i) {
153 pTable->dest[i] = pTable->src[i];
157 for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
158 for(uint32_t i=0u; i<pTable->wlen; ++i) {
159 pTable->dest[i] = 0u;
166 #define __PROGRAM_START __cmsis_start
170 #define __INITIAL_SP __StackTop
173 #ifndef __STACK_LIMIT
174 #define __STACK_LIMIT __StackLimit
177 #ifndef __VECTOR_TABLE
178 #define __VECTOR_TABLE __Vectors
181 #ifndef __VECTOR_TABLE_ATTRIBUTE
182 #define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section(".vectors")))
185 /* ########################### Core Function Access ########################### */
186 /** \ingroup CMSIS_Core_FunctionInterface
187 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
192 \brief Enable IRQ Interrupts
193 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
194 Can only be executed in Privileged modes.
196 __STATIC_FORCEINLINE void __enable_irq(void)
198 __ASM volatile ("cpsie i" : : : "memory");
203 \brief Disable IRQ Interrupts
204 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
205 Can only be executed in Privileged modes.
207 __STATIC_FORCEINLINE void __disable_irq(void)
209 __ASM volatile ("cpsid i" : : : "memory");
214 \brief Get Control Register
215 \details Returns the content of the Control Register.
216 \return Control Register value
218 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
222 __ASM volatile ("MRS %0, control" : "=r" (result) );
227 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
229 \brief Get Control Register (non-secure)
230 \details Returns the content of the non-secure Control Register when in secure mode.
231 \return non-secure Control Register value
233 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
237 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
244 \brief Set Control Register
245 \details Writes the given value to the Control Register.
246 \param [in] control Control Register value to set
248 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
250 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
254 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
256 \brief Set Control Register (non-secure)
257 \details Writes the given value to the non-secure Control Register when in secure state.
258 \param [in] control Control Register value to set
260 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
262 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
268 \brief Get IPSR Register
269 \details Returns the content of the IPSR Register.
270 \return IPSR Register value
272 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
276 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
282 \brief Get APSR Register
283 \details Returns the content of the APSR Register.
284 \return APSR Register value
286 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
290 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
296 \brief Get xPSR Register
297 \details Returns the content of the xPSR Register.
298 \return xPSR Register value
300 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
304 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
310 \brief Get Process Stack Pointer
311 \details Returns the current value of the Process Stack Pointer (PSP).
312 \return PSP Register value
314 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
318 __ASM volatile ("MRS %0, psp" : "=r" (result) );
323 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
325 \brief Get Process Stack Pointer (non-secure)
326 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
327 \return PSP Register value
329 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
333 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
340 \brief Set Process Stack Pointer
341 \details Assigns the given value to the Process Stack Pointer (PSP).
342 \param [in] topOfProcStack Process Stack Pointer value to set
344 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
346 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
350 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
352 \brief Set Process Stack Pointer (non-secure)
353 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
354 \param [in] topOfProcStack Process Stack Pointer value to set
356 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
358 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
364 \brief Get Main Stack Pointer
365 \details Returns the current value of the Main Stack Pointer (MSP).
366 \return MSP Register value
368 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
372 __ASM volatile ("MRS %0, msp" : "=r" (result) );
377 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
379 \brief Get Main Stack Pointer (non-secure)
380 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
381 \return MSP Register value
383 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
387 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
394 \brief Set Main Stack Pointer
395 \details Assigns the given value to the Main Stack Pointer (MSP).
396 \param [in] topOfMainStack Main Stack Pointer value to set
398 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
400 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
404 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
406 \brief Set Main Stack Pointer (non-secure)
407 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
408 \param [in] topOfMainStack Main Stack Pointer value to set
410 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
412 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
417 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
419 \brief Get Stack Pointer (non-secure)
420 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
421 \return SP Register value
423 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
427 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
433 \brief Set Stack Pointer (non-secure)
434 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
435 \param [in] topOfStack Stack Pointer value to set
437 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
439 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
445 \brief Get Priority Mask
446 \details Returns the current state of the priority mask bit from the Priority Mask Register.
447 \return Priority Mask value
449 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
453 __ASM volatile ("MRS %0, primask" : "=r" (result) );
458 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
460 \brief Get Priority Mask (non-secure)
461 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
462 \return Priority Mask value
464 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
468 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
475 \brief Set Priority Mask
476 \details Assigns the given value to the Priority Mask Register.
477 \param [in] priMask Priority Mask
479 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
481 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
485 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
487 \brief Set Priority Mask (non-secure)
488 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
489 \param [in] priMask Priority Mask
491 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
493 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
498 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
499 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
500 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
503 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
504 Can only be executed in Privileged modes.
506 __STATIC_FORCEINLINE void __enable_fault_irq(void)
508 __ASM volatile ("cpsie f" : : : "memory");
514 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
515 Can only be executed in Privileged modes.
517 __STATIC_FORCEINLINE void __disable_fault_irq(void)
519 __ASM volatile ("cpsid f" : : : "memory");
524 \brief Get Base Priority
525 \details Returns the current value of the Base Priority register.
526 \return Base Priority register value
528 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
532 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
537 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
539 \brief Get Base Priority (non-secure)
540 \details Returns the current value of the non-secure Base Priority register when in secure state.
541 \return Base Priority register value
543 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
547 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
554 \brief Set Base Priority
555 \details Assigns the given value to the Base Priority register.
556 \param [in] basePri Base Priority value to set
558 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
560 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
564 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
566 \brief Set Base Priority (non-secure)
567 \details Assigns the given value to the non-secure Base Priority register when in secure state.
568 \param [in] basePri Base Priority value to set
570 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
572 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
578 \brief Set Base Priority with condition
579 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
580 or the new value increases the BASEPRI priority level.
581 \param [in] basePri Base Priority value to set
583 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
585 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
590 \brief Get Fault Mask
591 \details Returns the current value of the Fault Mask register.
592 \return Fault Mask register value
594 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
598 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
603 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
605 \brief Get Fault Mask (non-secure)
606 \details Returns the current value of the non-secure Fault Mask register when in secure state.
607 \return Fault Mask register value
609 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
613 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
620 \brief Set Fault Mask
621 \details Assigns the given value to the Fault Mask register.
622 \param [in] faultMask Fault Mask value to set
624 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
626 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
630 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
632 \brief Set Fault Mask (non-secure)
633 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
634 \param [in] faultMask Fault Mask value to set
636 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
638 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
642 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
643 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
644 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
647 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
648 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
651 \brief Get Process Stack Pointer Limit
652 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
653 Stack Pointer Limit register hence zero is returned always in non-secure
656 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
657 \return PSPLIM Register value
659 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
661 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
662 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
663 // without main extensions, the non-secure PSPLIM is RAZ/WI
667 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
672 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
674 \brief Get Process Stack Pointer Limit (non-secure)
675 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
676 Stack Pointer Limit register hence zero is returned always.
678 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
679 \return PSPLIM Register value
681 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
683 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
684 // without main extensions, the non-secure PSPLIM is RAZ/WI
688 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
696 \brief Set Process Stack Pointer Limit
697 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
698 Stack Pointer Limit register hence the write is silently ignored in non-secure
701 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
702 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
704 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
706 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
707 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
708 // without main extensions, the non-secure PSPLIM is RAZ/WI
709 (void)ProcStackPtrLimit;
711 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
716 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
718 \brief Set Process Stack Pointer (non-secure)
719 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
720 Stack Pointer Limit register hence the write is silently ignored.
722 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
723 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
725 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
727 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
728 // without main extensions, the non-secure PSPLIM is RAZ/WI
729 (void)ProcStackPtrLimit;
731 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
738 \brief Get Main Stack Pointer Limit
739 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
740 Stack Pointer Limit register hence zero is returned always in non-secure
743 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
744 \return MSPLIM Register value
746 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
748 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
749 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
750 // without main extensions, the non-secure MSPLIM is RAZ/WI
754 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
760 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
762 \brief Get Main Stack Pointer Limit (non-secure)
763 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
764 Stack Pointer Limit register hence zero is returned always.
766 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
767 \return MSPLIM Register value
769 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
771 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
772 // without main extensions, the non-secure MSPLIM is RAZ/WI
776 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
784 \brief Set Main Stack Pointer Limit
785 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
786 Stack Pointer Limit register hence the write is silently ignored in non-secure
789 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
790 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
792 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
794 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
795 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
796 // without main extensions, the non-secure MSPLIM is RAZ/WI
797 (void)MainStackPtrLimit;
799 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
804 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
806 \brief Set Main Stack Pointer Limit (non-secure)
807 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
808 Stack Pointer Limit register hence the write is silently ignored.
810 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
811 \param [in] MainStackPtrLimit Main Stack Pointer value to set
813 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
815 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
816 // without main extensions, the non-secure MSPLIM is RAZ/WI
817 (void)MainStackPtrLimit;
819 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
824 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
825 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
830 \details Returns the current value of the Floating Point Status/Control register.
831 \return Floating Point Status/Control register value
833 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
835 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
836 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
837 #if __has_builtin(__builtin_arm_get_fpscr)
838 // Re-enable using built-in when GCC has been fixed
839 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
840 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
841 return __builtin_arm_get_fpscr();
845 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
856 \details Assigns the given value to the Floating Point Status/Control register.
857 \param [in] fpscr Floating Point Status/Control value to set
859 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
861 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
862 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
863 #if __has_builtin(__builtin_arm_set_fpscr)
864 // Re-enable using built-in when GCC has been fixed
865 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
866 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
867 __builtin_arm_set_fpscr(fpscr);
869 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
877 /*@} end of CMSIS_Core_RegAccFunctions */
880 /* ########################## Core Instruction Access ######################### */
881 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
882 Access to dedicated instructions
886 /* Define macros for porting to both thumb1 and thumb2.
887 * For thumb1, use low register (r0-r7), specified by constraint "l"
888 * Otherwise, use general registers, specified by constraint "r" */
889 #if defined (__thumb__) && !defined (__thumb2__)
890 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
891 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
892 #define __CMSIS_GCC_USE_REG(r) "l" (r)
894 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
895 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
896 #define __CMSIS_GCC_USE_REG(r) "r" (r)
901 \details No Operation does nothing. This instruction can be used for code alignment purposes.
903 #define __NOP() __ASM volatile ("nop")
906 \brief Wait For Interrupt
907 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
909 #define __WFI() __ASM volatile ("wfi":::"memory")
913 \brief Wait For Event
914 \details Wait For Event is a hint instruction that permits the processor to enter
915 a low-power state until one of a number of events occurs.
917 #define __WFE() __ASM volatile ("wfe":::"memory")
922 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
924 #define __SEV() __ASM volatile ("sev")
928 \brief Instruction Synchronization Barrier
929 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
930 so that all instructions following the ISB are fetched from cache or memory,
931 after the instruction has been completed.
933 __STATIC_FORCEINLINE void __ISB(void)
935 __ASM volatile ("isb 0xF":::"memory");
940 \brief Data Synchronization Barrier
941 \details Acts as a special kind of Data Memory Barrier.
942 It completes when all explicit memory accesses before this instruction complete.
944 __STATIC_FORCEINLINE void __DSB(void)
946 __ASM volatile ("dsb 0xF":::"memory");
951 \brief Data Memory Barrier
952 \details Ensures the apparent order of the explicit memory operations before
953 and after the instruction, without ensuring their completion.
955 __STATIC_FORCEINLINE void __DMB(void)
957 __ASM volatile ("dmb 0xF":::"memory");
962 \brief Reverse byte order (32 bit)
963 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
964 \param [in] value Value to reverse
965 \return Reversed value
967 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
969 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
970 return __builtin_bswap32(value);
974 __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
981 \brief Reverse byte order (16 bit)
982 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
983 \param [in] value Value to reverse
984 \return Reversed value
986 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
990 __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
996 \brief Reverse byte order (16 bit)
997 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
998 \param [in] value Value to reverse
999 \return Reversed value
1001 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
1003 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1004 return (int16_t)__builtin_bswap16(value);
1008 __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1015 \brief Rotate Right in unsigned value (32 bit)
1016 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
1017 \param [in] op1 Value to rotate
1018 \param [in] op2 Number of Bits to rotate
1019 \return Rotated value
1021 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
1028 return (op1 >> op2) | (op1 << (32U - op2));
1034 \details Causes the processor to enter Debug state.
1035 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
1036 \param [in] value is ignored by the processor.
1037 If required, a debugger can use it to store additional information about the breakpoint.
1039 #define __BKPT(value) __ASM volatile ("bkpt "#value)
1043 \brief Reverse bit order of value
1044 \details Reverses the bit order of the given value.
1045 \param [in] value Value to reverse
1046 \return Reversed value
1048 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
1052 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1053 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1054 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1055 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
1057 uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
1059 result = value; /* r will be reversed bits of v; first get LSB of v */
1060 for (value >>= 1U; value != 0U; value >>= 1U)
1063 result |= value & 1U;
1066 result <<= s; /* shift when v's highest bits are zero */
1073 \brief Count leading zeros
1074 \details Counts the number of leading zeros of a data value.
1075 \param [in] value Value to count the leading zeros
1076 \return number of leading zeros in value
1078 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
1080 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
1081 __builtin_clz(0) is undefined behaviour, so handle this case specially.
1082 This guarantees ARM-compatible results if happening to compile on a non-ARM
1083 target, and ensures the compiler doesn't decide to activate any
1084 optimisations using the logic "value was passed to __builtin_clz, so it
1086 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
1087 single CLZ instruction.
1093 return __builtin_clz(value);
1097 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1098 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1099 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1100 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1102 \brief LDR Exclusive (8 bit)
1103 \details Executes a exclusive LDR instruction for 8 bit value.
1104 \param [in] ptr Pointer to data
1105 \return value of type uint8_t at (*ptr)
1107 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
1111 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1112 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
1114 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1115 accepted by assembler. So has to use following less efficient pattern.
1117 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1119 return ((uint8_t) result); /* Add explicit type cast here */
1124 \brief LDR Exclusive (16 bit)
1125 \details Executes a exclusive LDR instruction for 16 bit values.
1126 \param [in] ptr Pointer to data
1127 \return value of type uint16_t at (*ptr)
1129 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
1133 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1134 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
1136 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1137 accepted by assembler. So has to use following less efficient pattern.
1139 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
1141 return ((uint16_t) result); /* Add explicit type cast here */
1146 \brief LDR Exclusive (32 bit)
1147 \details Executes a exclusive LDR instruction for 32 bit values.
1148 \param [in] ptr Pointer to data
1149 \return value of type uint32_t at (*ptr)
1151 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
1155 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
1161 \brief STR Exclusive (8 bit)
1162 \details Executes a exclusive STR instruction for 8 bit values.
1163 \param [in] value Value to store
1164 \param [in] ptr Pointer to location
1165 \return 0 Function succeeded
1166 \return 1 Function failed
1168 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
1172 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1178 \brief STR Exclusive (16 bit)
1179 \details Executes a exclusive STR instruction for 16 bit values.
1180 \param [in] value Value to store
1181 \param [in] ptr Pointer to location
1182 \return 0 Function succeeded
1183 \return 1 Function failed
1185 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
1189 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
1195 \brief STR Exclusive (32 bit)
1196 \details Executes a exclusive STR instruction for 32 bit values.
1197 \param [in] value Value to store
1198 \param [in] ptr Pointer to location
1199 \return 0 Function succeeded
1200 \return 1 Function failed
1202 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
1206 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
1212 \brief Remove the exclusive lock
1213 \details Removes the exclusive lock which is created by LDREX.
1215 __STATIC_FORCEINLINE void __CLREX(void)
1217 __ASM volatile ("clrex" ::: "memory");
1220 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1221 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1222 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1223 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1226 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1227 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1228 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1230 \brief Signed Saturate
1231 \details Saturates a signed value.
1232 \param [in] ARG1 Value to be saturated
1233 \param [in] ARG2 Bit position to saturate to (1..32)
1234 \return Saturated value
1236 #define __SSAT(ARG1, ARG2) \
1239 int32_t __RES, __ARG1 = (ARG1); \
1240 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1246 \brief Unsigned Saturate
1247 \details Saturates an unsigned value.
1248 \param [in] ARG1 Value to be saturated
1249 \param [in] ARG2 Bit position to saturate to (0..31)
1250 \return Saturated value
1252 #define __USAT(ARG1, ARG2) \
1255 uint32_t __RES, __ARG1 = (ARG1); \
1256 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1262 \brief Rotate Right with Extend (32 bit)
1263 \details Moves each bit of a bitstring right by one bit.
1264 The carry input is shifted in at the left end of the bitstring.
1265 \param [in] value Value to rotate
1266 \return Rotated value
1268 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
1272 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
1278 \brief LDRT Unprivileged (8 bit)
1279 \details Executes a Unprivileged LDRT instruction for 8 bit value.
1280 \param [in] ptr Pointer to data
1281 \return value of type uint8_t at (*ptr)
1283 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
1287 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1288 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
1290 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1291 accepted by assembler. So has to use following less efficient pattern.
1293 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1295 return ((uint8_t) result); /* Add explicit type cast here */
1300 \brief LDRT Unprivileged (16 bit)
1301 \details Executes a Unprivileged LDRT instruction for 16 bit values.
1302 \param [in] ptr Pointer to data
1303 \return value of type uint16_t at (*ptr)
1305 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
1309 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
1310 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
1312 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
1313 accepted by assembler. So has to use following less efficient pattern.
1315 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
1317 return ((uint16_t) result); /* Add explicit type cast here */
1322 \brief LDRT Unprivileged (32 bit)
1323 \details Executes a Unprivileged LDRT instruction for 32 bit values.
1324 \param [in] ptr Pointer to data
1325 \return value of type uint32_t at (*ptr)
1327 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
1331 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1337 \brief STRT Unprivileged (8 bit)
1338 \details Executes a Unprivileged STRT instruction for 8 bit values.
1339 \param [in] value Value to store
1340 \param [in] ptr Pointer to location
1342 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1344 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1349 \brief STRT Unprivileged (16 bit)
1350 \details Executes a Unprivileged STRT instruction for 16 bit values.
1351 \param [in] value Value to store
1352 \param [in] ptr Pointer to location
1354 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1356 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1361 \brief STRT Unprivileged (32 bit)
1362 \details Executes a Unprivileged STRT instruction for 32 bit values.
1363 \param [in] value Value to store
1364 \param [in] ptr Pointer to location
1366 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1368 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1371 #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1372 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1373 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1376 \brief Signed Saturate
1377 \details Saturates a signed value.
1378 \param [in] value Value to be saturated
1379 \param [in] sat Bit position to saturate to (1..32)
1380 \return Saturated value
1382 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
1384 if ((sat >= 1U) && (sat <= 32U))
1386 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
1387 const int32_t min = -1 - max ;
1401 \brief Unsigned Saturate
1402 \details Saturates an unsigned value.
1403 \param [in] value Value to be saturated
1404 \param [in] sat Bit position to saturate to (0..31)
1405 \return Saturated value
1407 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
1411 const uint32_t max = ((1U << sat) - 1U);
1412 if (val > (int32_t)max)
1421 return (uint32_t)val;
1424 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1425 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1426 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1429 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1430 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1432 \brief Load-Acquire (8 bit)
1433 \details Executes a LDAB instruction for 8 bit value.
1434 \param [in] ptr Pointer to data
1435 \return value of type uint8_t at (*ptr)
1437 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
1441 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1442 return ((uint8_t) result);
1447 \brief Load-Acquire (16 bit)
1448 \details Executes a LDAH instruction for 16 bit values.
1449 \param [in] ptr Pointer to data
1450 \return value of type uint16_t at (*ptr)
1452 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
1456 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1457 return ((uint16_t) result);
1462 \brief Load-Acquire (32 bit)
1463 \details Executes a LDA instruction for 32 bit values.
1464 \param [in] ptr Pointer to data
1465 \return value of type uint32_t at (*ptr)
1467 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
1471 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1477 \brief Store-Release (8 bit)
1478 \details Executes a STLB instruction for 8 bit values.
1479 \param [in] value Value to store
1480 \param [in] ptr Pointer to location
1482 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1484 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1489 \brief Store-Release (16 bit)
1490 \details Executes a STLH instruction for 16 bit values.
1491 \param [in] value Value to store
1492 \param [in] ptr Pointer to location
1494 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1496 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1501 \brief Store-Release (32 bit)
1502 \details Executes a STL instruction for 32 bit values.
1503 \param [in] value Value to store
1504 \param [in] ptr Pointer to location
1506 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1508 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1513 \brief Load-Acquire Exclusive (8 bit)
1514 \details Executes a LDAB exclusive instruction for 8 bit value.
1515 \param [in] ptr Pointer to data
1516 \return value of type uint8_t at (*ptr)
1518 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
1522 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1523 return ((uint8_t) result);
1528 \brief Load-Acquire Exclusive (16 bit)
1529 \details Executes a LDAH exclusive instruction for 16 bit values.
1530 \param [in] ptr Pointer to data
1531 \return value of type uint16_t at (*ptr)
1533 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
1537 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1538 return ((uint16_t) result);
1543 \brief Load-Acquire Exclusive (32 bit)
1544 \details Executes a LDA exclusive instruction for 32 bit values.
1545 \param [in] ptr Pointer to data
1546 \return value of type uint32_t at (*ptr)
1548 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
1552 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
1558 \brief Store-Release Exclusive (8 bit)
1559 \details Executes a STLB exclusive instruction for 8 bit values.
1560 \param [in] value Value to store
1561 \param [in] ptr Pointer to location
1562 \return 0 Function succeeded
1563 \return 1 Function failed
1565 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
1569 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1575 \brief Store-Release Exclusive (16 bit)
1576 \details Executes a STLH exclusive instruction for 16 bit values.
1577 \param [in] value Value to store
1578 \param [in] ptr Pointer to location
1579 \return 0 Function succeeded
1580 \return 1 Function failed
1582 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
1586 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1592 \brief Store-Release Exclusive (32 bit)
1593 \details Executes a STL exclusive instruction for 32 bit values.
1594 \param [in] value Value to store
1595 \param [in] ptr Pointer to location
1596 \return 0 Function succeeded
1597 \return 1 Function failed
1599 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
1603 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
1607 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1608 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1610 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1613 /* ################### Compiler specific Intrinsics ########################### */
1614 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1615 Access to dedicated SIMD instructions
1619 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1621 __STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1625 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1629 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1633 __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1637 __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1641 __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1645 __STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1649 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1653 __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1657 __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1661 __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1665 __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1670 __STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1674 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1678 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1682 __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1686 __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1690 __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1694 __STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1698 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1702 __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1706 __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1710 __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1714 __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1719 __STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1723 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1727 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1731 __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1735 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1739 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1743 __STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1747 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1751 __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1755 __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1759 __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1763 __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1767 __STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1771 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1775 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1779 __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1783 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1787 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1791 __STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1795 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1799 __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1803 __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1807 __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1811 __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1815 __STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1819 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1823 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1827 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1831 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1835 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1839 __STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1843 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1847 __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1851 __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1855 __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1859 __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1863 __STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1867 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1871 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1875 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1879 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1883 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1887 __STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1891 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1895 __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1899 __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1903 __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1907 __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1911 __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1915 __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1919 __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1923 __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1927 #define __SSAT16(ARG1, ARG2) \
1929 int32_t __RES, __ARG1 = (ARG1); \
1930 __ASM volatile ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1934 #define __USAT16(ARG1, ARG2) \
1936 uint32_t __RES, __ARG1 = (ARG1); \
1937 __ASM volatile ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1941 __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
1945 __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1949 __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1953 __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1957 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
1961 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1965 __STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate)
1969 __ASM ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) );
1974 __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
1978 __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1982 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
1986 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1990 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
1994 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1998 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
2002 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2006 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
2010 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2014 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
2022 #ifndef __ARMEB__ /* Little endian */
2023 __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]) );
2024 #else /* Big endian */
2025 __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]) );
2031 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
2039 #ifndef __ARMEB__ /* Little endian */
2040 __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]) );
2041 #else /* Big endian */
2042 __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]) );
2048 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
2052 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2056 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
2060 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2064 __STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
2068 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2072 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
2076 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2080 __STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
2088 #ifndef __ARMEB__ /* Little endian */
2089 __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]) );
2090 #else /* Big endian */
2091 __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]) );
2097 __STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
2105 #ifndef __ARMEB__ /* Little endian */
2106 __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]) );
2107 #else /* Big endian */
2108 __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]) );
2114 __STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
2118 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2122 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
2126 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2130 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
2134 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2139 #define __PKHBT(ARG1,ARG2,ARG3) \
2141 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2142 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2146 #define __PKHTB(ARG1,ARG2,ARG3) \
2148 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2150 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
2152 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2157 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
2158 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
2160 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
2161 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
2163 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
2167 __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
2171 #endif /* (__ARM_FEATURE_DSP == 1) */
2172 /*@} end of group CMSIS_SIMD_intrinsics */
2175 #pragma GCC diagnostic pop
2177 #endif /* __CMSIS_GCC_H */