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 /* ######################### Startup and Lowlevel Init ######################## */
122 #ifndef __PROGRAM_START
125 \brief Initializes data and bss sections
126 \details This default implementations initialized all data and additional bss
127 sections relying on .copy.table and .zero.table specified properly
128 in the used linker script.
131 __STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void)
133 extern void _start(void) __NO_RETURN;
135 typedef struct __copy_table {
141 typedef struct __zero_table {
146 extern const __copy_table_t __copy_table_start__;
147 extern const __copy_table_t __copy_table_end__;
148 extern const __zero_table_t __zero_table_start__;
149 extern const __zero_table_t __zero_table_end__;
151 for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) {
152 for(uint32_t i=0u; i<pTable->wlen; ++i) {
153 pTable->dest[i] = pTable->src[i];
157 for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) {
158 for(uint32_t i=0u; i<pTable->wlen; ++i) {
159 pTable->dest[i] = 0u;
166 #define __PROGRAM_START __cmsis_start
170 #define __INITIAL_SP __StackTop
173 #ifndef __STACK_LIMIT
174 #define __STACK_LIMIT __StackLimit
177 #ifndef __VECTOR_TABLE
178 #define __VECTOR_TABLE __Vectors
181 #ifndef __VECTOR_TABLE_ATTRIBUTE
182 #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section(".vectors")))
185 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
187 #define __STACK_SEAL __StackSeal
190 #ifndef __TZ_STACK_SEAL_SIZE
191 #define __TZ_STACK_SEAL_SIZE 8U
194 #ifndef __TZ_STACK_SEAL_VALUE
195 #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL
199 __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
200 *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE;
205 /* ########################## Core Instruction Access ######################### */
206 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
207 Access to dedicated instructions
211 /* Define macros for porting to both thumb1 and thumb2.
212 * For thumb1, use low register (r0-r7), specified by constraint "l"
213 * Otherwise, use general registers, specified by constraint "r" */
214 #if defined (__thumb__) && !defined (__thumb2__)
215 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
216 #define __CMSIS_GCC_RW_REG(r) "+l" (r)
217 #define __CMSIS_GCC_USE_REG(r) "l" (r)
219 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
220 #define __CMSIS_GCC_RW_REG(r) "+r" (r)
221 #define __CMSIS_GCC_USE_REG(r) "r" (r)
226 \details No Operation does nothing. This instruction can be used for code alignment purposes.
228 #define __NOP() __ASM volatile ("nop")
231 \brief Wait For Interrupt
232 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
234 #define __WFI() __ASM volatile ("wfi":::"memory")
238 \brief Wait For Event
239 \details Wait For Event is a hint instruction that permits the processor to enter
240 a low-power state until one of a number of events occurs.
242 #define __WFE() __ASM volatile ("wfe":::"memory")
247 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
249 #define __SEV() __ASM volatile ("sev")
253 \brief Instruction Synchronization Barrier
254 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
255 so that all instructions following the ISB are fetched from cache or memory,
256 after the instruction has been completed.
258 __STATIC_FORCEINLINE void __ISB(void)
260 __ASM volatile ("isb 0xF":::"memory");
265 \brief Data Synchronization Barrier
266 \details Acts as a special kind of Data Memory Barrier.
267 It completes when all explicit memory accesses before this instruction complete.
269 __STATIC_FORCEINLINE void __DSB(void)
271 __ASM volatile ("dsb 0xF":::"memory");
276 \brief Data Memory Barrier
277 \details Ensures the apparent order of the explicit memory operations before
278 and after the instruction, without ensuring their completion.
280 __STATIC_FORCEINLINE void __DMB(void)
282 __ASM volatile ("dmb 0xF":::"memory");
287 \brief Reverse byte order (32 bit)
288 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
289 \param [in] value Value to reverse
290 \return Reversed value
292 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
294 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
295 return __builtin_bswap32(value);
299 __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
306 \brief Reverse byte order (16 bit)
307 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
308 \param [in] value Value to reverse
309 \return Reversed value
311 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
315 __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
321 \brief Reverse byte order (16 bit)
322 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
323 \param [in] value Value to reverse
324 \return Reversed value
326 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
328 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
329 return (int16_t)__builtin_bswap16(value);
333 __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
340 \brief Rotate Right in unsigned value (32 bit)
341 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
342 \param [in] op1 Value to rotate
343 \param [in] op2 Number of Bits to rotate
344 \return Rotated value
346 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
353 return (op1 >> op2) | (op1 << (32U - op2));
359 \details Causes the processor to enter Debug state.
360 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
361 \param [in] value is ignored by the processor.
362 If required, a debugger can use it to store additional information about the breakpoint.
364 #define __BKPT(value) __ASM volatile ("bkpt "#value)
368 \brief Reverse bit order of value
369 \details Reverses the bit order of the given value.
370 \param [in] value Value to reverse
371 \return Reversed value
373 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
377 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
378 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
379 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
380 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
382 uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
384 result = value; /* r will be reversed bits of v; first get LSB of v */
385 for (value >>= 1U; value != 0U; value >>= 1U)
388 result |= value & 1U;
391 result <<= s; /* shift when v's highest bits are zero */
398 \brief Count leading zeros
399 \details Counts the number of leading zeros of a data value.
400 \param [in] value Value to count the leading zeros
401 \return number of leading zeros in value
403 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
405 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
406 __builtin_clz(0) is undefined behaviour, so handle this case specially.
407 This guarantees ARM-compatible results if happening to compile on a non-ARM
408 target, and ensures the compiler doesn't decide to activate any
409 optimisations using the logic "value was passed to __builtin_clz, so it
411 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
412 single CLZ instruction.
418 return __builtin_clz(value);
422 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
423 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
424 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
425 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
427 \brief LDR Exclusive (8 bit)
428 \details Executes a exclusive LDR instruction for 8 bit value.
429 \param [in] ptr Pointer to data
430 \return value of type uint8_t at (*ptr)
432 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
436 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
437 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
439 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
440 accepted by assembler. So has to use following less efficient pattern.
442 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
444 return ((uint8_t) result); /* Add explicit type cast here */
449 \brief LDR Exclusive (16 bit)
450 \details Executes a exclusive LDR instruction for 16 bit values.
451 \param [in] ptr Pointer to data
452 \return value of type uint16_t at (*ptr)
454 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
458 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
459 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
461 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
462 accepted by assembler. So has to use following less efficient pattern.
464 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
466 return ((uint16_t) result); /* Add explicit type cast here */
471 \brief LDR Exclusive (32 bit)
472 \details Executes a exclusive LDR instruction for 32 bit values.
473 \param [in] ptr Pointer to data
474 \return value of type uint32_t at (*ptr)
476 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
480 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
486 \brief STR Exclusive (8 bit)
487 \details Executes a exclusive STR instruction for 8 bit values.
488 \param [in] value Value to store
489 \param [in] ptr Pointer to location
490 \return 0 Function succeeded
491 \return 1 Function failed
493 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
497 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
503 \brief STR Exclusive (16 bit)
504 \details Executes a exclusive STR instruction for 16 bit values.
505 \param [in] value Value to store
506 \param [in] ptr Pointer to location
507 \return 0 Function succeeded
508 \return 1 Function failed
510 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
514 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
520 \brief STR Exclusive (32 bit)
521 \details Executes a exclusive STR instruction for 32 bit values.
522 \param [in] value Value to store
523 \param [in] ptr Pointer to location
524 \return 0 Function succeeded
525 \return 1 Function failed
527 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
531 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
537 \brief Remove the exclusive lock
538 \details Removes the exclusive lock which is created by LDREX.
540 __STATIC_FORCEINLINE void __CLREX(void)
542 __ASM volatile ("clrex" ::: "memory");
545 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
546 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
547 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
548 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
551 #if ((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)) )
555 \brief Signed Saturate
556 \details Saturates a signed value.
557 \param [in] ARG1 Value to be saturated
558 \param [in] ARG2 Bit position to saturate to (1..32)
559 \return Saturated value
561 #define __SSAT(ARG1, ARG2) \
564 int32_t __RES, __ARG1 = (ARG1); \
565 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
571 \brief Unsigned Saturate
572 \details Saturates an unsigned value.
573 \param [in] ARG1 Value to be saturated
574 \param [in] ARG2 Bit position to saturate to (0..31)
575 \return Saturated value
577 #define __USAT(ARG1, ARG2) \
580 uint32_t __RES, __ARG1 = (ARG1); \
581 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
587 \brief Rotate Right with Extend (32 bit)
588 \details Moves each bit of a bitstring right by one bit.
589 The carry input is shifted in at the left end of the bitstring.
590 \param [in] value Value to rotate
591 \return Rotated value
593 __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value)
597 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
603 \brief LDRT Unprivileged (8 bit)
604 \details Executes a Unprivileged LDRT instruction for 8 bit value.
605 \param [in] ptr Pointer to data
606 \return value of type uint8_t at (*ptr)
608 __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr)
612 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
613 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
615 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
616 accepted by assembler. So has to use following less efficient pattern.
618 __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
620 return ((uint8_t) result); /* Add explicit type cast here */
625 \brief LDRT Unprivileged (16 bit)
626 \details Executes a Unprivileged LDRT instruction for 16 bit values.
627 \param [in] ptr Pointer to data
628 \return value of type uint16_t at (*ptr)
630 __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr)
634 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
635 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
637 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
638 accepted by assembler. So has to use following less efficient pattern.
640 __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" );
642 return ((uint16_t) result); /* Add explicit type cast here */
647 \brief LDRT Unprivileged (32 bit)
648 \details Executes a Unprivileged LDRT instruction for 32 bit values.
649 \param [in] ptr Pointer to data
650 \return value of type uint32_t at (*ptr)
652 __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr)
656 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
662 \brief STRT Unprivileged (8 bit)
663 \details Executes a Unprivileged STRT instruction for 8 bit values.
664 \param [in] value Value to store
665 \param [in] ptr Pointer to location
667 __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
669 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
674 \brief STRT Unprivileged (16 bit)
675 \details Executes a Unprivileged STRT instruction for 16 bit values.
676 \param [in] value Value to store
677 \param [in] ptr Pointer to location
679 __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
681 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
686 \brief STRT Unprivileged (32 bit)
687 \details Executes a Unprivileged STRT instruction for 32 bit values.
688 \param [in] value Value to store
689 \param [in] ptr Pointer to location
691 __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
693 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
696 #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
697 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
698 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
701 \brief Signed Saturate
702 \details Saturates a signed value.
703 \param [in] value Value to be saturated
704 \param [in] sat Bit position to saturate to (1..32)
705 \return Saturated value
707 __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
709 if ((sat >= 1U) && (sat <= 32U))
711 const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
712 const int32_t min = -1 - max ;
726 \brief Unsigned Saturate
727 \details Saturates an unsigned value.
728 \param [in] value Value to be saturated
729 \param [in] sat Bit position to saturate to (0..31)
730 \return Saturated value
732 __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
736 const uint32_t max = ((1U << sat) - 1U);
737 if (val > (int32_t)max)
746 return (uint32_t)val;
749 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
750 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
751 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
754 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
755 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
757 \brief Load-Acquire (8 bit)
758 \details Executes a LDAB instruction for 8 bit value.
759 \param [in] ptr Pointer to data
760 \return value of type uint8_t at (*ptr)
762 __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr)
766 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
767 return ((uint8_t) result);
772 \brief Load-Acquire (16 bit)
773 \details Executes a LDAH instruction for 16 bit values.
774 \param [in] ptr Pointer to data
775 \return value of type uint16_t at (*ptr)
777 __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr)
781 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
782 return ((uint16_t) result);
787 \brief Load-Acquire (32 bit)
788 \details Executes a LDA instruction for 32 bit values.
789 \param [in] ptr Pointer to data
790 \return value of type uint32_t at (*ptr)
792 __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr)
796 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
802 \brief Store-Release (8 bit)
803 \details Executes a STLB instruction for 8 bit values.
804 \param [in] value Value to store
805 \param [in] ptr Pointer to location
807 __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
809 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
814 \brief Store-Release (16 bit)
815 \details Executes a STLH instruction for 16 bit values.
816 \param [in] value Value to store
817 \param [in] ptr Pointer to location
819 __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
821 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
826 \brief Store-Release (32 bit)
827 \details Executes a STL instruction for 32 bit values.
828 \param [in] value Value to store
829 \param [in] ptr Pointer to location
831 __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr)
833 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
838 \brief Load-Acquire Exclusive (8 bit)
839 \details Executes a LDAB exclusive instruction for 8 bit value.
840 \param [in] ptr Pointer to data
841 \return value of type uint8_t at (*ptr)
843 __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr)
847 __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
848 return ((uint8_t) result);
853 \brief Load-Acquire Exclusive (16 bit)
854 \details Executes a LDAH exclusive instruction for 16 bit values.
855 \param [in] ptr Pointer to data
856 \return value of type uint16_t at (*ptr)
858 __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr)
862 __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
863 return ((uint16_t) result);
868 \brief Load-Acquire Exclusive (32 bit)
869 \details Executes a LDA exclusive instruction for 32 bit values.
870 \param [in] ptr Pointer to data
871 \return value of type uint32_t at (*ptr)
873 __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr)
877 __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" );
883 \brief Store-Release Exclusive (8 bit)
884 \details Executes a STLB exclusive instruction for 8 bit values.
885 \param [in] value Value to store
886 \param [in] ptr Pointer to location
887 \return 0 Function succeeded
888 \return 1 Function failed
890 __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
894 __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
900 \brief Store-Release Exclusive (16 bit)
901 \details Executes a STLH exclusive instruction for 16 bit values.
902 \param [in] value Value to store
903 \param [in] ptr Pointer to location
904 \return 0 Function succeeded
905 \return 1 Function failed
907 __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
911 __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
917 \brief Store-Release Exclusive (32 bit)
918 \details Executes a STL exclusive instruction for 32 bit values.
919 \param [in] value Value to store
920 \param [in] ptr Pointer to location
921 \return 0 Function succeeded
922 \return 1 Function failed
924 __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
928 __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" );
932 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
933 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
935 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
938 /* ########################### Core Function Access ########################### */
939 /** \ingroup CMSIS_Core_FunctionInterface
940 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
945 \brief Enable IRQ Interrupts
946 \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
947 Can only be executed in Privileged modes.
949 __STATIC_FORCEINLINE void __enable_irq(void)
951 __ASM volatile ("cpsie i" : : : "memory");
956 \brief Disable IRQ Interrupts
957 \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
958 Can only be executed in Privileged modes.
960 __STATIC_FORCEINLINE void __disable_irq(void)
962 __ASM volatile ("cpsid i" : : : "memory");
967 \brief Get Control Register
968 \details Returns the content of the Control Register.
969 \return Control Register value
971 __STATIC_FORCEINLINE uint32_t __get_CONTROL(void)
975 __ASM volatile ("MRS %0, control" : "=r" (result) );
980 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
982 \brief Get Control Register (non-secure)
983 \details Returns the content of the non-secure Control Register when in secure mode.
984 \return non-secure Control Register value
986 __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void)
990 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
997 \brief Set Control Register
998 \details Writes the given value to the Control Register.
999 \param [in] control Control Register value to set
1001 __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control)
1003 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
1008 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1010 \brief Set Control Register (non-secure)
1011 \details Writes the given value to the non-secure Control Register when in secure state.
1012 \param [in] control Control Register value to set
1014 __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
1016 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
1023 \brief Get IPSR Register
1024 \details Returns the content of the IPSR Register.
1025 \return IPSR Register value
1027 __STATIC_FORCEINLINE uint32_t __get_IPSR(void)
1031 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
1037 \brief Get APSR Register
1038 \details Returns the content of the APSR Register.
1039 \return APSR Register value
1041 __STATIC_FORCEINLINE uint32_t __get_APSR(void)
1045 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
1051 \brief Get xPSR Register
1052 \details Returns the content of the xPSR Register.
1053 \return xPSR Register value
1055 __STATIC_FORCEINLINE uint32_t __get_xPSR(void)
1059 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
1065 \brief Get Process Stack Pointer
1066 \details Returns the current value of the Process Stack Pointer (PSP).
1067 \return PSP Register value
1069 __STATIC_FORCEINLINE uint32_t __get_PSP(void)
1073 __ASM volatile ("MRS %0, psp" : "=r" (result) );
1078 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1080 \brief Get Process Stack Pointer (non-secure)
1081 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
1082 \return PSP Register value
1084 __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void)
1088 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
1095 \brief Set Process Stack Pointer
1096 \details Assigns the given value to the Process Stack Pointer (PSP).
1097 \param [in] topOfProcStack Process Stack Pointer value to set
1099 __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack)
1101 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : );
1105 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1107 \brief Set Process Stack Pointer (non-secure)
1108 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
1109 \param [in] topOfProcStack Process Stack Pointer value to set
1111 __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
1113 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : );
1119 \brief Get Main Stack Pointer
1120 \details Returns the current value of the Main Stack Pointer (MSP).
1121 \return MSP Register value
1123 __STATIC_FORCEINLINE uint32_t __get_MSP(void)
1127 __ASM volatile ("MRS %0, msp" : "=r" (result) );
1132 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1134 \brief Get Main Stack Pointer (non-secure)
1135 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
1136 \return MSP Register value
1138 __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void)
1142 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
1149 \brief Set Main Stack Pointer
1150 \details Assigns the given value to the Main Stack Pointer (MSP).
1151 \param [in] topOfMainStack Main Stack Pointer value to set
1153 __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack)
1155 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : );
1159 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1161 \brief Set Main Stack Pointer (non-secure)
1162 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
1163 \param [in] topOfMainStack Main Stack Pointer value to set
1165 __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
1167 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : );
1172 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1174 \brief Get Stack Pointer (non-secure)
1175 \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state.
1176 \return SP Register value
1178 __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void)
1182 __ASM volatile ("MRS %0, sp_ns" : "=r" (result) );
1188 \brief Set Stack Pointer (non-secure)
1189 \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state.
1190 \param [in] topOfStack Stack Pointer value to set
1192 __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack)
1194 __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : );
1200 \brief Get Priority Mask
1201 \details Returns the current state of the priority mask bit from the Priority Mask Register.
1202 \return Priority Mask value
1204 __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void)
1208 __ASM volatile ("MRS %0, primask" : "=r" (result) );
1213 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1215 \brief Get Priority Mask (non-secure)
1216 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
1217 \return Priority Mask value
1219 __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void)
1223 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
1230 \brief Set Priority Mask
1231 \details Assigns the given value to the Priority Mask Register.
1232 \param [in] priMask Priority Mask
1234 __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask)
1236 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
1240 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1242 \brief Set Priority Mask (non-secure)
1243 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
1244 \param [in] priMask Priority Mask
1246 __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
1248 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
1253 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1254 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1255 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
1258 \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
1259 Can only be executed in Privileged modes.
1261 __STATIC_FORCEINLINE void __enable_fault_irq(void)
1263 __ASM volatile ("cpsie f" : : : "memory");
1269 \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
1270 Can only be executed in Privileged modes.
1272 __STATIC_FORCEINLINE void __disable_fault_irq(void)
1274 __ASM volatile ("cpsid f" : : : "memory");
1279 \brief Get Base Priority
1280 \details Returns the current value of the Base Priority register.
1281 \return Base Priority register value
1283 __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void)
1287 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
1292 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1294 \brief Get Base Priority (non-secure)
1295 \details Returns the current value of the non-secure Base Priority register when in secure state.
1296 \return Base Priority register value
1298 __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void)
1302 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
1309 \brief Set Base Priority
1310 \details Assigns the given value to the Base Priority register.
1311 \param [in] basePri Base Priority value to set
1313 __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri)
1315 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
1319 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1321 \brief Set Base Priority (non-secure)
1322 \details Assigns the given value to the non-secure Base Priority register when in secure state.
1323 \param [in] basePri Base Priority value to set
1325 __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
1327 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
1333 \brief Set Base Priority with condition
1334 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
1335 or the new value increases the BASEPRI priority level.
1336 \param [in] basePri Base Priority value to set
1338 __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri)
1340 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
1345 \brief Get Fault Mask
1346 \details Returns the current value of the Fault Mask register.
1347 \return Fault Mask register value
1349 __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void)
1353 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
1358 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1360 \brief Get Fault Mask (non-secure)
1361 \details Returns the current value of the non-secure Fault Mask register when in secure state.
1362 \return Fault Mask register value
1364 __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void)
1368 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
1375 \brief Set Fault Mask
1376 \details Assigns the given value to the Fault Mask register.
1377 \param [in] faultMask Fault Mask value to set
1379 __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask)
1381 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
1385 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1387 \brief Set Fault Mask (non-secure)
1388 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
1389 \param [in] faultMask Fault Mask value to set
1391 __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
1393 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
1397 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1398 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1399 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
1402 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1403 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1406 \brief Get Process Stack Pointer Limit
1407 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1408 Stack Pointer Limit register hence zero is returned always in non-secure
1411 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
1412 \return PSPLIM Register value
1414 __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void)
1416 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1417 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1418 // without main extensions, the non-secure PSPLIM is RAZ/WI
1422 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
1427 #if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3))
1429 \brief Get Process Stack Pointer Limit (non-secure)
1430 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1431 Stack Pointer Limit register hence zero is returned always.
1433 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1434 \return PSPLIM Register value
1436 __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void)
1438 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1439 // without main extensions, the non-secure PSPLIM is RAZ/WI
1443 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
1451 \brief Set Process Stack Pointer Limit
1452 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1453 Stack Pointer Limit register hence the write is silently ignored in non-secure
1456 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
1457 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1459 __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
1461 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1462 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1463 // without main extensions, the non-secure PSPLIM is RAZ/WI
1464 (void)ProcStackPtrLimit;
1466 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
1471 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1473 \brief Set Process Stack Pointer (non-secure)
1474 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1475 Stack Pointer Limit register hence the write is silently ignored.
1477 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
1478 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
1480 __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
1482 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1483 // without main extensions, the non-secure PSPLIM is RAZ/WI
1484 (void)ProcStackPtrLimit;
1486 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
1493 \brief Get Main Stack Pointer Limit
1494 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1495 Stack Pointer Limit register hence zero is returned always in non-secure
1498 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
1499 \return MSPLIM Register value
1501 __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void)
1503 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1504 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1505 // without main extensions, the non-secure MSPLIM is RAZ/WI
1509 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
1515 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1517 \brief Get Main Stack Pointer Limit (non-secure)
1518 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1519 Stack Pointer Limit register hence zero is returned always.
1521 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
1522 \return MSPLIM Register value
1524 __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void)
1526 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1527 // without main extensions, the non-secure MSPLIM is RAZ/WI
1531 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
1539 \brief Set Main Stack Pointer Limit
1540 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1541 Stack Pointer Limit register hence the write is silently ignored in non-secure
1544 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
1545 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
1547 __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
1549 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
1550 (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
1551 // without main extensions, the non-secure MSPLIM is RAZ/WI
1552 (void)MainStackPtrLimit;
1554 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
1559 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
1561 \brief Set Main Stack Pointer Limit (non-secure)
1562 Devices without ARMv8-M Main Extensions (i.e. Cortex-M23) lack the non-secure
1563 Stack Pointer Limit register hence the write is silently ignored.
1565 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
1566 \param [in] MainStackPtrLimit Main Stack Pointer value to set
1568 __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
1570 #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)))
1571 // without main extensions, the non-secure MSPLIM is RAZ/WI
1572 (void)MainStackPtrLimit;
1574 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
1579 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1580 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1585 \details Returns the current value of the Floating Point Status/Control register.
1586 \return Floating Point Status/Control register value
1588 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
1590 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1591 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
1592 #if __has_builtin(__builtin_arm_get_fpscr)
1593 // Re-enable using built-in when GCC has been fixed
1594 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
1595 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
1596 return __builtin_arm_get_fpscr();
1600 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
1611 \details Assigns the given value to the Floating Point Status/Control register.
1612 \param [in] fpscr Floating Point Status/Control value to set
1614 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
1616 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
1617 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
1618 #if __has_builtin(__builtin_arm_set_fpscr)
1619 // Re-enable using built-in when GCC has been fixed
1620 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
1621 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
1622 __builtin_arm_set_fpscr(fpscr);
1624 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
1632 /*@} end of CMSIS_Core_RegAccFunctions */
1635 /* ################### Compiler specific Intrinsics ########################### */
1636 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1637 Access to dedicated SIMD instructions
1641 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
1643 __STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1647 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1651 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1655 __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1659 __STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1663 __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1667 __STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1671 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1675 __STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1679 __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1683 __STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1687 __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1692 __STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1696 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1700 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1704 __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1708 __STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1712 __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1716 __STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1720 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1724 __STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1728 __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1732 __STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1736 __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1741 __STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1745 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1749 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1753 __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1757 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1761 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1765 __STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1769 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1773 __STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1777 __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1781 __STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1785 __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1789 __STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1793 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1797 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1801 __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1805 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1809 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1813 __STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1817 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1821 __STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1825 __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1829 __STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1833 __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1837 __STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1841 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1845 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1849 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1853 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1857 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1861 __STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1865 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1869 __STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1873 __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1877 __STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1881 __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1885 __STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1889 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1893 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1897 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1901 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1905 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1909 __STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1913 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1917 __STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1921 __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1925 __STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1929 __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1933 __STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1937 __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1941 __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1945 __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1949 #define __SSAT16(ARG1, ARG2) \
1952 int32_t __RES, __ARG1 = (ARG1); \
1953 __ASM volatile ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1957 #define __USAT16(ARG1, ARG2) \
1960 uint32_t __RES, __ARG1 = (ARG1); \
1961 __ASM volatile ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
1965 __STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1)
1969 __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1973 __STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1977 __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1981 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
1985 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1989 __STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate)
1992 if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
1993 __ASM volatile ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) );
1995 result = __SXTB16(__ROR(op1, rotate)) ;
2000 __STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
2004 __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2008 __STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate)
2011 if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) {
2012 __ASM volatile ("sxtab16 %0, %1, %2, ROR %3" : "=r" (result) : "r" (op1) , "r" (op2) , "i" (rotate));
2014 result = __SXTAB16(op1, __ROR(op2, rotate));
2020 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
2024 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2028 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
2032 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2036 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
2040 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2044 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
2048 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2052 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
2060 #ifndef __ARMEB__ /* Little endian */
2061 __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]) );
2062 #else /* Big endian */
2063 __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]) );
2069 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
2077 #ifndef __ARMEB__ /* Little endian */
2078 __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]) );
2079 #else /* Big endian */
2080 __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]) );
2086 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
2090 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2094 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
2098 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2102 __STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
2106 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2110 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
2114 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
2118 __STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
2126 #ifndef __ARMEB__ /* Little endian */
2127 __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]) );
2128 #else /* Big endian */
2129 __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]) );
2135 __STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
2143 #ifndef __ARMEB__ /* Little endian */
2144 __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]) );
2145 #else /* Big endian */
2146 __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]) );
2152 __STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
2156 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2160 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
2164 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2168 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
2172 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
2177 #define __PKHBT(ARG1,ARG2,ARG3) \
2180 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2181 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2185 #define __PKHTB(ARG1,ARG2,ARG3) \
2188 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
2190 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
2192 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
2197 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
2201 __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
2205 #endif /* (__ARM_FEATURE_DSP == 1) */
2206 /*@} end of group CMSIS_SIMD_intrinsics */
2209 #pragma GCC diagnostic pop
2211 #endif /* __CMSIS_GCC_H */