1 /**************************************************************************//**
3 * @brief CMSIS compiler GCC header file
5 * @date 13. November 2022
6 ******************************************************************************/
8 * Copyright (c) 2009-2022 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
47 #define __FORCEINLINE __attribute__((always_inline))
49 #ifndef __STATIC_INLINE
50 #define __STATIC_INLINE static inline
52 #ifndef __STATIC_FORCEINLINE
53 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
56 #define __NO_RETURN __attribute__((__noreturn__))
58 #ifndef CMSIS_DEPRECATED
59 #define CMSIS_DEPRECATED __attribute__((deprecated))
62 #define __USED __attribute__((used))
65 #define __WEAK __attribute__((weak))
68 #define __PACKED __attribute__((packed, aligned(1)))
70 #ifndef __PACKED_STRUCT
71 #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
73 #ifndef __UNALIGNED_UINT16_WRITE
74 #pragma GCC diagnostic push
75 #pragma GCC diagnostic ignored "-Wpacked"
76 #pragma GCC diagnostic ignored "-Wattributes"
77 __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
78 #pragma GCC diagnostic pop
79 #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
81 #ifndef __UNALIGNED_UINT16_READ
82 #pragma GCC diagnostic push
83 #pragma GCC diagnostic ignored "-Wpacked"
84 #pragma GCC diagnostic ignored "-Wattributes"
85 __PACKED_STRUCT T_UINT16_READ { uint16_t v; };
86 #pragma GCC diagnostic pop
87 #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
89 #ifndef __UNALIGNED_UINT32_WRITE
90 #pragma GCC diagnostic push
91 #pragma GCC diagnostic ignored "-Wpacked"
92 #pragma GCC diagnostic ignored "-Wattributes"
93 __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
94 #pragma GCC diagnostic pop
95 #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
97 #ifndef __UNALIGNED_UINT32_READ
98 #pragma GCC diagnostic push
99 #pragma GCC diagnostic ignored "-Wpacked"
100 #pragma GCC diagnostic ignored "-Wattributes"
101 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
102 #pragma GCC diagnostic pop
103 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
106 #define __ALIGNED(x) __attribute__((aligned(x)))
109 #define __RESTRICT __restrict
111 #ifndef __COMPILER_BARRIER
112 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
116 /* ########################## Core Instruction Access ######################### */
119 \details No Operation does nothing. This instruction can be used for code alignment purposes.
121 #define __NOP() __ASM volatile ("nop")
124 \brief Wait For Interrupt
125 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
127 #define __WFI() __ASM volatile ("wfi":::"memory")
131 \brief Wait For Event
132 \details Wait For Event is a hint instruction that permits the processor to enter
133 a low-power state until one of a number of events occurs.
135 #define __WFE() __ASM volatile ("wfe":::"memory")
140 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
142 #define __SEV() __ASM volatile ("sev")
146 \brief Instruction Synchronization Barrier
147 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
148 so that all instructions following the ISB are fetched from cache or memory,
149 after the instruction has been completed.
151 __STATIC_FORCEINLINE void __ISB(void)
153 __ASM volatile ("isb 0xF":::"memory");
158 \brief Data Synchronization Barrier
159 \details Acts as a special kind of Data Memory Barrier.
160 It completes when all explicit memory accesses before this instruction complete.
162 __STATIC_FORCEINLINE void __DSB(void)
164 __ASM volatile ("dsb 0xF":::"memory");
169 \brief Data Memory Barrier
170 \details Ensures the apparent order of the explicit memory operations before
171 and after the instruction, without ensuring their completion.
173 __STATIC_FORCEINLINE void __DMB(void)
175 __ASM volatile ("dmb 0xF":::"memory");
180 \brief Reverse byte order (32 bit)
181 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
182 \param [in] value Value to reverse
183 \return Reversed value
185 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
187 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
188 return __builtin_bswap32(value);
192 __ASM ("rev %0, %1" : "=r" (result) : "r" (value) );
199 \brief Reverse byte order (16 bit)
200 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
201 \param [in] value Value to reverse
202 \return Reversed value
204 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
207 __ASM ("rev16 %0, %1" : "=r" (result) : "r" (value));
213 \brief Reverse byte order (16 bit)
214 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
215 \param [in] value Value to reverse
216 \return Reversed value
218 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
220 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
221 return (int16_t)__builtin_bswap16(value);
225 __ASM ("revsh %0, %1" : "=r" (result) : "r" (value) );
232 \brief Rotate Right in unsigned value (32 bit)
233 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
234 \param [in] op1 Value to rotate
235 \param [in] op2 Number of Bits to rotate
236 \return Rotated value
238 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
245 return (op1 >> op2) | (op1 << (32U - op2));
251 \details Causes the processor to enter Debug state.
252 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
253 \param [in] value is ignored by the processor.
254 If required, a debugger can use it to store additional information about the breakpoint.
256 #define __BKPT(value) __ASM volatile ("bkpt "#value)
260 \brief Reverse bit order of value
261 \details Reverses the bit order of the given value.
262 \param [in] value Value to reverse
263 \return Reversed value
265 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
268 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
274 \brief Count leading zeros
275 \details Counts the number of leading zeros of a data value.
276 \param [in] value Value to count the leading zeros
277 \return number of leading zeros in value
279 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
281 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
282 __builtin_clz(0) is undefined behaviour, so handle this case specially.
283 This guarantees ARM-compatible results if happening to compile on a non-ARM
284 target, and ensures the compiler doesn't decide to activate any
285 optimisations using the logic "value was passed to __builtin_clz, so it
287 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
288 single CLZ instruction.
294 return __builtin_clz(value);
298 \brief LDR Exclusive (8 bit)
299 \details Executes a exclusive LDR instruction for 8 bit value.
300 \param [in] ptr Pointer to data
301 \return value of type uint8_t at (*ptr)
303 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
307 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
308 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
310 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
311 accepted by assembler. So has to use following less efficient pattern.
313 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
315 return ((uint8_t) result); /* Add explicit type cast here */
320 \brief LDR Exclusive (16 bit)
321 \details Executes a exclusive LDR instruction for 16 bit values.
322 \param [in] ptr Pointer to data
323 \return value of type uint16_t at (*ptr)
325 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
329 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
330 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
332 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
333 accepted by assembler. So has to use following less efficient pattern.
335 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
337 return ((uint16_t) result); /* Add explicit type cast here */
342 \brief LDR Exclusive (32 bit)
343 \details Executes a exclusive LDR instruction for 32 bit values.
344 \param [in] ptr Pointer to data
345 \return value of type uint32_t at (*ptr)
347 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
351 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
357 \brief STR Exclusive (8 bit)
358 \details Executes a exclusive STR instruction for 8 bit values.
359 \param [in] value Value to store
360 \param [in] ptr Pointer to location
361 \return 0 Function succeeded
362 \return 1 Function failed
364 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
368 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
374 \brief STR Exclusive (16 bit)
375 \details Executes a exclusive STR instruction for 16 bit values.
376 \param [in] value Value to store
377 \param [in] ptr Pointer to location
378 \return 0 Function succeeded
379 \return 1 Function failed
381 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
385 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
391 \brief STR Exclusive (32 bit)
392 \details Executes a exclusive STR instruction for 32 bit values.
393 \param [in] value Value to store
394 \param [in] ptr Pointer to location
395 \return 0 Function succeeded
396 \return 1 Function failed
398 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
402 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
408 \brief Remove the exclusive lock
409 \details Removes the exclusive lock which is created by LDREX.
411 __STATIC_FORCEINLINE void __CLREX(void)
413 __ASM volatile ("clrex" ::: "memory");
417 \brief Signed Saturate
418 \details Saturates a signed value.
419 \param [in] ARG1 Value to be saturated
420 \param [in] ARG2 Bit position to saturate to (1..32)
421 \return Saturated value
423 #define __SSAT(ARG1, ARG2) \
426 int32_t __RES, __ARG1 = (ARG1); \
427 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
433 \brief Unsigned Saturate
434 \details Saturates an unsigned value.
435 \param [in] ARG1 Value to be saturated
436 \param [in] ARG2 Bit position to saturate to (0..31)
437 \return Saturated value
439 #define __USAT(ARG1, ARG2) \
442 uint32_t __RES, __ARG1 = (ARG1); \
443 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
447 /* ########################### Core Function Access ########################### */
448 /** \ingroup CMSIS_Core_FunctionInterface
449 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
454 \brief Enable IRQ Interrupts
455 \details Enables IRQ interrupts by clearing special-purpose register PRIMASK.
456 Can only be executed in Privileged modes.
458 __STATIC_FORCEINLINE void __enable_irq(void)
460 __ASM volatile ("cpsie i" : : : "memory");
465 \brief Disable IRQ Interrupts
466 \details Disables IRQ interrupts by setting special-purpose register PRIMASK.
467 Can only be executed in Privileged modes.
469 __STATIC_FORCEINLINE void __disable_irq(void)
471 __ASM volatile ("cpsid i" : : : "memory");
476 \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK.
477 Can only be executed in Privileged modes.
479 __STATIC_FORCEINLINE void __enable_fault_irq(void)
481 __ASM volatile ("cpsie f" : : : "memory");
487 \details Disables FIQ interrupts by setting special-purpose register FAULTMASK.
488 Can only be executed in Privileged modes.
490 __STATIC_FORCEINLINE void __disable_fault_irq(void)
492 __ASM volatile ("cpsid f" : : : "memory");
497 \details Returns the current value of the Floating Point Status/Control register.
498 \return Floating Point Status/Control register value
500 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
502 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
503 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
504 #if __has_builtin(__builtin_arm_get_fpscr)
505 // Re-enable using built-in when GCC has been fixed
506 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
507 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
508 return __builtin_arm_get_fpscr();
512 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
523 \details Assigns the given value to the Floating Point Status/Control register.
524 \param [in] fpscr Floating Point Status/Control value to set
526 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
528 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
529 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
530 #if __has_builtin(__builtin_arm_set_fpscr)
531 // Re-enable using built-in when GCC has been fixed
532 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
533 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
534 __builtin_arm_set_fpscr(fpscr);
536 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
544 /*@} end of CMSIS_Core_RegAccFunctions */
547 /* ################### Compiler specific Intrinsics ########################### */
548 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
549 Access to dedicated SIMD instructions
553 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
557 __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
562 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
566 __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
571 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
575 __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
579 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
583 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
587 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
591 __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
595 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
599 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
603 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
607 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
611 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
615 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
619 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
623 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
627 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
631 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
635 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
639 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
643 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
647 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
651 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
655 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
659 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
667 #ifndef __ARMEB__ /* Little endian */
668 __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]) );
669 #else /* Big endian */
670 __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]) );
676 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
684 #ifndef __ARMEB__ /* Little endian */
685 __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]) );
686 #else /* Big endian */
687 __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]) );
693 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
697 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
701 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
705 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
709 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
713 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
717 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
721 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
725 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
729 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
734 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
738 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
744 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
745 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
747 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
748 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
750 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
754 __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
758 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
762 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
766 /*@} end of group CMSIS_SIMD_intrinsics */
770 /** \defgroup CMSIS_Core_intrinsics CMSIS Core Intrinsics
771 Access to dedicated SIMD instructions
775 /** \brief Get CPSR Register
776 \return CPSR Register value
778 __STATIC_FORCEINLINE uint32_t __get_CPSR(void)
781 __ASM volatile("MRS %0, cpsr" : "=r" (result) );
785 /** \brief Set CPSR Register
786 \param [in] cpsr CPSR value to set
788 __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr)
790 __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory");
794 \return Processor Mode
796 __STATIC_FORCEINLINE uint32_t __get_mode(void)
798 return (__get_CPSR() & 0x1FU);
802 \param [in] mode Mode value to set
804 __STATIC_FORCEINLINE void __set_mode(uint32_t mode)
806 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
809 /** \brief Get Stack Pointer
810 \return Stack Pointer value
812 __STATIC_FORCEINLINE uint32_t __get_SP(void)
815 __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory");
819 /** \brief Set Stack Pointer
820 \param [in] stack Stack Pointer value to set
822 __STATIC_FORCEINLINE void __set_SP(uint32_t stack)
824 __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory");
827 /** \brief Get USR/SYS Stack Pointer
828 \return USR/SYS Stack Pointer value
830 __STATIC_FORCEINLINE uint32_t __get_SP_usr(void)
832 uint32_t cpsr = __get_CPSR();
836 "MOV %0, sp " : "=r"(result) : : "memory"
843 /** \brief Set USR/SYS Stack Pointer
844 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
846 __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack)
848 uint32_t cpsr = __get_CPSR();
851 "MOV sp, %0 " : : "r" (topOfProcStack) : "memory"
858 \return Floating Point Exception Control register value
860 __STATIC_FORCEINLINE uint32_t __get_FPEXC(void)
862 #if (__FPU_PRESENT == 1)
864 __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
872 \param [in] fpexc Floating Point Exception Control value to set
874 __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc)
876 #if (__FPU_PRESENT == 1)
877 __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
882 * Include common core functions to access Coprocessor 15 registers
885 #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
886 #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
887 #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
888 #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
890 #include "cmsis_cp15.h"
892 /** \brief Enable Floating Point Unit
894 Critical section, called from undef handler, so systick is disabled
896 __STATIC_INLINE void __FPU_Enable(void)
898 // Permit access to VFP/NEON, registers by modifying CPACR
899 const uint32_t cpacr = __get_CPACR();
900 __set_CPACR(cpacr | 0x00F00000ul);
904 const uint32_t fpexc = __get_FPEXC();
905 __set_FPEXC(fpexc | 0x40000000ul);
908 // Initialise VFP/NEON registers to 0
911 // Initialise D16 registers to 0
929 #if (defined(__ARM_NEON) && (__ARM_NEON == 1))
930 // Initialise D32 registers to 0
951 // Initialise FPSCR to a known state
952 const uint32_t fpscr = __get_FPSCR();
953 __set_FPSCR(fpscr & 0x00086060ul);
956 /*@} end of group CMSIS_Core_intrinsics */
958 #pragma GCC diagnostic pop
960 #endif /* __CMSIS_GCC_H */