1 /**************************************************************************//**
\r
2 * @file core_cmFunc.h
\r
3 * @brief CMSIS Cortex-M Core Function Access Header File
\r
5 * @date 28. August 2014
\r
9 ******************************************************************************/
\r
10 /* Copyright (c) 2009 - 2014 ARM LIMITED
\r
12 All rights reserved.
\r
13 Redistribution and use in source and binary forms, with or without
\r
14 modification, are permitted provided that the following conditions are met:
\r
15 - Redistributions of source code must retain the above copyright
\r
16 notice, this list of conditions and the following disclaimer.
\r
17 - Redistributions in binary form must reproduce the above copyright
\r
18 notice, this list of conditions and the following disclaimer in the
\r
19 documentation and/or other materials provided with the distribution.
\r
20 - Neither the name of ARM nor the names of its contributors may be used
\r
21 to endorse or promote products derived from this software without
\r
22 specific prior written permission.
\r
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
\r
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
34 POSSIBILITY OF SUCH DAMAGE.
\r
35 ---------------------------------------------------------------------------*/
\r
38 #ifndef __CORE_CMFUNC_H
\r
39 #define __CORE_CMFUNC_H
\r
42 /* ########################### Core Function Access ########################### */
\r
43 /** \ingroup CMSIS_Core_FunctionInterface
\r
44 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
\r
48 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
\r
49 /* ARM armcc specific functions */
\r
51 #if (__ARMCC_VERSION < 400677)
\r
52 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
\r
55 /* intrinsic void __enable_irq(); */
\r
56 /* intrinsic void __disable_irq(); */
\r
58 /** \brief Get Control Register
\r
60 This function returns the content of the Control Register.
\r
62 \return Control Register value
\r
64 __STATIC_INLINE uint32_t __get_CONTROL(void)
\r
66 register uint32_t __regControl __ASM("control");
\r
67 return(__regControl);
\r
71 /** \brief Set Control Register
\r
73 This function writes the given value to the Control Register.
\r
75 \param [in] control Control Register value to set
\r
77 __STATIC_INLINE void __set_CONTROL(uint32_t control)
\r
79 register uint32_t __regControl __ASM("control");
\r
80 __regControl = control;
\r
84 /** \brief Get IPSR Register
\r
86 This function returns the content of the IPSR Register.
\r
88 \return IPSR Register value
\r
90 __STATIC_INLINE uint32_t __get_IPSR(void)
\r
92 register uint32_t __regIPSR __ASM("ipsr");
\r
97 /** \brief Get APSR Register
\r
99 This function returns the content of the APSR Register.
\r
101 \return APSR Register value
\r
103 __STATIC_INLINE uint32_t __get_APSR(void)
\r
105 register uint32_t __regAPSR __ASM("apsr");
\r
110 /** \brief Get xPSR Register
\r
112 This function returns the content of the xPSR Register.
\r
114 \return xPSR Register value
\r
116 __STATIC_INLINE uint32_t __get_xPSR(void)
\r
118 register uint32_t __regXPSR __ASM("xpsr");
\r
123 /** \brief Get Process Stack Pointer
\r
125 This function returns the current value of the Process Stack Pointer (PSP).
\r
127 \return PSP Register value
\r
129 __STATIC_INLINE uint32_t __get_PSP(void)
\r
131 register uint32_t __regProcessStackPointer __ASM("psp");
\r
132 return(__regProcessStackPointer);
\r
136 /** \brief Set Process Stack Pointer
\r
138 This function assigns the given value to the Process Stack Pointer (PSP).
\r
140 \param [in] topOfProcStack Process Stack Pointer value to set
\r
142 __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
\r
144 register uint32_t __regProcessStackPointer __ASM("psp");
\r
145 __regProcessStackPointer = topOfProcStack;
\r
149 /** \brief Get Main Stack Pointer
\r
151 This function returns the current value of the Main Stack Pointer (MSP).
\r
153 \return MSP Register value
\r
155 __STATIC_INLINE uint32_t __get_MSP(void)
\r
157 register uint32_t __regMainStackPointer __ASM("msp");
\r
158 return(__regMainStackPointer);
\r
162 /** \brief Set Main Stack Pointer
\r
164 This function assigns the given value to the Main Stack Pointer (MSP).
\r
166 \param [in] topOfMainStack Main Stack Pointer value to set
\r
168 __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
\r
170 register uint32_t __regMainStackPointer __ASM("msp");
\r
171 __regMainStackPointer = topOfMainStack;
\r
175 /** \brief Get Priority Mask
\r
177 This function returns the current state of the priority mask bit from the Priority Mask Register.
\r
179 \return Priority Mask value
\r
181 __STATIC_INLINE uint32_t __get_PRIMASK(void)
\r
183 register uint32_t __regPriMask __ASM("primask");
\r
184 return(__regPriMask);
\r
188 /** \brief Set Priority Mask
\r
190 This function assigns the given value to the Priority Mask Register.
\r
192 \param [in] priMask Priority Mask
\r
194 __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
\r
196 register uint32_t __regPriMask __ASM("primask");
\r
197 __regPriMask = (priMask);
\r
201 #if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300)
\r
203 /** \brief Enable FIQ
\r
205 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
206 Can only be executed in Privileged modes.
\r
208 #define __enable_fault_irq __enable_fiq
\r
211 /** \brief Disable FIQ
\r
213 This function disables FIQ interrupts by setting the F-bit in the CPSR.
\r
214 Can only be executed in Privileged modes.
\r
216 #define __disable_fault_irq __disable_fiq
\r
219 /** \brief Get Base Priority
\r
221 This function returns the current value of the Base Priority register.
\r
223 \return Base Priority register value
\r
225 __STATIC_INLINE uint32_t __get_BASEPRI(void)
\r
227 register uint32_t __regBasePri __ASM("basepri");
\r
228 return(__regBasePri);
\r
232 /** \brief Set Base Priority
\r
234 This function assigns the given value to the Base Priority register.
\r
236 \param [in] basePri Base Priority value to set
\r
238 __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
\r
240 register uint32_t __regBasePri __ASM("basepri");
\r
241 __regBasePri = (basePri & 0xff);
\r
245 /** \brief Get Fault Mask
\r
247 This function returns the current value of the Fault Mask register.
\r
249 \return Fault Mask register value
\r
251 __STATIC_INLINE uint32_t __get_FAULTMASK(void)
\r
253 register uint32_t __regFaultMask __ASM("faultmask");
\r
254 return(__regFaultMask);
\r
258 /** \brief Set Fault Mask
\r
260 This function assigns the given value to the Fault Mask register.
\r
262 \param [in] faultMask Fault Mask value to set
\r
264 __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
266 register uint32_t __regFaultMask __ASM("faultmask");
\r
267 __regFaultMask = (faultMask & (uint32_t)1);
\r
270 #endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
\r
273 #if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
\r
275 /** \brief Get FPSCR
\r
277 This function returns the current value of the Floating Point Status/Control register.
\r
279 \return Floating Point Status/Control register value
\r
281 __STATIC_INLINE uint32_t __get_FPSCR(void)
\r
283 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
284 register uint32_t __regfpscr __ASM("fpscr");
\r
285 return(__regfpscr);
\r
292 /** \brief Set FPSCR
\r
294 This function assigns the given value to the Floating Point Status/Control register.
\r
296 \param [in] fpscr Floating Point Status/Control value to set
\r
298 __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
\r
300 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
301 register uint32_t __regfpscr __ASM("fpscr");
\r
302 __regfpscr = (fpscr);
\r
308 #endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
\r
311 #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
\r
312 /* GNU gcc specific functions */
\r
314 /** \brief Enable IRQ Interrupts
\r
316 This function enables IRQ interrupts by clearing the I-bit in the CPSR.
\r
317 Can only be executed in Privileged modes.
\r
319 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
\r
321 __ASM volatile ("cpsie i" : : : "memory");
\r
325 /** \brief Disable IRQ Interrupts
\r
327 This function disables IRQ interrupts by setting the I-bit in the CPSR.
\r
328 Can only be executed in Privileged modes.
\r
330 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
\r
332 __ASM volatile ("cpsid i" : : : "memory");
\r
336 /** \brief Get Control Register
\r
338 This function returns the content of the Control Register.
\r
340 \return Control Register value
\r
342 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
\r
346 __ASM volatile ("MRS %0, control" : "=r" (result) );
\r
351 /** \brief Set Control Register
\r
353 This function writes the given value to the Control Register.
\r
355 \param [in] control Control Register value to set
\r
357 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
\r
359 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
\r
363 /** \brief Get IPSR Register
\r
365 This function returns the content of the IPSR Register.
\r
367 \return IPSR Register value
\r
369 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
\r
373 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
\r
378 /** \brief Get APSR Register
\r
380 This function returns the content of the APSR Register.
\r
382 \return APSR Register value
\r
384 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
\r
388 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
\r
393 /** \brief Get xPSR Register
\r
395 This function returns the content of the xPSR Register.
\r
397 \return xPSR Register value
\r
399 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
\r
403 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
\r
408 /** \brief Get Process Stack Pointer
\r
410 This function returns the current value of the Process Stack Pointer (PSP).
\r
412 \return PSP Register value
\r
414 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
\r
416 register uint32_t result;
\r
418 __ASM volatile ("MRS %0, psp\n" : "=r" (result) );
\r
423 /** \brief Set Process Stack Pointer
\r
425 This function assigns the given value to the Process Stack Pointer (PSP).
\r
427 \param [in] topOfProcStack Process Stack Pointer value to set
\r
429 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
\r
431 __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
\r
435 /** \brief Get Main Stack Pointer
\r
437 This function returns the current value of the Main Stack Pointer (MSP).
\r
439 \return MSP Register value
\r
441 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
\r
443 register uint32_t result;
\r
445 __ASM volatile ("MRS %0, msp\n" : "=r" (result) );
\r
450 /** \brief Set Main Stack Pointer
\r
452 This function assigns the given value to the Main Stack Pointer (MSP).
\r
454 \param [in] topOfMainStack Main Stack Pointer value to set
\r
456 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
\r
458 __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
\r
462 /** \brief Get Priority Mask
\r
464 This function returns the current state of the priority mask bit from the Priority Mask Register.
\r
466 \return Priority Mask value
\r
468 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
\r
472 __ASM volatile ("MRS %0, primask" : "=r" (result) );
\r
477 /** \brief Set Priority Mask
\r
479 This function assigns the given value to the Priority Mask Register.
\r
481 \param [in] priMask Priority Mask
\r
483 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
\r
485 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
\r
489 #if (__CORTEX_M >= 0x03)
\r
491 /** \brief Enable FIQ
\r
493 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
494 Can only be executed in Privileged modes.
\r
496 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
\r
498 __ASM volatile ("cpsie f" : : : "memory");
\r
502 /** \brief Disable FIQ
\r
504 This function disables FIQ interrupts by setting the F-bit in the CPSR.
\r
505 Can only be executed in Privileged modes.
\r
507 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
\r
509 __ASM volatile ("cpsid f" : : : "memory");
\r
513 /** \brief Get Base Priority
\r
515 This function returns the current value of the Base Priority register.
\r
517 \return Base Priority register value
\r
519 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
\r
523 __ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
\r
528 /** \brief Set Base Priority
\r
530 This function assigns the given value to the Base Priority register.
\r
532 \param [in] basePri Base Priority value to set
\r
534 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
\r
536 __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
\r
540 /** \brief Get Fault Mask
\r
542 This function returns the current value of the Fault Mask register.
\r
544 \return Fault Mask register value
\r
546 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
\r
550 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
\r
555 /** \brief Set Fault Mask
\r
557 This function assigns the given value to the Fault Mask register.
\r
559 \param [in] faultMask Fault Mask value to set
\r
561 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
563 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
\r
566 #endif /* (__CORTEX_M >= 0x03) */
\r
569 #if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
\r
571 /** \brief Get FPSCR
\r
573 This function returns the current value of the Floating Point Status/Control register.
\r
575 \return Floating Point Status/Control register value
\r
577 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
\r
579 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
582 /* Empty asm statement works as a scheduling barrier */
\r
583 __ASM volatile ("");
\r
584 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
\r
585 __ASM volatile ("");
\r
593 /** \brief Set FPSCR
\r
595 This function assigns the given value to the Floating Point Status/Control register.
\r
597 \param [in] fpscr Floating Point Status/Control value to set
\r
599 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
\r
601 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
602 /* Empty asm statement works as a scheduling barrier */
\r
603 __ASM volatile ("");
\r
604 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
\r
605 __ASM volatile ("");
\r
611 #endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
\r
614 #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
\r
615 /* IAR iccarm specific functions */
\r
616 #include <cmsis_iar.h>
\r
619 #elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
\r
620 /* TI CCS specific functions */
\r
621 #include <cmsis_ccs.h>
\r
624 #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
\r
625 /* TASKING carm specific functions */
\r
627 * The CMSIS functions have been implemented as intrinsics in the compiler.
\r
628 * Please use "carm -?i" to get an up to date list of all intrinsics,
\r
629 * Including the CMSIS ones.
\r
633 #elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
\r
634 /* Cosmic specific functions */
\r
635 #include <cmsis_csm.h>
\r
639 /*@} end of CMSIS_Core_RegAccFunctions */
\r
641 #endif /* __CORE_CMFUNC_H */
\r