1 /**************************************************************************//**
3 * @brief CMSIS compiler specific macros, functions, instructions
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 /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */
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 /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */
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 /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */
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 __PACKED_STRUCT T_UINT32_READ { uint32_t v; };
101 #pragma GCC diagnostic pop
102 #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
105 #define __ALIGNED(x) __attribute__((aligned(x)))
107 #ifndef __COMPILER_BARRIER
108 #define __COMPILER_BARRIER() __ASM volatile("":::"memory")
112 __STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
116 __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
121 __STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
125 __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
130 __STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
134 __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
138 __STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
142 __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
146 __STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2)
150 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
154 __STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
158 __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
162 __STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
166 __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
170 __STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
178 #ifndef __ARMEB__ /* Little endian */
179 __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]) );
180 #else /* Big endian */
181 __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]) );
187 __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2)
191 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
195 __STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1)
199 __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
204 __STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
208 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
214 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
215 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
217 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
218 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
220 __STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
224 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
228 __STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
232 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
236 __STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
240 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
244 __STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
252 #ifndef __ARMEB__ /* Little endian */
253 __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]) );
254 #else /* Big endian */
255 __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]) );
261 __STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
265 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
269 __STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
273 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
277 __STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
281 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
285 __STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
289 __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
293 __STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
297 __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
301 __STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
305 __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
309 __STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
313 __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
317 __STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
321 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
326 /* ########################## Core Instruction Access ######################### */
330 #define __NOP() __ASM volatile ("nop")
333 \brief Wait For Interrupt
335 #define __WFI() __ASM volatile ("wfi":::"memory")
338 \brief Wait For Event
340 #define __WFE() __ASM volatile ("wfe":::"memory")
345 #define __SEV() __ASM volatile ("sev")
348 \brief Instruction Synchronization Barrier
349 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
350 so that all instructions following the ISB are fetched from cache or memory,
351 after the instruction has been completed.
353 __STATIC_FORCEINLINE void __ISB(void)
355 __ASM volatile ("isb 0xF":::"memory");
360 \brief Data Synchronization Barrier
361 \details Acts as a special kind of Data Memory Barrier.
362 It completes when all explicit memory accesses before this instruction complete.
364 __STATIC_FORCEINLINE void __DSB(void)
366 __ASM volatile ("dsb 0xF":::"memory");
370 \brief Data Memory Barrier
371 \details Ensures the apparent order of the explicit memory operations before
372 and after the instruction, without ensuring their completion.
374 __STATIC_FORCEINLINE void __DMB(void)
376 __ASM volatile ("dmb 0xF":::"memory");
380 \brief Reverse byte order (32 bit)
381 \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
382 \param [in] value Value to reverse
383 \return Reversed value
385 __STATIC_FORCEINLINE uint32_t __REV(uint32_t value)
387 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
388 return __builtin_bswap32(value);
392 __ASM ("rev %0, %1" : "=r" (result) : "r" (value) );
398 \brief Reverse byte order (16 bit)
399 \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
400 \param [in] value Value to reverse
401 \return Reversed value
403 __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value)
406 __ASM ("rev16 %0, %1" : "=r" (result) : "r" (value));
411 \brief Reverse byte order (16 bit)
412 \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
413 \param [in] value Value to reverse
414 \return Reversed value
416 __STATIC_FORCEINLINE int16_t __REVSH(int16_t value)
418 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
419 return (int16_t)__builtin_bswap16(value);
423 __ASM ("revsh %0, %1" : "=r" (result) : "r" (value) );
429 \brief Rotate Right in unsigned value (32 bit)
430 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
431 \param [in] op1 Value to rotate
432 \param [in] op2 Number of Bits to rotate
433 \return Rotated value
435 __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
442 return (op1 >> op2) | (op1 << (32U - op2));
448 \param [in] value is ignored by the processor.
449 If required, a debugger can use it to store additional information about the breakpoint.
451 #define __BKPT(value) __ASM volatile ("bkpt "#value)
454 \brief Reverse bit order of value
455 \details Reverses the bit order of the given value.
456 \param [in] value Value to reverse
457 \return Reversed value
459 __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value)
462 __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) );
467 \brief Count leading zeros
468 \param [in] value Value to count the leading zeros
469 \return number of leading zeros in value
471 __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value)
473 /* Even though __builtin_clz produces a CLZ instruction on ARM, formally
474 __builtin_clz(0) is undefined behaviour, so handle this case specially.
475 This guarantees ARM-compatible results if happening to compile on a non-ARM
476 target, and ensures the compiler doesn't decide to activate any
477 optimisations using the logic "value was passed to __builtin_clz, so it
479 ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a
480 single CLZ instruction.
486 return __builtin_clz(value);
490 \brief LDR Exclusive (8 bit)
491 \details Executes a exclusive LDR instruction for 8 bit value.
492 \param [in] ptr Pointer to data
493 \return value of type uint8_t at (*ptr)
495 __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr)
499 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
500 __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
502 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
503 accepted by assembler. So has to use following less efficient pattern.
505 __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
507 return ((uint8_t) result); /* Add explicit type cast here */
512 \brief LDR Exclusive (16 bit)
513 \details Executes a exclusive LDR instruction for 16 bit values.
514 \param [in] ptr Pointer to data
515 \return value of type uint16_t at (*ptr)
517 __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr)
521 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
522 __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
524 /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
525 accepted by assembler. So has to use following less efficient pattern.
527 __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
529 return ((uint16_t) result); /* Add explicit type cast here */
534 \brief LDR Exclusive (32 bit)
535 \details Executes a exclusive LDR instruction for 32 bit values.
536 \param [in] ptr Pointer to data
537 \return value of type uint32_t at (*ptr)
539 __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr)
543 __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
549 \brief STR Exclusive (8 bit)
550 \details Executes a exclusive STR instruction for 8 bit values.
551 \param [in] value Value to store
552 \param [in] ptr Pointer to location
553 \return 0 Function succeeded
554 \return 1 Function failed
556 __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
560 __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
566 \brief STR Exclusive (16 bit)
567 \details Executes a exclusive STR instruction for 16 bit values.
568 \param [in] value Value to store
569 \param [in] ptr Pointer to location
570 \return 0 Function succeeded
571 \return 1 Function failed
573 __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
577 __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
583 \brief STR Exclusive (32 bit)
584 \details Executes a exclusive STR instruction for 32 bit values.
585 \param [in] value Value to store
586 \param [in] ptr Pointer to location
587 \return 0 Function succeeded
588 \return 1 Function failed
590 __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
594 __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
600 \brief Remove the exclusive lock
601 \details Removes the exclusive lock which is created by LDREX.
603 __STATIC_FORCEINLINE void __CLREX(void)
605 __ASM volatile ("clrex" ::: "memory");
609 \brief Signed Saturate
610 \details Saturates a signed value.
611 \param [in] value Value to be saturated
612 \param [in] sat Bit position to saturate to (1..32)
613 \return Saturated value
615 #define __SSAT(ARG1, ARG2) \
618 int32_t __RES, __ARG1 = (ARG1); \
619 __ASM volatile ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
625 \brief Unsigned Saturate
626 \details Saturates an unsigned value.
627 \param [in] value Value to be saturated
628 \param [in] sat Bit position to saturate to (0..31)
629 \return Saturated value
631 #define __USAT(ARG1, ARG2) \
634 uint32_t __RES, __ARG1 = (ARG1); \
635 __ASM volatile ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) : "cc" ); \
639 /* ########################### Core Function Access ########################### */
642 \brief Enable IRQ Interrupts
643 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
644 Can only be executed in Privileged modes.
646 __STATIC_FORCEINLINE void __enable_irq(void)
648 __ASM volatile ("cpsie i" : : : "memory");
652 \brief Disable IRQ Interrupts
653 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
654 Can only be executed in Privileged modes.
656 __STATIC_FORCEINLINE void __disable_irq(void)
658 __ASM volatile ("cpsid i" : : : "memory");
663 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
664 Can only be executed in Privileged modes.
666 __STATIC_FORCEINLINE void __enable_fault_irq(void)
668 __ASM volatile ("cpsie f" : : : "memory");
673 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
674 Can only be executed in Privileged modes.
676 __STATIC_FORCEINLINE void __disable_fault_irq(void)
678 __ASM volatile ("cpsid f" : : : "memory");
683 \details Returns the current value of the Floating Point Status/Control register.
684 \return Floating Point Status/Control register value
686 __STATIC_FORCEINLINE uint32_t __get_FPSCR(void)
688 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
689 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
690 #if __has_builtin(__builtin_arm_get_fpscr)
691 // Re-enable using built-in when GCC has been fixed
692 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
693 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
694 return __builtin_arm_get_fpscr();
698 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
708 \details Assigns the given value to the Floating Point Status/Control register.
709 \param [in] fpscr Floating Point Status/Control value to set
711 __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr)
713 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
714 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
715 #if __has_builtin(__builtin_arm_set_fpscr)
716 // Re-enable using built-in when GCC has been fixed
717 // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2)
718 /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */
719 __builtin_arm_set_fpscr(fpscr);
721 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory");
728 /** \brief Get CPSR Register
729 \return CPSR Register value
731 __STATIC_FORCEINLINE uint32_t __get_CPSR(void)
734 __ASM volatile("MRS %0, cpsr" : "=r" (result) );
738 /** \brief Set CPSR Register
739 \param [in] cpsr CPSR value to set
741 __STATIC_FORCEINLINE void __set_CPSR(uint32_t cpsr)
743 __ASM volatile ("MSR cpsr, %0" : : "r" (cpsr) : "cc", "memory");
747 \return Processor Mode
749 __STATIC_FORCEINLINE uint32_t __get_mode(void)
751 return (__get_CPSR() & 0x1FU);
755 \param [in] mode Mode value to set
757 __STATIC_FORCEINLINE void __set_mode(uint32_t mode)
759 __ASM volatile("MSR cpsr_c, %0" : : "r" (mode) : "memory");
762 /** \brief Get Stack Pointer
763 \return Stack Pointer value
765 __STATIC_FORCEINLINE uint32_t __get_SP(void)
768 __ASM volatile("MOV %0, sp" : "=r" (result) : : "memory");
772 /** \brief Set Stack Pointer
773 \param [in] stack Stack Pointer value to set
775 __STATIC_FORCEINLINE void __set_SP(uint32_t stack)
777 __ASM volatile("MOV sp, %0" : : "r" (stack) : "memory");
780 /** \brief Get USR/SYS Stack Pointer
781 \return USR/SYS Stack Pointer value
783 __STATIC_FORCEINLINE uint32_t __get_SP_usr(void)
785 uint32_t cpsr = __get_CPSR();
789 "MOV %0, sp " : "=r"(result) : : "memory"
796 /** \brief Set USR/SYS Stack Pointer
797 \param [in] topOfProcStack USR/SYS Stack Pointer value to set
799 __STATIC_FORCEINLINE void __set_SP_usr(uint32_t topOfProcStack)
801 uint32_t cpsr = __get_CPSR();
804 "MOV sp, %0 " : : "r" (topOfProcStack) : "memory"
811 \return Floating Point Exception Control register value
813 __STATIC_FORCEINLINE uint32_t __get_FPEXC(void)
815 #if (__FPU_PRESENT == 1)
817 __ASM volatile("VMRS %0, fpexc" : "=r" (result) : : "memory");
825 \param [in] fpexc Floating Point Exception Control value to set
827 __STATIC_FORCEINLINE void __set_FPEXC(uint32_t fpexc)
829 #if (__FPU_PRESENT == 1)
830 __ASM volatile ("VMSR fpexc, %0" : : "r" (fpexc) : "memory");
835 * Include common core functions to access Coprocessor 15 registers
838 #define __get_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MRC p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : "=r" (Rt) : : "memory" )
839 #define __set_CP(cp, op1, Rt, CRn, CRm, op2) __ASM volatile("MCR p" # cp ", " # op1 ", %0, c" # CRn ", c" # CRm ", " # op2 : : "r" (Rt) : "memory" )
840 #define __get_CP64(cp, op1, Rt, CRm) __ASM volatile("MRRC p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : "=r" (Rt) : : "memory" )
841 #define __set_CP64(cp, op1, Rt, CRm) __ASM volatile("MCRR p" # cp ", " # op1 ", %Q0, %R0, c" # CRm : : "r" (Rt) : "memory" )
843 #include "cmsis_cp15.h"
845 /** \brief Enable Floating Point Unit
847 Critical section, called from undef handler, so systick is disabled
849 __STATIC_INLINE void __FPU_Enable(void)
852 //Permit access to VFP/NEON, registers by modifying CPACR
853 " MRC p15,0,R1,c1,c0,2 \n"
854 " ORR R1,R1,#0x00F00000 \n"
855 " MCR p15,0,R1,c1,c0,2 \n"
857 //Ensure that subsequent instructions occur in the context of VFP/NEON access permitted
862 " ORR R1,R1,#0x40000000 \n"
865 //Initialise VFP/NEON registers to 0
868 //Initialise D16 registers to 0
886 #if (defined(__ARM_NEON) && (__ARM_NEON == 1))
887 //Initialise D32 registers to 0
906 //Initialise FPSCR to a known state
908 " LDR R2,=0x00086060 \n" //Mask off all bits that do not have to be preserved. Non-preserved bits can/should be zero.
911 : : : "cc", "r1", "r2"
915 #pragma GCC diagnostic pop
917 #endif /* __CMSIS_GCC_H */