1 /**************************************************************************//**
2 * @file cmsis_tiarmclang_m.h
3 * @brief CMSIS compiler tiarmclang header file
5 * @date 23. November 2023
6 ******************************************************************************/
8 * Copyright (c) 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_TIARMCLANG_M_H
26 #define __CMSIS_TIARMCLANG_M_H
28 #pragma clang system_header /* treat file as system include file */
30 #if (__ARM_ACLE >= 200)
33 #error Compiler must support ACLE V2.0
34 #endif /* (__ARM_ACLE >= 200) */
36 /* CMSIS compiler specific defines */
41 #define __INLINE __inline
43 #ifndef __STATIC_INLINE
44 #define __STATIC_INLINE static __inline
46 #ifndef __STATIC_FORCEINLINE
47 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline
50 #define __NO_RETURN __attribute__((__noreturn__))
53 #define __USED __attribute__((used))
56 #define __WEAK __attribute__((weak))
59 #define __PACKED __attribute__((packed, aligned(1)))
61 #ifndef __PACKED_STRUCT
62 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
64 #ifndef __PACKED_UNION
65 #define __PACKED_UNION union __attribute__((packed, aligned(1)))
67 #ifndef __UNALIGNED_UINT16_WRITE
68 #pragma clang diagnostic push
69 #pragma clang diagnostic ignored "-Wpacked"
70 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
71 #pragma clang diagnostic pop
72 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
74 #ifndef __UNALIGNED_UINT16_READ
75 #pragma clang diagnostic push
76 #pragma clang diagnostic ignored "-Wpacked"
77 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
78 #pragma clang diagnostic pop
79 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
81 #ifndef __UNALIGNED_UINT32_WRITE
82 #pragma clang diagnostic push
83 #pragma clang diagnostic ignored "-Wpacked"
84 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
85 #pragma clang diagnostic pop
86 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
88 #ifndef __UNALIGNED_UINT32_READ
89 #pragma clang diagnostic push
90 #pragma clang diagnostic ignored "-Wpacked"
91 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
92 #pragma clang diagnostic pop
93 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
96 #define __ALIGNED(x) __attribute__((aligned(x)))
99 #define __RESTRICT __restrict
101 #ifndef __COMPILER_BARRIER
102 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
105 #define __NO_INIT __attribute__ ((section (".noinit")))
108 #define __ALIAS(x) __attribute__ ((alias(x)))
111 /* ######################### Startup and Lowlevel Init ######################## */
112 #ifndef __PROGRAM_START
113 #define __PROGRAM_START _c_int00
117 #define __INITIAL_SP __STACK_END
120 #ifndef __STACK_LIMIT
121 #define __STACK_LIMIT __STACK_SIZE
124 #ifndef __VECTOR_TABLE
125 #define __VECTOR_TABLE __Vectors
128 #ifndef __VECTOR_TABLE_ATTRIBUTE
129 #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".intvecs")))
132 #if (__ARM_FEATURE_CMSE == 3)
134 #define __STACK_SEAL Image$$STACKSEAL$$ZI$$Base
137 #ifndef __TZ_STACK_SEAL_SIZE
138 #define __TZ_STACK_SEAL_SIZE 8U
141 #ifndef __TZ_STACK_SEAL_VALUE
142 #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
146 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
147 *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
152 /* ########################## Core Instruction Access ######################### */
153 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
154 Access to dedicated instructions
158 /* Define macros for porting to both thumb1 and thumb2.
159 * For thumb1, use low register (r0-r7), specified by constraint "l"
160 * Otherwise, use general registers, specified by constraint "r" */
161 #if defined (__thumb__) && !defined (__thumb2__)
162 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
163 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
164 #define __CMSIS_GCC_USE_REG(r) "l" (r)
166 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
167 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
168 #define __CMSIS_GCC_USE_REG(r) "r" (r)
173 \details No Operation does nothing. This instruction can be used for code alignment purposes.
175 #define __NOP() __nop()
179 \brief Wait For Interrupt
180 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
182 #define __WFI() __wfi()
186 \brief Wait For Event
187 \details Wait For Event is a hint instruction that permits the processor to enter
188 a low-power state until one of a number of events occurs.
190 #define __WFE() __wfe()
195 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
197 #define __SEV() __sev()
201 \brief Instruction Synchronization Barrier
202 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
203 so that all instructions following the ISB are fetched from cache or memory,
204 after the instruction has been completed.
206 #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)
218 \brief Data Memory Barrier
219 \details Ensures the apparent order of the explicit memory operations before
220 and after the instruction, without ensuring their completion.
222 #define __DMB() __dmb(0xF)
226 \brief Reverse byte order (32 bit)
227 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
228 \param [in] value Value to reverse
229 \return Reversed value
231 #define __REV(value) __rev(value)
235 \brief Reverse byte order (16 bit)
236 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
237 \param [in] value Value to reverse
238 \return Reversed value
240 #define __REV16(value) __rev16(value)
244 \brief Reverse byte order (16 bit)
245 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
246 \param [in] value Value to reverse
247 \return Reversed value
249 #define __REVSH(value) __revsh(value)
253 \brief Rotate Right in unsigned value (32 bit)
254 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
255 \param [in] op1 Value to rotate
256 \param [in] op2 Number of Bits to rotate
257 \return Rotated value
259 #define __ROR(op1, op2) __ror(op1, op2)
264 \details Causes the processor to enter Debug state.
265 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
266 \param [in] value is ignored by the processor.
267 If required, a debugger can use it to store additional information about the breakpoint.
269 #define __BKPT(value) __ASM volatile ("bkpt "#value)
273 \brief Reverse bit order of value
274 \details Reverses the bit order of the given value.
275 \param [in] value Value to reverse
276 \return Reversed value
278 #define __RBIT(value) __rbit(value)
282 \brief Count leading zeros
283 \details Counts the number of leading zeros of a data value.
284 \param [in] value Value to count the leading zeros
285 \return number of leading zeros in value
287 #define __CLZ(value) __clz(value)
290 /* __ARM_FEATURE_SAT is wrong for for Armv8-M Baseline devices */
291 #if ((__ARM_FEATURE_SAT >= 1) && \
292 (__ARM_ARCH_ISA_THUMB >= 2) )
294 \brief Signed Saturate
295 \details Saturates a signed value.
296 \param [in] value Value to be saturated
297 \param [in] sat Bit position to saturate to (1..32)
298 \return Saturated value
300 #define __SSAT(value, sat) __ssat(value, sat)
304 \brief Unsigned Saturate
305 \details Saturates an unsigned value.
306 \param [in] value Value to be saturated
307 \param [in] sat Bit position to saturate to (0..31)
308 \return Saturated value
310 #define __USAT(value, sat) __usat(value, sat)
312 #else /* (__ARM_FEATURE_SAT >= 1) */
314 \brief Signed Saturate
315 \details Saturates a signed value.
316 \param [in] value Value to be saturated
317 \param [in] sat Bit position to saturate to (1..32)
318 \return Saturated value
320 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
322 if ((sat >= 1U) && (sat <= 32U))
324 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
325 const int32_t min = -1 - max ;
340 \brief Unsigned Saturate
341 \details Saturates an unsigned value.
342 \param [in] value Value to be saturated
343 \param [in] sat Bit position to saturate to (0..31)
344 \return Saturated value
346 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
350 const uint32_t max = ((1U << sat) - 1U);
351 if (val > (int32_t)max)
360 return ((uint32_t)val);
362 #endif /* (__ARM_FEATURE_SAT >= 1) */
365 #if (__ARM_FEATURE_LDREX >= 1)
367 \brief Remove the exclusive lock
368 \details Removes the exclusive lock which is created by LDREX.
370 #define __CLREX __builtin_arm_clrex
374 \brief LDR Exclusive (8 bit)
375 \details Executes a exclusive LDR instruction for 8 bit value.
376 \param [in] ptr Pointer to data
377 \return value of type uint8_t at (*ptr)
379 #define __LDREXB (uint8_t)__builtin_arm_ldrex
383 \brief STR Exclusive (8 bit)
384 \details Executes a exclusive STR instruction for 8 bit values.
385 \param [in] value Value to store
386 \param [in] ptr Pointer to location
387 \return 0 Function succeeded
388 \return 1 Function failed
390 #define __STREXB (uint32_t)__builtin_arm_strex
391 #endif /* (__ARM_FEATURE_LDREX >= 1) */
394 #if (__ARM_FEATURE_LDREX >= 2)
396 \brief LDR Exclusive (16 bit)
397 \details Executes a exclusive LDR instruction for 16 bit values.
398 \param [in] ptr Pointer to data
399 \return value of type uint16_t at (*ptr)
401 #define __LDREXH (uint16_t)__builtin_arm_ldrex
405 \brief STR Exclusive (16 bit)
406 \details Executes a exclusive STR instruction for 16 bit values.
407 \param [in] value Value to store
408 \param [in] ptr Pointer to location
409 \return 0 Function succeeded
410 \return 1 Function failed
412 #define __STREXH (uint32_t)__builtin_arm_strex
413 #endif /* (__ARM_FEATURE_LDREX >= 2) */
416 #if (__ARM_FEATURE_LDREX >= 4)
418 \brief LDR Exclusive (32 bit)
419 \details Executes a exclusive LDR instruction for 32 bit values.
420 \param [in] ptr Pointer to data
421 \return value of type uint32_t at (*ptr)
423 #define __LDREXW (uint32_t)__builtin_arm_ldrex
427 \brief STR Exclusive (32 bit)
428 \details Executes a exclusive STR instruction for 32 bit values.
429 \param [in] value Value to store
430 \param [in] ptr Pointer to location
431 \return 0 Function succeeded
432 \return 1 Function failed
434 #define __STREXW (uint32_t)__builtin_arm_strex
435 #endif /* (__ARM_FEATURE_LDREX >= 4) */
438 #if (__ARM_ARCH_ISA_THUMB >= 2)
440 \brief Rotate Right with Extend (32 bit)
441 \details Moves each bit of a bitstring right by one bit.
442 The carry input is shifted in at the left end of the bitstring.
443 \param [in] value Value to rotate
444 \return Rotated value
446 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
450 __ASM volatile ("rrx %0, %1" : "=r" (result) : "r" (value));
456 \brief LDRT Unprivileged (8 bit)
457 \details Executes a Unprivileged LDRT instruction for 8 bit value.
458 \param [in] ptr Pointer to data
459 \return value of type uint8_t at (*ptr)
461 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
465 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
466 return ((uint8_t)result); /* Add explicit type cast here */
471 \brief LDRT Unprivileged (16 bit)
472 \details Executes a Unprivileged LDRT instruction for 16 bit values.
473 \param [in] ptr Pointer to data
474 \return value of type uint16_t at (*ptr)
476 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
480 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
481 return ((uint16_t)result); /* Add explicit type cast here */
486 \brief LDRT Unprivileged (32 bit)
487 \details Executes a Unprivileged LDRT instruction for 32 bit values.
488 \param [in] ptr Pointer to data
489 \return value of type uint32_t at (*ptr)
491 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
495 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
501 \brief STRT Unprivileged (8 bit)
502 \details Executes a Unprivileged STRT instruction for 8 bit values.
503 \param [in] value Value to store
504 \param [in] ptr Pointer to location
506 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
508 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
513 \brief STRT Unprivileged (16 bit)
514 \details Executes a Unprivileged STRT instruction for 16 bit values.
515 \param [in] value Value to store
516 \param [in] ptr Pointer to location
518 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
520 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
525 \brief STRT Unprivileged (32 bit)
526 \details Executes a Unprivileged STRT instruction for 32 bit values.
527 \param [in] value Value to store
528 \param [in] ptr Pointer to location
530 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
532 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
534 #endif /* (__ARM_ARCH_ISA_THUMB >= 2) */
537 #if (__ARM_ARCH >= 8)
539 \brief Load-Acquire (8 bit)
540 \details Executes a LDAB instruction for 8 bit value.
541 \param [in] ptr Pointer to data
542 \return value of type uint8_t at (*ptr)
544 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
548 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
549 return ((uint8_t)result); /* Add explicit type cast here */
554 \brief Load-Acquire (16 bit)
555 \details Executes a LDAH instruction for 16 bit values.
556 \param [in] ptr Pointer to data
557 \return value of type uint16_t at (*ptr)
559 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
563 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
564 return ((uint16_t)result); /* Add explicit type cast here */
569 \brief Load-Acquire (32 bit)
570 \details Executes a LDA instruction for 32 bit values.
571 \param [in] ptr Pointer to data
572 \return value of type uint32_t at (*ptr)
574 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
578 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
584 \brief Store-Release (8 bit)
585 \details Executes a STLB instruction for 8 bit values.
586 \param [in] value Value to store
587 \param [in] ptr Pointer to location
589 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
591 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
596 \brief Store-Release (16 bit)
597 \details Executes a STLH instruction for 16 bit values.
598 \param [in] value Value to store
599 \param [in] ptr Pointer to location
601 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
603 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
608 \brief Store-Release (32 bit)
609 \details Executes a STL instruction for 32 bit values.
610 \param [in] value Value to store
611 \param [in] ptr Pointer to location
613 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
615 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
620 \brief Load-Acquire Exclusive (8 bit)
621 \details Executes a LDAB exclusive instruction for 8 bit value.
622 \param [in] ptr Pointer to data
623 \return value of type uint8_t at (*ptr)
625 #define __LDAEXB (uint8_t)__builtin_arm_ldaex
629 \brief Load-Acquire Exclusive (16 bit)
630 \details Executes a LDAH exclusive instruction for 16 bit values.
631 \param [in] ptr Pointer to data
632 \return value of type uint16_t at (*ptr)
634 #define __LDAEXH (uint16_t)__builtin_arm_ldaex
638 \brief Load-Acquire Exclusive (32 bit)
639 \details Executes a LDA exclusive instruction for 32 bit values.
640 \param [in] ptr Pointer to data
641 \return value of type uint32_t at (*ptr)
643 #define __LDAEX (uint32_t)__builtin_arm_ldaex
647 \brief Store-Release Exclusive (8 bit)
648 \details Executes a STLB exclusive instruction for 8 bit values.
649 \param [in] value Value to store
650 \param [in] ptr Pointer to location
651 \return 0 Function succeeded
652 \return 1 Function failed
654 #define __STLEXB (uint32_t)__builtin_arm_stlex
658 \brief Store-Release Exclusive (16 bit)
659 \details Executes a STLH exclusive instruction for 16 bit values.
660 \param [in] value Value to store
661 \param [in] ptr Pointer to location
662 \return 0 Function succeeded
663 \return 1 Function failed
665 #define __STLEXH (uint32_t)__builtin_arm_stlex
669 \brief Store-Release Exclusive (32 bit)
670 \details Executes a STL exclusive instruction for 32 bit values.
671 \param [in] value Value to store
672 \param [in] ptr Pointer to location
673 \return 0 Function succeeded
674 \return 1 Function failed
676 #define __STLEX (uint32_t)__builtin_arm_stlex
678 #endif /* (__ARM_ARCH >= 8) */
680 /** @}*/ /* end of group CMSIS_Core_InstructionInterface */
683 /* ########################### Core Function Access ########################### */
684 /** \ingroup CMSIS_Core_FunctionInterface
685 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
690 \brief Enable IRQ Interrupts
691 \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
692 Can only be executed in Privileged modes.
694 #ifndef __ARM_COMPAT_H
695 __STATIC_FORCEINLINE void __enable_irq(void)
697 __ASM volatile ("cpsie i" : : : "memory");
703 \brief Disable IRQ Interrupts
704 \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
705 Can only be executed in Privileged modes.
707 #ifndef __ARM_COMPAT_H
708 __STATIC_FORCEINLINE void __disable_irq(void)
710 __ASM volatile ("cpsid i" : : : "memory");
716 \brief Get Control Register
717 \details Returns the content of the Control Register.
718 \return Control Register value
720 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
724 __ASM volatile ("MRS %0, control" : "=r" (result) );
729 #if (__ARM_FEATURE_CMSE == 3)
731 \brief Get Control Register (non-secure)
732 \details Returns the content of the non-secure Control Register when in secure mode.
733 \return non-secure Control Register value
735 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
739 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
746 \brief Set Control Register
747 \details Writes the given value to the Control Register.
748 \param [in] control Control Register value to set
750 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
752 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
757 #if (__ARM_FEATURE_CMSE == 3)
759 \brief Set Control Register (non-secure)
760 \details Writes the given value to the non-secure Control Register when in secure state.
761 \param [in] control Control Register value to set
763 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
765 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
772 \brief Get IPSR Register
773 \details Returns the content of the IPSR Register.
774 \return IPSR Register value
776 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
780 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
786 \brief Get APSR Register
787 \details Returns the content of the APSR Register.
788 \return APSR Register value
790 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
794 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
800 \brief Get xPSR Register
801 \details Returns the content of the xPSR Register.
802 \return xPSR Register value
804 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
808 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
814 \brief Get Process Stack Pointer
815 \details Returns the current value of the Process Stack Pointer (PSP).
816 \return PSP Register value
818 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
822 __ASM volatile ("MRS %0, psp" : "=r" (result) );
827 #if (__ARM_FEATURE_CMSE == 3)
829 \brief Get Process Stack Pointer (non-secure)
830 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
831 \return PSP Register value
833 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
837 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
844 \brief Set Process Stack Pointer
845 \details Assigns the given value to the Process Stack Pointer (PSP).
846 \param [in] topOfProcStack Process Stack Pointer value to set
848 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
850 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
854 #if (__ARM_FEATURE_CMSE == 3)
856 \brief Set Process Stack Pointer (non-secure)
857 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
858 \param [in] topOfProcStack Process Stack Pointer value to set
860 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
862 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
868 \brief Get Main Stack Pointer
869 \details Returns the current value of the Main Stack Pointer (MSP).
870 \return MSP Register value
872 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
876 __ASM volatile ("MRS %0, msp" : "=r" (result) );
881 #if (__ARM_FEATURE_CMSE == 3)
883 \brief Get Main Stack Pointer (non-secure)
884 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
885 \return MSP Register value
887 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
891 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
898 \brief Set Main Stack Pointer
899 \details Assigns the given value to the Main Stack Pointer (MSP).
900 \param [in] topOfMainStack Main Stack Pointer value to set
902 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
904 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
908 #if (__ARM_FEATURE_CMSE == 3)
910 \brief Set Main Stack Pointer (non-secure)
911 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
912 \param [in] topOfMainStack Main Stack Pointer value to set
914 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
916 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
921 #if (__ARM_FEATURE_CMSE == 3)
923 \brief Get Stack Pointer (non-secure)
924 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
925 \return SP Register value
927 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
931 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
937 \brief Set Stack Pointer (non-secure)
938 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
939 \param [in] topOfStack Stack Pointer value to set
941 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
943 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
949 \brief Get Priority Mask
950 \details Returns the current state of the priority mask bit from the Priority Mask Register.
951 \return Priority Mask value
953 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
957 __ASM volatile ("MRS %0, primask" : "=r" (result) );
962 #if (__ARM_FEATURE_CMSE == 3)
964 \brief Get Priority Mask (non-secure)
965 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
966 \return Priority Mask value
968 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
972 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
979 \brief Set Priority Mask
980 \details Assigns the given value to the Priority Mask Register.
981 \param [in] priMask Priority Mask
983 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
985 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
989 #if (__ARM_FEATURE_CMSE == 3)
991 \brief Set Priority Mask (non-secure)
992 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
993 \param [in] priMask Priority Mask
995 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
997 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
1002 #if (__ARM_ARCH_ISA_THUMB >= 2)
1005 \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
1006 Can only be executed in Privileged modes.
1008 __STATIC_FORCEINLINE void __enable_fault_irq(void)
1010 __ASM volatile ("cpsie f" : : : "memory");
1016 \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
1017 Can only be executed in Privileged modes.
1019 __STATIC_FORCEINLINE void __disable_fault_irq(void)
1021 __ASM volatile ("cpsid f" : : : "memory");
1026 \brief Get Base Priority
1027 \details Returns the current value of the Base Priority register.
1028 \return Base Priority register value
1030 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
1034 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
1039 #if (__ARM_FEATURE_CMSE == 3)
1041 \brief Get Base Priority (non-secure)
1042 \details Returns the current value of the non-secure Base Priority register when in secure state.
1043 \return Base Priority register value
1045 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
1049 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
1056 \brief Set Base Priority
1057 \details Assigns the given value to the Base Priority register.
1058 \param [in] basePri Base Priority value to set
1060 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
1062 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
1066 #if (__ARM_FEATURE_CMSE == 3)
1068 \brief Set Base Priority (non-secure)
1069 \details Assigns the given value to the non-secure Base Priority register when in secure state.
1070 \param [in] basePri Base Priority value to set
1072 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
1074 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
1080 \brief Set Base Priority with condition
1081 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
1082 or the new value increases the BASEPRI priority level.
1083 \param [in] basePri Base Priority value to set
1085 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
1087 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
1092 \brief Get Fault Mask
1093 \details Returns the current value of the Fault Mask register.
1094 \return Fault Mask register value
1096 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
1100 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
1105 #if (__ARM_FEATURE_CMSE == 3)
1107 \brief Get Fault Mask (non-secure)
1108 \details Returns the current value of the non-secure Fault Mask register when in secure state.
1109 \return Fault Mask register value
1111 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
1115 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
1122 \brief Set Fault Mask
1123 \details Assigns the given value to the Fault Mask register.
1124 \param [in] faultMask Fault Mask value to set
1126 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
1128 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
1132 #if (__ARM_FEATURE_CMSE == 3)
1134 \brief Set Fault Mask (non-secure)
1135 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
1136 \param [in] faultMask Fault Mask value to set
1138 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
1140 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
1144 #endif /* (__ARM_ARCH_ISA_THUMB >= 2) */
1147 #if (__ARM_ARCH >= 8)
1149 \brief Get Process Stack Pointer Limit
1150 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1151 Stack Pointer Limit register hence zero is returned always in non-secure
1154 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
1155 \return PSPLIM Register value
1157 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
1159 #if (((__ARM_ARCH_8M_MAIN__ < 1) && \
1160 (__ARM_ARCH_8_1M_MAIN__ < 1) ) && \
1161 (__ARM_FEATURE_CMSE < 3) )
1162 /* without main extensions, the non-secure PSPLIM is RAZ/WI */
1166 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
1171 #if (__ARM_FEATURE_CMSE == 3)
1173 \brief Get Process Stack Pointer Limit (non-secure)
1174 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1175 Stack Pointer Limit register hence zero is returned always.
1177 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1178 \return PSPLIM Register value
1180 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
1182 #if ((__ARM_ARCH_8M_MAIN__ < 1) && \
1183 (__ARM_ARCH_8_1M_MAIN__ < 1) )
1184 /* without main extensions, the non-secure PSPLIM is RAZ/WI */
1188 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
1196 \brief Set Process Stack Pointer Limit
1197 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1198 Stack Pointer Limit register hence the write is silently ignored in non-secure
1201 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
1202 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1204 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
1206 #if (((__ARM_ARCH_8M_MAIN__ < 1) && \
1207 (__ARM_ARCH_8_1M_MAIN__ < 1) ) && \
1208 (__ARM_FEATURE_CMSE < 3) )
1209 /* without main extensions, the non-secure PSPLIM is RAZ/WI */
1210 (void)ProcStackPtrLimit;
1212 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
1217 #if (__ARM_FEATURE_CMSE == 3)
1219 \brief Set Process Stack Pointer (non-secure)
1220 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1221 Stack Pointer Limit register hence the write is silently ignored.
1223 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1224 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1226 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
1228 #if ((__ARM_ARCH_8M_MAIN__ < 1) && \
1229 (__ARM_ARCH_8_1M_MAIN__ < 1) )
1230 /* without main extensions, the non-secure PSPLIM is RAZ/WI */
1231 (void)ProcStackPtrLimit;
1233 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
1240 \brief Get Main Stack Pointer Limit
1241 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1242 Stack Pointer Limit register hence zero is returned always.
1244 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
1245 \return MSPLIM Register value
1247 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
1249 #if (((__ARM_ARCH_8M_MAIN__ < 1) && \
1250 (__ARM_ARCH_8_1M_MAIN__ < 1) ) && \
1251 (__ARM_FEATURE_CMSE < 3) )
1252 /* without main extensions, the non-secure MSPLIM is RAZ/WI */
1256 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
1262 #if (__ARM_FEATURE_CMSE == 3)
1264 \brief Get Main Stack Pointer Limit (non-secure)
1265 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1266 Stack Pointer Limit register hence zero is returned always.
1268 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
1269 \return MSPLIM Register value
1271 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
1273 #if ((__ARM_ARCH_8M_MAIN__ < 1) && \
1274 (__ARM_ARCH_8_1M_MAIN__ < 1) )
1275 /* without main extensions, the non-secure MSPLIM is RAZ/WI */
1279 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
1287 \brief Set Main Stack Pointer Limit
1288 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1289 Stack Pointer Limit register hence the write is silently ignored.
1291 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
1292 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
1294 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
1296 #if (((__ARM_ARCH_8M_MAIN__ < 1) && \
1297 (__ARM_ARCH_8_1M_MAIN__ < 1) ) && \
1298 (__ARM_FEATURE_CMSE < 3) )
1299 /* without main extensions, the non-secure MSPLIM is RAZ/WI */
1300 (void)MainStackPtrLimit;
1302 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
1307 #if (__ARM_FEATURE_CMSE == 3)
1309 \brief Set Main Stack Pointer Limit (non-secure)
1310 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1311 Stack Pointer Limit register hence the write is silently ignored.
1313 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
1314 \param [in] MainStackPtrLimit Main Stack Pointer value to set
1316 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
1318 #if ((__ARM_ARCH_8M_MAIN__ < 1) && \
1319 (__ARM_ARCH_8_1M_MAIN__ < 1) )
1320 /* without main extensions, the non-secure MSPLIM is RAZ/WI */
1321 (void)MainStackPtrLimit;
1323 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
1328 #endif /* (__ARM_ARCH >= 8) */
1333 \details Returns the current value of the Floating Point Status/Control register.
1334 \return Floating Point Status/Control register value
1336 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
1339 return (__builtin_arm_get_fpscr());
1348 \details Assigns the given value to the Floating Point Status/Control register.
1349 \param [in] fpscr Floating Point Status/Control value to set
1351 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
1354 __builtin_arm_set_fpscr(fpscr);
1361 /** @} end of CMSIS_Core_RegAccFunctions */
1364 /* ################### Compiler specific Intrinsics ########################### */
1365 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1366 Access to dedicated SIMD instructions
1370 #if (__ARM_FEATURE_DSP == 1)
1371 #define __SADD8 __sadd8
1372 #define __QADD8 __qadd8
1373 #define __SHADD8 __shadd8
1374 #define __UADD8 __uadd8
1375 #define __UQADD8 __uqadd8
1376 #define __UHADD8 __uhadd8
1377 #define __SSUB8 __ssub8
1378 #define __QSUB8 __qsub8
1379 #define __SHSUB8 __shsub8
1380 #define __USUB8 __usub8
1381 #define __UQSUB8 __uqsub8
1382 #define __UHSUB8 __uhsub8
1383 #define __SADD16 __sadd16
1384 #define __QADD16 __qadd16
1385 #define __SHADD16 __shadd16
1386 #define __UADD16 __uadd16
1387 #define __UQADD16 __uqadd16
1388 #define __UHADD16 __uhadd16
1389 #define __SSUB16 __ssub16
1390 #define __QSUB16 __qsub16
1391 #define __SHSUB16 __shsub16
1392 #define __USUB16 __usub16
1393 #define __UQSUB16 __uqsub16
1394 #define __UHSUB16 __uhsub16
1395 #define __SASX __sasx
1396 #define __QASX __qasx
1397 #define __SHASX __shasx
1398 #define __UASX __uasx
1399 #define __UQASX __uqasx
1400 #define __UHASX __uhasx
1401 #define __SSAX __ssax
1402 #define __QSAX __qsax
1403 #define __SHSAX __shsax
1404 #define __USAX __usax
1405 #define __UQSAX __uqsax
1406 #define __UHSAX __uhsax
1407 #define __USAD8 __usad8
1408 #define __USADA8 __usada8
1409 #define __SSAT16 __ssat16
1410 #define __USAT16 __usat16
1411 #define __UXTB16 __uxtb16
1412 #define __UXTAB16 __uxtab16
1413 #define __SXTB16 __sxtb16
1414 #define __SXTAB16 __sxtab16
1415 #define __SMUAD __smuad
1416 #define __SMUADX __smuadx
1417 #define __SMLAD __smlad
1418 #define __SMLADX __smladx
1419 #define __SMLALD __smlald
1420 #define __SMLALDX __smlaldx
1421 #define __SMUSD __smusd
1422 #define __SMUSDX __smusdx
1423 #define __SMLSD __smlsd
1424 #define __SMLSDX __smlsdx
1425 #define __SMLSLD __smlsld
1426 #define __SMLSLDX __smlsldx
1428 #define __QADD __qadd
1429 #define __QSUB __qsub
1431 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
1432 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
1434 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
1435 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
1437 #define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2))
1439 #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3))
1441 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1445 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
1449 #endif /* (__ARM_FEATURE_DSP == 1) */
1450 /** @} end of group CMSIS_SIMD_intrinsics */
1453 #endif /* __CMSIS_TIARMCLANG_M_H */