1 /**************************************************************************//**
3 * @brief CMSIS compiler LLVM/Clang header file
6 ******************************************************************************/
8 * Copyright (c) 2009-2023 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.
25 #ifndef __CMSIS_CLANG_H
26 #define __CMSIS_CLANG_H
28 #pragma clang system_header
32 /* Fallback for __has_builtin */
34 #define __has_builtin(x) (0)
37 /* CMSIS compiler specific defines */
42 #define __INLINE inline
44 #ifndef __STATIC_INLINE
45 #define __STATIC_INLINE static inline
47 #ifndef __STATIC_FORCEINLINE
48 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
51 #define __NO_RETURN __attribute__((__noreturn__))
54 #define __USED __attribute__((used))
57 #define __WEAK __attribute__((weak))
60 #define __PACKED __attribute__((packed, aligned(1)))
62 #ifndef __PACKED_STRUCT
63 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
65 #ifndef __PACKED_UNION
66 #define __PACKED_UNION union __attribute__((packed, aligned(1)))
68 #ifndef __UNALIGNED_UINT16_WRITE
69 #pragma clang diagnostic push
70 #pragma clang diagnostic ignored "-Wpacked"
71 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
72 #pragma clang diagnostic pop
73 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
75 #ifndef __UNALIGNED_UINT16_READ
76 #pragma clang diagnostic push
77 #pragma clang diagnostic ignored "-Wpacked"
78 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
79 #pragma clang diagnostic pop
80 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
82 #ifndef __UNALIGNED_UINT32_WRITE
83 #pragma clang diagnostic push
84 #pragma clang diagnostic ignored "-Wpacked"
85 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
86 #pragma clang diagnostic pop
87 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
89 #ifndef __UNALIGNED_UINT32_READ
90 #pragma clang diagnostic push
91 #pragma clang diagnostic ignored "-Wpacked"
92 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
93 #pragma clang diagnostic pop
94 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
97 #define __ALIGNED(x) __attribute__((aligned(x)))
100 #define __RESTRICT __restrict
102 #ifndef __COMPILER_BARRIER
103 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
106 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
109 #define __ALIAS(x) __attribute__ ((alias(x)))
112 /* ######################### Startup and Lowlevel Init ######################## */
114 #ifndef __PROGRAM_START
115 #define __PROGRAM_START _start
119 #define __INITIAL_SP __stack
122 #ifndef __STACK_LIMIT
123 #define __STACK_LIMIT __stack_limit
126 #ifndef __VECTOR_TABLE
127 #define __VECTOR_TABLE __Vectors
130 #ifndef __VECTOR_TABLE_ATTRIBUTE
131 #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors")))
134 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
136 #define __STACK_SEAL __stack_seal
139 #ifndef __TZ_STACK_SEAL_SIZE
140 #define __TZ_STACK_SEAL_SIZE 8U
143 #ifndef __TZ_STACK_SEAL_VALUE
144 #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
148 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
149 *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
154 /* ########################## Core Instruction Access ######################### */
155 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
156 Access to dedicated instructions
160 /* Define macros for porting to both thumb1 and thumb2.
161 * For thumb1, use low register (r0-r7), specified by constraint "l"
162 * Otherwise, use general registers, specified by constraint "r" */
163 #if defined (__thumb__) && !defined (__thumb2__)
164 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
165 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
166 #define __CMSIS_GCC_USE_REG(r) "l" (r)
168 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
169 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
170 #define __CMSIS_GCC_USE_REG(r) "r" (r)
175 \details No Operation does nothing. This instruction can be used for code alignment purposes.
177 #define __NOP() __nop()
180 \brief Wait For Interrupt
181 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
183 #define __WFI() __wfi()
187 \brief Wait For Event
188 \details Wait For Event is a hint instruction that permits the processor to enter
189 a low-power state until one of a number of events occurs.
191 #define __WFE() __wfe()
196 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
198 #define __SEV() __sev()
202 \brief Instruction Synchronization Barrier
203 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
204 so that all instructions following the ISB are fetched from cache or memory,
205 after the instruction has been completed.
207 #define __ISB() __isb(0xF)
210 \brief Data Synchronization Barrier
211 \details Acts as a special kind of Data Memory Barrier.
212 It completes when all explicit memory accesses before this instruction complete.
214 #define __DSB() __dsb(0xF)
217 \brief Data Memory Barrier
218 \details Ensures the apparent order of the explicit memory operations before
219 and after the instruction, without ensuring their completion.
221 #define __DMB() __dmb(0xF)
224 \brief Reverse byte order (32 bit)
225 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
226 \param [in] value Value to reverse
227 \return Reversed value
229 #define __REV(value) __rev(value)
232 \brief Reverse byte order (16 bit)
233 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
234 \param [in] value Value to reverse
235 \return Reversed value
237 #define __REV16(value) __rev16(value)
240 \brief Reverse byte order (16 bit)
241 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
242 \param [in] value Value to reverse
243 \return Reversed value
245 #define __REVSH(value) __revsh(value)
248 \brief Rotate Right in unsigned value (32 bit)
249 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
250 \param [in] op1 Value to rotate
251 \param [in] op2 Number of Bits to rotate
252 \return Rotated value
254 #define __ROR(op1, op2) __ror(op1, op2)
258 \details Causes the processor to enter Debug state.
259 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
260 \param [in] value is ignored by the processor.
261 If required, a debugger can use it to store additional information about the breakpoint.
263 #define __BKPT(value) __ASM volatile ("bkpt "#value)
266 \brief Reverse bit order of value
267 \details Reverses the bit order of the given value.
268 \param [in] value Value to reverse
269 \return Reversed value
271 #define __RBIT(value) __rbit(value)
274 \brief Count leading zeros
275 \details Counts the number of leading zeros of a data value.
276 \param [in] value Value to count the leading zeros
277 \return number of leading zeros in value
279 #define __CLZ(value) __clz(value)
281 // Workaround for wrong features set by Clang for Armv8-M Baseline devices
282 #if defined(__ARM_FEATURE_SAT) && (__ARM_ARCH_ISA_THUMB >= 2)
284 \brief Signed Saturate
285 \details Saturates a signed value.
286 \param [in] value Value to be saturated
287 \param [in] sat Bit position to saturate to (1..32)
288 \return Saturated value
290 #define __SSAT(value, sat) __ssat(value, sat)
293 \brief Unsigned Saturate
294 \details Saturates an unsigned value.
295 \param [in] value Value to be saturated
296 \param [in] sat Bit position to saturate to (0..31)
297 \return Saturated value
299 #define __USAT(value, sat) __usat(value, sat)
301 #else /* __ARM_FEATURE_SAT */
304 \brief Signed Saturate
305 \details Saturates a signed value.
306 \param [in] value Value to be saturated
307 \param [in] sat Bit position to saturate to (1..32)
308 \return Saturated value
310 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
312 if ((sat >= 1U) && (sat <= 32U))
314 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
315 const int32_t min = -1 - max ;
329 \brief Unsigned Saturate
330 \details Saturates an unsigned value.
331 \param [in] value Value to be saturated
332 \param [in] sat Bit position to saturate to (0..31)
333 \return Saturated value
335 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
339 const uint32_t max = ((1U << sat) - 1U);
340 if (val > (int32_t)max)
349 return (uint32_t)val;
352 #endif /* __ARM_FEATURE_SAT */
354 #if __ARM_ARCH_ISA_THUMB >= 2
356 \brief Rotate Right with Extend (32 bit)
357 \details Moves each bit of a bitstring right by one bit.
358 The carry input is shifted in at the left end of the bitstring.
359 \param [in] value Value to rotate
360 \return Rotated value
362 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
366 __ASM volatile ("rrx %0, %1" : "=r" (result) : "r" (value));
369 #endif /* __ARM_ARCH_ISA_THUMB >= 2 */
371 #if __ARM_FEATURE_LDREX >= 4
373 \brief LDR Exclusive (32 bit)
374 \details Executes a exclusive LDR instruction for 32 bit values.
375 \param [in] ptr Pointer to data
376 \return value of type uint32_t at (*ptr)
378 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
382 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
387 \brief STR Exclusive (32 bit)
388 \details Executes a exclusive STR instruction for 32 bit values.
389 \param [in] value Value to store
390 \param [in] ptr Pointer to location
391 \return 0 Function succeeded
392 \return 1 Function failed
394 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
398 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
402 #endif /* __ARM_FEATURE_LDREX => 4 */
404 #if __ARM_FEATURE_LDREX >= 7
406 \brief LDR Exclusive (16 bit)
407 \details Executes a exclusive LDR instruction for 16 bit values.
408 \param [in] ptr Pointer to data
409 \return value of type uint16_t at (*ptr)
411 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
415 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
416 return ((uint16_t) result); /* Add explicit type cast here */
420 \brief STR Exclusive (16 bit)
421 \details Executes a exclusive STR instruction for 16 bit values.
422 \param [in] value Value to store
423 \param [in] ptr Pointer to location
424 \return 0 Function succeeded
425 \return 1 Function failed
427 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
431 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
436 \brief LDR Exclusive (8 bit)
437 \details Executes a exclusive LDR instruction for 8 bit value.
438 \param [in] ptr Pointer to data
439 \return value of type uint8_t at (*ptr)
441 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
445 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
446 return ((uint8_t) result); /* Add explicit type cast here */
450 \brief STR Exclusive (8 bit)
451 \details Executes a exclusive STR instruction for 8 bit values.
452 \param [in] value Value to store
453 \param [in] ptr Pointer to location
454 \return 0 Function succeeded
455 \return 1 Function failed
457 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
461 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
466 \brief Remove the exclusive lock
467 \details Removes the exclusive lock which is created by LDREX.
469 __STATIC_FORCEINLINE void __CLREX(void)
471 __ASM volatile ("clrex" ::: "memory");
473 #endif /* __ARM_FEATURE_LDREX */
475 #if __ARM_ARCH_ISA_THUMB >= 2
478 \brief LDRT Unprivileged (8 bit)
479 \details Executes a Unprivileged LDRT instruction for 8 bit value.
480 \param [in] ptr Pointer to data
481 \return value of type uint8_t at (*ptr)
483 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
487 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
488 return ((uint8_t) result); /* Add explicit type cast here */
493 \brief LDRT Unprivileged (16 bit)
494 \details Executes a Unprivileged LDRT instruction for 16 bit values.
495 \param [in] ptr Pointer to data
496 \return value of type uint16_t at (*ptr)
498 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
502 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
503 return ((uint16_t) result); /* Add explicit type cast here */
508 \brief LDRT Unprivileged (32 bit)
509 \details Executes a Unprivileged LDRT instruction for 32 bit values.
510 \param [in] ptr Pointer to data
511 \return value of type uint32_t at (*ptr)
513 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
517 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
523 \brief STRT Unprivileged (8 bit)
524 \details Executes a Unprivileged STRT instruction for 8 bit values.
525 \param [in] value Value to store
526 \param [in] ptr Pointer to location
528 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
530 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
535 \brief STRT Unprivileged (16 bit)
536 \details Executes a Unprivileged STRT instruction for 16 bit values.
537 \param [in] value Value to store
538 \param [in] ptr Pointer to location
540 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
542 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
547 \brief STRT Unprivileged (32 bit)
548 \details Executes a Unprivileged STRT instruction for 32 bit values.
549 \param [in] value Value to store
550 \param [in] ptr Pointer to location
552 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
554 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
556 #endif /* __ARM_ARCH_ISA_THUMB >= 2 */
560 \brief Load-Acquire (8 bit)
561 \details Executes a LDAB instruction for 8 bit value.
562 \param [in] ptr Pointer to data
563 \return value of type uint8_t at (*ptr)
565 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
569 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
570 return ((uint8_t) result);
575 \brief Load-Acquire (16 bit)
576 \details Executes a LDAH instruction for 16 bit values.
577 \param [in] ptr Pointer to data
578 \return value of type uint16_t at (*ptr)
580 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
584 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
585 return ((uint16_t) result);
590 \brief Load-Acquire (32 bit)
591 \details Executes a LDA instruction for 32 bit values.
592 \param [in] ptr Pointer to data
593 \return value of type uint32_t at (*ptr)
595 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
599 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
605 \brief Store-Release (8 bit)
606 \details Executes a STLB instruction for 8 bit values.
607 \param [in] value Value to store
608 \param [in] ptr Pointer to location
610 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
612 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
617 \brief Store-Release (16 bit)
618 \details Executes a STLH instruction for 16 bit values.
619 \param [in] value Value to store
620 \param [in] ptr Pointer to location
622 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
624 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
629 \brief Store-Release (32 bit)
630 \details Executes a STL instruction for 32 bit values.
631 \param [in] value Value to store
632 \param [in] ptr Pointer to location
634 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
636 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
641 \brief Load-Acquire Exclusive (8 bit)
642 \details Executes a LDAB exclusive instruction for 8 bit value.
643 \param [in] ptr Pointer to data
644 \return value of type uint8_t at (*ptr)
646 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
650 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
651 return ((uint8_t) result);
656 \brief Load-Acquire Exclusive (16 bit)
657 \details Executes a LDAH exclusive instruction for 16 bit values.
658 \param [in] ptr Pointer to data
659 \return value of type uint16_t at (*ptr)
661 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
665 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
666 return ((uint16_t) result);
671 \brief Load-Acquire Exclusive (32 bit)
672 \details Executes a LDA exclusive instruction for 32 bit values.
673 \param [in] ptr Pointer to data
674 \return value of type uint32_t at (*ptr)
676 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
680 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
686 \brief Store-Release Exclusive (8 bit)
687 \details Executes a STLB exclusive instruction for 8 bit values.
688 \param [in] value Value to store
689 \param [in] ptr Pointer to location
690 \return 0 Function succeeded
691 \return 1 Function failed
693 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
697 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
703 \brief Store-Release Exclusive (16 bit)
704 \details Executes a STLH exclusive instruction for 16 bit values.
705 \param [in] value Value to store
706 \param [in] ptr Pointer to location
707 \return 0 Function succeeded
708 \return 1 Function failed
710 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
714 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
720 \brief Store-Release Exclusive (32 bit)
721 \details Executes a STL exclusive instruction for 32 bit values.
722 \param [in] value Value to store
723 \param [in] ptr Pointer to location
724 \return 0 Function succeeded
725 \return 1 Function failed
727 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
731 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
735 #endif /* __ARM_ARCH >= 8 */
737 /** @}*/ /* end of group CMSIS_Core_InstructionInterface */
740 /* ########################### Core Function Access ########################### */
741 /** \ingroup CMSIS_Core_FunctionInterface
742 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
747 \brief Enable IRQ Interrupts
748 \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
749 Can only be executed in Privileged modes.
751 __STATIC_FORCEINLINE void __enable_irq(void)
753 __ASM volatile ("cpsie i" : : : "memory");
758 \brief Disable IRQ Interrupts
759 \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
760 Can only be executed in Privileged modes.
762 __STATIC_FORCEINLINE void __disable_irq(void)
764 __ASM volatile ("cpsid i" : : : "memory");
769 \brief Get Control Register
770 \details Returns the content of the Control Register.
771 \return Control Register value
773 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
777 __ASM volatile ("MRS %0, control" : "=r" (result) );
782 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
784 \brief Get Control Register (non-secure)
785 \details Returns the content of the non-secure Control Register when in secure mode.
786 \return non-secure Control Register value
788 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
792 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
799 \brief Set Control Register
800 \details Writes the given value to the Control Register.
801 \param [in] control Control Register value to set
803 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
805 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
810 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
812 \brief Set Control Register (non-secure)
813 \details Writes the given value to the non-secure Control Register when in secure state.
814 \param [in] control Control Register value to set
816 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
818 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
825 \brief Get IPSR Register
826 \details Returns the content of the IPSR Register.
827 \return IPSR Register value
829 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
833 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
839 \brief Get APSR Register
840 \details Returns the content of the APSR Register.
841 \return APSR Register value
843 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
847 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
853 \brief Get xPSR Register
854 \details Returns the content of the xPSR Register.
855 \return xPSR Register value
857 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
861 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
867 \brief Get Process Stack Pointer
868 \details Returns the current value of the Process Stack Pointer (PSP).
869 \return PSP Register value
871 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
875 __ASM volatile ("MRS %0, psp" : "=r" (result) );
880 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
882 \brief Get Process Stack Pointer (non-secure)
883 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
884 \return PSP Register value
886 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
890 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
897 \brief Set Process Stack Pointer
898 \details Assigns the given value to the Process Stack Pointer (PSP).
899 \param [in] topOfProcStack Process Stack Pointer value to set
901 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
903 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
907 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
909 \brief Set Process Stack Pointer (non-secure)
910 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
911 \param [in] topOfProcStack Process Stack Pointer value to set
913 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
915 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
921 \brief Get Main Stack Pointer
922 \details Returns the current value of the Main Stack Pointer (MSP).
923 \return MSP Register value
925 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
929 __ASM volatile ("MRS %0, msp" : "=r" (result) );
934 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
936 \brief Get Main Stack Pointer (non-secure)
937 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
938 \return MSP Register value
940 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
944 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
951 \brief Set Main Stack Pointer
952 \details Assigns the given value to the Main Stack Pointer (MSP).
953 \param [in] topOfMainStack Main Stack Pointer value to set
955 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
957 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
961 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
963 \brief Set Main Stack Pointer (non-secure)
964 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
965 \param [in] topOfMainStack Main Stack Pointer value to set
967 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
969 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
974 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
976 \brief Get Stack Pointer (non-secure)
977 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
978 \return SP Register value
980 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
984 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
990 \brief Set Stack Pointer (non-secure)
991 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
992 \param [in] topOfStack Stack Pointer value to set
994 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
996 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
1002 \brief Get Priority Mask
1003 \details Returns the current state of the priority mask bit from the Priority Mask Register.
1004 \return Priority Mask value
1006 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
1010 __ASM volatile ("MRS %0, primask" : "=r" (result) );
1015 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1017 \brief Get Priority Mask (non-secure)
1018 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
1019 \return Priority Mask value
1021 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
1025 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
1032 \brief Set Priority Mask
1033 \details Assigns the given value to the Priority Mask Register.
1034 \param [in] priMask Priority Mask
1036 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
1038 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
1042 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1044 \brief Set Priority Mask (non-secure)
1045 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
1046 \param [in] priMask Priority Mask
1048 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
1050 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
1055 #if __ARM_ARCH_ISA_THUMB >= 2
1058 \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
1059 Can only be executed in Privileged modes.
1061 __STATIC_FORCEINLINE void __enable_fault_irq(void)
1063 __ASM volatile ("cpsie f" : : : "memory");
1069 \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
1070 Can only be executed in Privileged modes.
1072 __STATIC_FORCEINLINE void __disable_fault_irq(void)
1074 __ASM volatile ("cpsid f" : : : "memory");
1079 \brief Get Base Priority
1080 \details Returns the current value of the Base Priority register.
1081 \return Base Priority register value
1083 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
1087 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
1092 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1094 \brief Get Base Priority (non-secure)
1095 \details Returns the current value of the non-secure Base Priority register when in secure state.
1096 \return Base Priority register value
1098 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
1102 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
1109 \brief Set Base Priority
1110 \details Assigns the given value to the Base Priority register.
1111 \param [in] basePri Base Priority value to set
1113 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
1115 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
1119 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1121 \brief Set Base Priority (non-secure)
1122 \details Assigns the given value to the non-secure Base Priority register when in secure state.
1123 \param [in] basePri Base Priority value to set
1125 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
1127 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
1133 \brief Set Base Priority with condition
1134 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
1135 or the new value increases the BASEPRI priority level.
1136 \param [in] basePri Base Priority value to set
1138 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
1140 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
1145 \brief Get Fault Mask
1146 \details Returns the current value of the Fault Mask register.
1147 \return Fault Mask register value
1149 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
1153 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
1158 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1160 \brief Get Fault Mask (non-secure)
1161 \details Returns the current value of the non-secure Fault Mask register when in secure state.
1162 \return Fault Mask register value
1164 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
1168 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
1175 \brief Set Fault Mask
1176 \details Assigns the given value to the Fault Mask register.
1177 \param [in] faultMask Fault Mask value to set
1179 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
1181 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
1185 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1187 \brief Set Fault Mask (non-secure)
1188 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
1189 \param [in] faultMask Fault Mask value to set
1191 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
1193 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
1197 #endif /* __ARM_ARCH_ISA_THUMB >= 2 */
1203 \brief Get Process Stack Pointer Limit
1204 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1205 Stack Pointer Limit register hence zero is returned always in non-secure
1208 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
1209 \return PSPLIM Register value
1211 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
1213 #if (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1214 // without main extensions, the non-secure PSPLIM is RAZ/WI
1218 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
1223 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
1225 \brief Get Process Stack Pointer Limit (non-secure)
1226 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1227 Stack Pointer Limit register hence zero is returned always.
1229 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1230 \return PSPLIM Register value
1232 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
1234 #if __ARM_ARCH_ISA_THUMB < 2
1235 // without main extensions, the non-secure PSPLIM is RAZ/WI
1239 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
1247 \brief Set Process Stack Pointer Limit
1248 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1249 Stack Pointer Limit register hence the write is silently ignored in non-secure
1252 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
1253 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1255 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
1257 #if (__ARM_ARCH_ISA_THUMB < 2) && (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1258 // without main extensions, the non-secure PSPLIM is RAZ/WI
1259 (void)ProcStackPtrLimit;
1261 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
1266 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1268 \brief Set Process Stack Pointer (non-secure)
1269 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1270 Stack Pointer Limit register hence the write is silently ignored.
1272 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1273 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1275 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
1277 #if __ARM_ARCH_ISA_THUMB < 2
1278 // without main extensions, the non-secure PSPLIM is RAZ/WI
1279 (void)ProcStackPtrLimit;
1281 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
1288 \brief Get Main Stack Pointer Limit
1289 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1290 Stack Pointer Limit register hence zero is returned always in non-secure
1293 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
1294 \return MSPLIM Register value
1296 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
1298 #if (__ARM_ARCH_ISA_THUMB < 2) && (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1299 // without main extensions, the non-secure MSPLIM is RAZ/WI
1303 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
1309 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1311 \brief Get Main Stack Pointer Limit (non-secure)
1312 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1313 Stack Pointer Limit register hence zero is returned always.
1315 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
1316 \return MSPLIM Register value
1318 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
1320 #if __ARM_ARCH_ISA_THUMB < 2
1321 // without main extensions, the non-secure MSPLIM is RAZ/WI
1325 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
1333 \brief Set Main Stack Pointer Limit
1334 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1335 Stack Pointer Limit register hence the write is silently ignored in non-secure
1338 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
1339 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
1341 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
1343 #if (__ARM_ARCH_ISA_THUMB < 2) && (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))
1344 // without main extensions, the non-secure MSPLIM is RAZ/WI
1345 (void)MainStackPtrLimit;
1347 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
1352 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1354 \brief Set Main Stack Pointer Limit (non-secure)
1355 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1356 Stack Pointer Limit register hence the write is silently ignored.
1358 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
1359 \param [in] MainStackPtrLimit Main Stack Pointer value to set
1361 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
1363 #if __ARM_ARCH_ISA_THUMB < 2
1364 // without main extensions, the non-secure MSPLIM is RAZ/WI
1365 (void)MainStackPtrLimit;
1367 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
1372 #endif /* __ARM_ARCH >= 8 */
1377 \details Returns the current value of the Floating Point Status/Control register.
1378 \return Floating Point Status/Control register value
1380 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
1382 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1383 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
1384 return __builtin_arm_get_fpscr();
1393 \details Assigns the given value to the Floating Point Status/Control register.
1394 \param [in] fpscr Floating Point Status/Control value to set
1396 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
1398 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1399 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
1400 __builtin_arm_set_fpscr(fpscr);
1407 /** @} end of CMSIS_Core_RegAccFunctions */
1410 /* ################### Compiler specific Intrinsics ########################### */
1411 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1412 Access to dedicated SIMD instructions
1416 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1418 #define __SADD8 __sadd8
1419 #define __QADD8 __qadd8
1420 #define __SHADD8 __shadd8
1421 #define __UADD8 __uadd8
1422 #define __UQADD8 __uqadd8
1423 #define __UHADD8 __uhadd8
1424 #define __SSUB8 __ssub8
1425 #define __QSUB8 __qsub8
1426 #define __SHSUB8 __shsub8
1427 #define __USUB8 __usub8
1428 #define __UQSUB8 __uqsub8
1429 #define __UHSUB8 __uhsub8
1430 #define __SADD16 __sadd16
1431 #define __QADD16 __qadd16
1432 #define __SHADD16 __shadd16
1433 #define __UADD16 __uadd16
1434 #define __UQADD16 __uqadd16
1435 #define __UHADD16 __uhadd16
1436 #define __SSUB16 __ssub16
1437 #define __QSUB16 __qsub16
1438 #define __SHSUB16 __shsub16
1439 #define __USUB16 __usub16
1440 #define __UQSUB16 __uqsub16
1441 #define __UHSUB16 __uhsub16
1442 #define __SASX __sasx
1443 #define __QASX __qasx
1444 #define __SHASX __shasx
1445 #define __UASX __uasx
1446 #define __UQASX __uqasx
1447 #define __UHASX __uhasx
1448 #define __SSAX __ssax
1449 #define __QSAX __qsax
1450 #define __SHSAX __shsax
1451 #define __USAX __usax
1452 #define __UQSAX __uqsax
1453 #define __UHSAX __uhsax
1454 #define __USAD8 __usad8
1455 #define __USADA8 __usada8
1456 #define __SSAT16 __ssat16
1457 #define __USAT16 __usat16
1458 #define __UXTB16 __uxtb16
1459 #define __UXTAB16 __uxtab16
1460 #define __SXTB16 __sxtb16
1461 #define __SXTAB16 __sxtab16
1462 #define __SMUAD __smuad
1463 #define __SMUADX __smuadx
1464 #define __SMLAD __smlad
1465 #define __SMLADX __smladx
1466 #define __SMLALD __smlald
1467 #define __SMLALDX __smlaldx
1468 #define __SMUSD __smusd
1469 #define __SMUSDX __smusdx
1470 #define __SMLSD __smlsd
1471 #define __SMLSDX __smlsdx
1472 #define __SMLSLD __smlsld
1473 #define __SMLSLDX __smlsldx
1475 #define __QADD __qadd
1476 #define __QSUB __qsub
1478 #define __PKHBT(ARG1,ARG2,ARG3) \
1481 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1482 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1486 #define __PKHTB(ARG1,ARG2,ARG3) \
1489 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1491 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
1493 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1497 #define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
1499 #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
1501 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1505 __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
1509 #endif /* (__ARM_FEATURE_DSP == 1) */
1510 /** @} end of group CMSIS_SIMD_intrinsics */
1512 #endif /* __CMSIS_CLANG_H */