1 /**************************************************************************//**
3 * @brief CMSIS compiler GCC header file
5 * @date 17. December 2022
6 ******************************************************************************/
8 * Copyright (c) 2009-2021 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 #define __NO_INIT __attribute__ ((section (".bss.noinit")))
123 #define __ALIAS(x) __attribute__ ((alias(x)))
126 /* ######################### Startup and Lowlevel Init ######################## */
128 #ifndef __PROGRAM_START
131 \brief Initializes data and bss sections
132 \details This default implementations initialized all data and additional bss
133 sections relying on .copy.table and .zero.table specified properly
134 in the used linker script.
137 __STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void)
139 extern void _start(void) __NO_RETURN;
141 typedef struct __copy_table {
147 typedef struct __zero_table {
152 extern const __copy_table_t __copy_table_start__;
153 extern const __copy_table_t __copy_table_end__;
154 extern const __zero_table_t __zero_table_start__;
155 extern const __zero_table_t __zero_table_end__;
157 for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
158 for(uint32_t i=0u; i<pTable->wlen; ++i) {
159 pTable->dest[i] = pTable->src[i];
163 for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
164 for(uint32_t i=0u; i<pTable->wlen; ++i) {
165 pTable->dest[i] = 0u;
172 #define __PROGRAM_START __cmsis_start
176 #define __INITIAL_SP __StackTop
179 #ifndef __STACK_LIMIT
180 #define __STACK_LIMIT __StackLimit
183 #ifndef __VECTOR_TABLE
184 #define __VECTOR_TABLE __Vectors
187 #ifndef __VECTOR_TABLE_ATTRIBUTE
188 #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors")))
191 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
193 #define __STACK_SEAL __StackSeal
196 #ifndef __TZ_STACK_SEAL_SIZE
197 #define __TZ_STACK_SEAL_SIZE 8U
200 #ifndef __TZ_STACK_SEAL_VALUE
201 #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
205 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
206 *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
211 /* ########################## Core Instruction Access ######################### */
212 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
213 Access to dedicated instructions
217 /* Define macros for porting to both thumb1 and thumb2.
218 * For thumb1, use low register (r0-r7), specified by constraint "l"
219 * Otherwise, use general registers, specified by constraint "r" */
220 #if defined (__thumb__) && !defined (__thumb2__)
221 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
222 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
223 #define __CMSIS_GCC_USE_REG(r) "l" (r)
225 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
226 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
227 #define __CMSIS_GCC_USE_REG(r) "r" (r)
232 \details No Operation does nothing. This instruction can be used for code alignment purposes.
234 #define __NOP() __ASM volatile ("nop")
237 \brief Wait For Interrupt
238 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
240 #define __WFI() __ASM volatile ("wfi":::"memory")
244 \brief Wait For Event
245 \details Wait For Event is a hint instruction that permits the processor to enter
246 a low-power state until one of a number of events occurs.
248 #define __WFE() __ASM volatile ("wfe":::"memory")
253 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
255 #define __SEV() __ASM volatile ("sev")
259 \brief Instruction Synchronization Barrier
260 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
261 so that all instructions following the ISB are fetched from cache or memory,
262 after the instruction has been completed.
264 __STATIC_FORCEINLINE void __ISB(void)
266 __ASM volatile ("isb 0xF":::"memory");
271 \brief Data Synchronization Barrier
272 \details Acts as a special kind of Data Memory Barrier.
273 It completes when all explicit memory accesses before this instruction complete.
275 __STATIC_FORCEINLINE void __DSB(void)
277 __ASM volatile ("dsb 0xF":::"memory");
282 \brief Data Memory Barrier
283 \details Ensures the apparent order of the explicit memory operations before
284 and after the instruction, without ensuring their completion.
286 __STATIC_FORCEINLINE void __DMB(void)
288 __ASM volatile ("dmb 0xF":::"memory");
293 \brief Reverse byte order (32 bit)
294 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
295 \param [in] value Value to reverse
296 \return Reversed value
298 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
300 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
301 return __builtin_bswap32(value);
305 __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
312 \brief Reverse byte order (16 bit)
313 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
314 \param [in] value Value to reverse
315 \return Reversed value
317 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
321 __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
327 \brief Reverse byte order (16 bit)
328 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
329 \param [in] value Value to reverse
330 \return Reversed value
332 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
334 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
335 return (int16_t)__builtin_bswap16(value);
339 __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
346 \brief Rotate Right in unsigned value (32 bit)
347 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
348 \param [in] op1 Value to rotate
349 \param [in] op2 Number of Bits to rotate
350 \return Rotated value
352 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
359 return (op1 >> op2) | (op1 << (32U - op2));
365 \details Causes the processor to enter Debug state.
366 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
367 \param [in] value is ignored by the processor.
368 If required, a debugger can use it to store additional information about the breakpoint.
370 #define __BKPT(value) __ASM volatile ("bkpt "#value)
374 \brief Reverse bit order of value
375 \details Reverses the bit order of the given value.
376 \param [in] value Value to reverse
377 \return Reversed value
379 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
383 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
384 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
385 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
386 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
388 uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
390 result = value; /* r will be reversed bits of v; first get LSB of v */
391 for (value >>= 1U; value != 0U; value >>= 1U)
394 result |= value & 1U;
397 result <<= s; /* shift when v's highest bits are zero */
404 \brief Count leading zeros
405 \details Counts the number of leading zeros of a data value.
406 \param [in] value Value to count the leading zeros
407 \return number of leading zeros in value
409 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
411 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
412 __builtin_clz(0) is undefined behaviour, so handle this case specially.
413 This guarantees ARM-compatible results if happening to compile on a non-ARM
414 target, and ensures the compiler doesn't decide to activate any
415 optimisations using the logic "value was passed to __builtin_clz, so it
417 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
418 single CLZ instruction.
424 return __builtin_clz(value);
428 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
429 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
430 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
431 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
433 \brief LDR Exclusive (8 bit)
434 \details Executes a exclusive LDR instruction for 8 bit value.
435 \param [in] ptr Pointer to data
436 \return value of type uint8_t at (*ptr)
438 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
442 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
443 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
445 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
446 accepted by assembler. So has to use following less efficient pattern.
448 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
450 return ((uint8_t) result); /* Add explicit type cast here */
455 \brief LDR Exclusive (16 bit)
456 \details Executes a exclusive LDR instruction for 16 bit values.
457 \param [in] ptr Pointer to data
458 \return value of type uint16_t at (*ptr)
460 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
464 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
465 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
467 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
468 accepted by assembler. So has to use following less efficient pattern.
470 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
472 return ((uint16_t) result); /* Add explicit type cast here */
477 \brief LDR Exclusive (32 bit)
478 \details Executes a exclusive LDR instruction for 32 bit values.
479 \param [in] ptr Pointer to data
480 \return value of type uint32_t at (*ptr)
482 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
486 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
492 \brief STR Exclusive (8 bit)
493 \details Executes a exclusive STR instruction for 8 bit values.
494 \param [in] value Value to store
495 \param [in] ptr Pointer to location
496 \return 0 Function succeeded
497 \return 1 Function failed
499 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
503 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
509 \brief STR Exclusive (16 bit)
510 \details Executes a exclusive STR instruction for 16 bit values.
511 \param [in] value Value to store
512 \param [in] ptr Pointer to location
513 \return 0 Function succeeded
514 \return 1 Function failed
516 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
520 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
526 \brief STR Exclusive (32 bit)
527 \details Executes a exclusive STR instruction for 32 bit values.
528 \param [in] value Value to store
529 \param [in] ptr Pointer to location
530 \return 0 Function succeeded
531 \return 1 Function failed
533 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
537 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
543 \brief Remove the exclusive lock
544 \details Removes the exclusive lock which is created by LDREX.
546 __STATIC_FORCEINLINE void __CLREX(void)
548 __ASM volatile ("clrex" ::: "memory");
551 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
552 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
553 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
554 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
557 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
558 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
559 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
561 \brief Signed Saturate
562 \details Saturates a signed value.
563 \param [in] ARG1 Value to be saturated
564 \param [in] ARG2 Bit position to saturate to (1..32)
565 \return Saturated value
567 #define __SSAT(ARG1, ARG2) \
570 int32_t __RES, __ARG1 = (ARG1); \
571 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
577 \brief Unsigned Saturate
578 \details Saturates an unsigned value.
579 \param [in] ARG1 Value to be saturated
580 \param [in] ARG2 Bit position to saturate to (0..31)
581 \return Saturated value
583 #define __USAT(ARG1, ARG2) \
586 uint32_t __RES, __ARG1 = (ARG1); \
587 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
593 \brief Rotate Right with Extend (32 bit)
594 \details Moves each bit of a bitstring right by one bit.
595 The carry input is shifted in at the left end of the bitstring.
596 \param [in] value Value to rotate
597 \return Rotated value
599 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
603 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
609 \brief LDRT Unprivileged (8 bit)
610 \details Executes a Unprivileged LDRT instruction for 8 bit value.
611 \param [in] ptr Pointer to data
612 \return value of type uint8_t at (*ptr)
614 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
618 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
619 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
621 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
622 accepted by assembler. So has to use following less efficient pattern.
624 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
626 return ((uint8_t) result); /* Add explicit type cast here */
631 \brief LDRT Unprivileged (16 bit)
632 \details Executes a Unprivileged LDRT instruction for 16 bit values.
633 \param [in] ptr Pointer to data
634 \return value of type uint16_t at (*ptr)
636 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
640 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
641 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
643 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
644 accepted by assembler. So has to use following less efficient pattern.
646 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
648 return ((uint16_t) result); /* Add explicit type cast here */
653 \brief LDRT Unprivileged (32 bit)
654 \details Executes a Unprivileged LDRT instruction for 32 bit values.
655 \param [in] ptr Pointer to data
656 \return value of type uint32_t at (*ptr)
658 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
662 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
668 \brief STRT Unprivileged (8 bit)
669 \details Executes a Unprivileged STRT instruction for 8 bit values.
670 \param [in] value Value to store
671 \param [in] ptr Pointer to location
673 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
675 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
680 \brief STRT Unprivileged (16 bit)
681 \details Executes a Unprivileged STRT instruction for 16 bit values.
682 \param [in] value Value to store
683 \param [in] ptr Pointer to location
685 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
687 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
692 \brief STRT Unprivileged (32 bit)
693 \details Executes a Unprivileged STRT instruction for 32 bit values.
694 \param [in] value Value to store
695 \param [in] ptr Pointer to location
697 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
699 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
702 #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
703 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
704 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
707 \brief Signed Saturate
708 \details Saturates a signed value.
709 \param [in] value Value to be saturated
710 \param [in] sat Bit position to saturate to (1..32)
711 \return Saturated value
713 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
715 if ((sat >= 1U) && (sat <= 32U))
717 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
718 const int32_t min = -1 - max ;
732 \brief Unsigned Saturate
733 \details Saturates an unsigned value.
734 \param [in] value Value to be saturated
735 \param [in] sat Bit position to saturate to (0..31)
736 \return Saturated value
738 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
742 const uint32_t max = ((1U << sat) - 1U);
743 if (val > (int32_t)max)
752 return (uint32_t)val;
755 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
756 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
757 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
760 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
761 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
763 \brief Load-Acquire (8 bit)
764 \details Executes a LDAB instruction for 8 bit value.
765 \param [in] ptr Pointer to data
766 \return value of type uint8_t at (*ptr)
768 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
772 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
773 return ((uint8_t) result);
778 \brief Load-Acquire (16 bit)
779 \details Executes a LDAH instruction for 16 bit values.
780 \param [in] ptr Pointer to data
781 \return value of type uint16_t at (*ptr)
783 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
787 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
788 return ((uint16_t) result);
793 \brief Load-Acquire (32 bit)
794 \details Executes a LDA instruction for 32 bit values.
795 \param [in] ptr Pointer to data
796 \return value of type uint32_t at (*ptr)
798 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
802 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
808 \brief Store-Release (8 bit)
809 \details Executes a STLB instruction for 8 bit values.
810 \param [in] value Value to store
811 \param [in] ptr Pointer to location
813 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
815 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
820 \brief Store-Release (16 bit)
821 \details Executes a STLH instruction for 16 bit values.
822 \param [in] value Value to store
823 \param [in] ptr Pointer to location
825 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
827 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
832 \brief Store-Release (32 bit)
833 \details Executes a STL instruction for 32 bit values.
834 \param [in] value Value to store
835 \param [in] ptr Pointer to location
837 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
839 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
844 \brief Load-Acquire Exclusive (8 bit)
845 \details Executes a LDAB exclusive instruction for 8 bit value.
846 \param [in] ptr Pointer to data
847 \return value of type uint8_t at (*ptr)
849 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
853 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
854 return ((uint8_t) result);
859 \brief Load-Acquire Exclusive (16 bit)
860 \details Executes a LDAH exclusive instruction for 16 bit values.
861 \param [in] ptr Pointer to data
862 \return value of type uint16_t at (*ptr)
864 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
868 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
869 return ((uint16_t) result);
874 \brief Load-Acquire Exclusive (32 bit)
875 \details Executes a LDA exclusive instruction for 32 bit values.
876 \param [in] ptr Pointer to data
877 \return value of type uint32_t at (*ptr)
879 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
883 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
889 \brief Store-Release Exclusive (8 bit)
890 \details Executes a STLB exclusive instruction for 8 bit values.
891 \param [in] value Value to store
892 \param [in] ptr Pointer to location
893 \return 0 Function succeeded
894 \return 1 Function failed
896 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
900 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
906 \brief Store-Release Exclusive (16 bit)
907 \details Executes a STLH exclusive instruction for 16 bit values.
908 \param [in] value Value to store
909 \param [in] ptr Pointer to location
910 \return 0 Function succeeded
911 \return 1 Function failed
913 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
917 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
923 \brief Store-Release Exclusive (32 bit)
924 \details Executes a STL exclusive instruction for 32 bit values.
925 \param [in] value Value to store
926 \param [in] ptr Pointer to location
927 \return 0 Function succeeded
928 \return 1 Function failed
930 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
934 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
938 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
939 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
941 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
944 /* ########################### Core Function Access ########################### */
945 /** \ingroup CMSIS_Core_FunctionInterface
946 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
951 \brief Enable IRQ Interrupts
952 \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
953 Can only be executed in Privileged modes.
955 __STATIC_FORCEINLINE void __enable_irq(void)
957 __ASM volatile ("cpsie i" : : : "memory");
962 \brief Disable IRQ Interrupts
963 \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
964 Can only be executed in Privileged modes.
966 __STATIC_FORCEINLINE void __disable_irq(void)
968 __ASM volatile ("cpsid i" : : : "memory");
973 \brief Get Control Register
974 \details Returns the content of the Control Register.
975 \return Control Register value
977 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
981 __ASM volatile ("MRS %0, control" : "=r" (result) );
986 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
988 \brief Get Control Register (non-secure)
989 \details Returns the content of the non-secure Control Register when in secure mode.
990 \return non-secure Control Register value
992 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
996 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
1003 \brief Set Control Register
1004 \details Writes the given value to the Control Register.
1005 \param [in] control Control Register value to set
1007 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
1009 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
1014 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1016 \brief Set Control Register (non-secure)
1017 \details Writes the given value to the non-secure Control Register when in secure state.
1018 \param [in] control Control Register value to set
1020 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
1022 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
1029 \brief Get IPSR Register
1030 \details Returns the content of the IPSR Register.
1031 \return IPSR Register value
1033 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
1037 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
1043 \brief Get APSR Register
1044 \details Returns the content of the APSR Register.
1045 \return APSR Register value
1047 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
1051 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
1057 \brief Get xPSR Register
1058 \details Returns the content of the xPSR Register.
1059 \return xPSR Register value
1061 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
1065 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
1071 \brief Get Process Stack Pointer
1072 \details Returns the current value of the Process Stack Pointer (PSP).
1073 \return PSP Register value
1075 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
1079 __ASM volatile ("MRS %0, psp" : "=r" (result) );
1084 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1086 \brief Get Process Stack Pointer (non-secure)
1087 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
1088 \return PSP Register value
1090 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
1094 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
1101 \brief Set Process Stack Pointer
1102 \details Assigns the given value to the Process Stack Pointer (PSP).
1103 \param [in] topOfProcStack Process Stack Pointer value to set
1105 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
1107 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
1111 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1113 \brief Set Process Stack Pointer (non-secure)
1114 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
1115 \param [in] topOfProcStack Process Stack Pointer value to set
1117 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
1119 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
1125 \brief Get Main Stack Pointer
1126 \details Returns the current value of the Main Stack Pointer (MSP).
1127 \return MSP Register value
1129 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
1133 __ASM volatile ("MRS %0, msp" : "=r" (result) );
1138 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1140 \brief Get Main Stack Pointer (non-secure)
1141 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
1142 \return MSP Register value
1144 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
1148 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
1155 \brief Set Main Stack Pointer
1156 \details Assigns the given value to the Main Stack Pointer (MSP).
1157 \param [in] topOfMainStack Main Stack Pointer value to set
1159 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
1161 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
1165 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1167 \brief Set Main Stack Pointer (non-secure)
1168 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
1169 \param [in] topOfMainStack Main Stack Pointer value to set
1171 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
1173 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
1178 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1180 \brief Get Stack Pointer (non-secure)
1181 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
1182 \return SP Register value
1184 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
1188 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
1194 \brief Set Stack Pointer (non-secure)
1195 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
1196 \param [in] topOfStack Stack Pointer value to set
1198 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
1200 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
1206 \brief Get Priority Mask
1207 \details Returns the current state of the priority mask bit from the Priority Mask Register.
1208 \return Priority Mask value
1210 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
1214 __ASM volatile ("MRS %0, primask" : "=r" (result) );
1219 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1221 \brief Get Priority Mask (non-secure)
1222 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
1223 \return Priority Mask value
1225 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
1229 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
1236 \brief Set Priority Mask
1237 \details Assigns the given value to the Priority Mask Register.
1238 \param [in] priMask Priority Mask
1240 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
1242 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
1246 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1248 \brief Set Priority Mask (non-secure)
1249 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
1250 \param [in] priMask Priority Mask
1252 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
1254 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
1259 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1260 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1261 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1264 \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
1265 Can only be executed in Privileged modes.
1267 __STATIC_FORCEINLINE void __enable_fault_irq(void)
1269 __ASM volatile ("cpsie f" : : : "memory");
1275 \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
1276 Can only be executed in Privileged modes.
1278 __STATIC_FORCEINLINE void __disable_fault_irq(void)
1280 __ASM volatile ("cpsid f" : : : "memory");
1285 \brief Get Base Priority
1286 \details Returns the current value of the Base Priority register.
1287 \return Base Priority register value
1289 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
1293 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
1298 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1300 \brief Get Base Priority (non-secure)
1301 \details Returns the current value of the non-secure Base Priority register when in secure state.
1302 \return Base Priority register value
1304 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
1308 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
1315 \brief Set Base Priority
1316 \details Assigns the given value to the Base Priority register.
1317 \param [in] basePri Base Priority value to set
1319 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
1321 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
1325 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1327 \brief Set Base Priority (non-secure)
1328 \details Assigns the given value to the non-secure Base Priority register when in secure state.
1329 \param [in] basePri Base Priority value to set
1331 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
1333 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
1339 \brief Set Base Priority with condition
1340 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
1341 or the new value increases the BASEPRI priority level.
1342 \param [in] basePri Base Priority value to set
1344 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
1346 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
1351 \brief Get Fault Mask
1352 \details Returns the current value of the Fault Mask register.
1353 \return Fault Mask register value
1355 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
1359 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
1364 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1366 \brief Get Fault Mask (non-secure)
1367 \details Returns the current value of the non-secure Fault Mask register when in secure state.
1368 \return Fault Mask register value
1370 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
1374 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
1381 \brief Set Fault Mask
1382 \details Assigns the given value to the Fault Mask register.
1383 \param [in] faultMask Fault Mask value to set
1385 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
1387 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
1391 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1393 \brief Set Fault Mask (non-secure)
1394 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
1395 \param [in] faultMask Fault Mask value to set
1397 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
1399 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
1403 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1404 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1405 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1408 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1409 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1412 \brief Get Process Stack Pointer Limit
1413 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1414 Stack Pointer Limit register hence zero is returned always in non-secure
1417 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
1418 \return PSPLIM Register value
1420 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
1422 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1423 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1424 // without main extensions, the non-secure PSPLIM is RAZ/WI
1428 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
1433 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
1435 \brief Get Process Stack Pointer Limit (non-secure)
1436 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1437 Stack Pointer Limit register hence zero is returned always.
1439 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1440 \return PSPLIM Register value
1442 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
1444 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1445 // without main extensions, the non-secure PSPLIM is RAZ/WI
1449 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
1457 \brief Set Process Stack Pointer Limit
1458 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1459 Stack Pointer Limit register hence the write is silently ignored in non-secure
1462 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
1463 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1465 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
1467 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1468 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1469 // without main extensions, the non-secure PSPLIM is RAZ/WI
1470 (void)ProcStackPtrLimit;
1472 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
1477 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1479 \brief Set Process Stack Pointer (non-secure)
1480 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1481 Stack Pointer Limit register hence the write is silently ignored.
1483 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1484 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1486 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
1488 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1489 // without main extensions, the non-secure PSPLIM is RAZ/WI
1490 (void)ProcStackPtrLimit;
1492 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
1499 \brief Get Main Stack Pointer Limit
1500 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1501 Stack Pointer Limit register hence zero is returned always in non-secure
1504 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
1505 \return MSPLIM Register value
1507 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
1509 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1510 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1511 // without main extensions, the non-secure MSPLIM is RAZ/WI
1515 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
1521 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1523 \brief Get Main Stack Pointer Limit (non-secure)
1524 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1525 Stack Pointer Limit register hence zero is returned always.
1527 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
1528 \return MSPLIM Register value
1530 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
1532 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1533 // without main extensions, the non-secure MSPLIM is RAZ/WI
1537 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
1545 \brief Set Main Stack Pointer Limit
1546 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1547 Stack Pointer Limit register hence the write is silently ignored in non-secure
1550 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
1551 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
1553 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
1555 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1556 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1557 // without main extensions, the non-secure MSPLIM is RAZ/WI
1558 (void)MainStackPtrLimit;
1560 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
1565 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1567 \brief Set Main Stack Pointer Limit (non-secure)
1568 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1569 Stack Pointer Limit register hence the write is silently ignored.
1571 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
1572 \param [in] MainStackPtrLimit Main Stack Pointer value to set
1574 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
1576 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1577 // without main extensions, the non-secure MSPLIM is RAZ/WI
1578 (void)MainStackPtrLimit;
1580 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
1585 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1586 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1591 \details Returns the current value of the Floating Point Status/Control register.
1592 \return Floating Point Status/Control register value
1594 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
1596 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1597 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
1598 #if __has_builtin(__builtin_arm_get_fpscr)
1599 // Re-enable using built-in when GCC has been fixed
1600 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
1601 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
1602 return __builtin_arm_get_fpscr();
1606 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
1617 \details Assigns the given value to the Floating Point Status/Control register.
1618 \param [in] fpscr Floating Point Status/Control value to set
1620 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
1622 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1623 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
1624 #if __has_builtin(__builtin_arm_set_fpscr)
1625 // Re-enable using built-in when GCC has been fixed
1626 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
1627 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
1628 __builtin_arm_set_fpscr(fpscr);
1630 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
1638 /*@} end of CMSIS_Core_RegAccFunctions */
1641 /* ################### Compiler specific Intrinsics ########################### */
1642 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1643 Access to dedicated SIMD instructions
1647 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1649 __STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1653 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1657 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1661 __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1665 __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1669 __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1673 __STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1677 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1681 __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1685 __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1689 __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1693 __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1698 __STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1702 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1706 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1710 __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1714 __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1718 __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1722 __STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1726 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1730 __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1734 __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1738 __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1742 __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1747 __STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1751 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1755 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1759 __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1763 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1767 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1771 __STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1775 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1779 __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1783 __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1787 __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1791 __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1795 __STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1799 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1803 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1807 __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1811 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1815 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1819 __STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1823 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1827 __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1831 __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1835 __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1839 __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1843 __STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1847 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1851 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1855 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1859 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1863 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1867 __STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1871 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1875 __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1879 __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1883 __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1887 __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1891 __STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1895 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1899 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1903 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1907 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1911 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1915 __STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1919 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1923 __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1927 __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1931 __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1935 __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1939 __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1943 __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1947 __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1951 __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1955 #define __SSAT16(ARG1, ARG2) \
1958 int32_t __RES, __ARG1 = (ARG1); \
1959 __ASM volatile ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1963 #define __USAT16(ARG1, ARG2) \
1966 uint32_t __RES, __ARG1 = (ARG1); \
1967 __ASM volatile ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1971 __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
1975 __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1979 __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1983 __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1987 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
1991 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1995 __STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate)
1998 if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
1999 __ASM volatile ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) );
2001 result = __SXTB16(__ROR(op1, rotate)) ;
2006 __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
2010 __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2014 __STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate)
2017 if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
2018 __ASM volatile ("sxtab16 %0, %1, %2, ROR %3" : "=r" (result) : "r" (op1) , "r" (op2) , "i" (rotate));
2020 result = __SXTAB16(op1, __ROR(op2, rotate));
2026 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
2030 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2034 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
2038 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2042 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
2046 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2050 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
2054 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2058 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
2066 #ifndef __ARMEB__ /* Little endian */
2067 __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]) );
2068 #else /* Big endian */
2069 __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]) );
2075 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
2083 #ifndef __ARMEB__ /* Little endian */
2084 __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]) );
2085 #else /* Big endian */
2086 __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]) );
2092 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
2096 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2100 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
2104 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2108 __STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
2112 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2116 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
2120 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2124 __STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
2132 #ifndef __ARMEB__ /* Little endian */
2133 __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]) );
2134 #else /* Big endian */
2135 __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]) );
2141 __STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
2149 #ifndef __ARMEB__ /* Little endian */
2150 __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]) );
2151 #else /* Big endian */
2152 __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]) );
2158 __STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
2162 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2166 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
2170 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2174 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
2178 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2183 #define __PKHBT(ARG1,ARG2,ARG3) \
2186 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2187 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2191 #define __PKHTB(ARG1,ARG2,ARG3) \
2194 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2196 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
2198 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2203 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
2207 __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
2211 #endif /* (__ARM_FEATURE_DSP == 1) */
2212 /*@} end of group CMSIS_SIMD_intrinsics */
2215 #pragma GCC diagnostic pop
2217 #endif /* __CMSIS_GCC_H */