1 /**************************************************************************//**
\r
2 * @file core_cmFunc.h
\r
3 * @brief CMSIS Cortex-M Core Function Access Header File
\r
5 * @date 18. March 2015
\r
9 ******************************************************************************/
\r
10 /* Copyright (c) 2009 - 2015 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 Set Base Priority with condition
\r
247 This function assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
\r
248 or the new value increases the BASEPRI priority level.
\r
250 \param [in] basePri Base Priority value to set
\r
252 __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
\r
254 register uint32_t __regBasePriMax __ASM("basepri_max");
\r
255 __regBasePriMax = (basePri & 0xff);
\r
259 /** \brief Get Fault Mask
\r
261 This function returns the current value of the Fault Mask register.
\r
263 \return Fault Mask register value
\r
265 __STATIC_INLINE uint32_t __get_FAULTMASK(void)
\r
267 register uint32_t __regFaultMask __ASM("faultmask");
\r
268 return(__regFaultMask);
\r
272 /** \brief Set Fault Mask
\r
274 This function assigns the given value to the Fault Mask register.
\r
276 \param [in] faultMask Fault Mask value to set
\r
278 __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
280 register uint32_t __regFaultMask __ASM("faultmask");
\r
281 __regFaultMask = (faultMask & (uint32_t)1);
\r
284 #endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */
\r
287 #if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
\r
289 /** \brief Get FPSCR
\r
291 This function returns the current value of the Floating Point Status/Control register.
\r
293 \return Floating Point Status/Control register value
\r
295 __STATIC_INLINE uint32_t __get_FPSCR(void)
\r
297 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
298 register uint32_t __regfpscr __ASM("fpscr");
\r
299 return(__regfpscr);
\r
306 /** \brief Set FPSCR
\r
308 This function assigns the given value to the Floating Point Status/Control register.
\r
310 \param [in] fpscr Floating Point Status/Control value to set
\r
312 __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
\r
314 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
315 register uint32_t __regfpscr __ASM("fpscr");
\r
316 __regfpscr = (fpscr);
\r
320 #endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
\r
323 #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
\r
324 /* GNU gcc specific functions */
\r
326 /** \brief Enable IRQ Interrupts
\r
328 This function enables IRQ interrupts by clearing the I-bit in the CPSR.
\r
329 Can only be executed in Privileged modes.
\r
331 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
\r
333 __ASM volatile ("cpsie i" : : : "memory");
\r
337 /** \brief Disable IRQ Interrupts
\r
339 This function disables IRQ interrupts by setting the I-bit in the CPSR.
\r
340 Can only be executed in Privileged modes.
\r
342 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
\r
344 __ASM volatile ("cpsid i" : : : "memory");
\r
348 /** \brief Get Control Register
\r
350 This function returns the content of the Control Register.
\r
352 \return Control Register value
\r
354 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
\r
358 __ASM volatile ("MRS %0, control" : "=r" (result) );
\r
363 /** \brief Set Control Register
\r
365 This function writes the given value to the Control Register.
\r
367 \param [in] control Control Register value to set
\r
369 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
\r
371 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
\r
375 /** \brief Get IPSR Register
\r
377 This function returns the content of the IPSR Register.
\r
379 \return IPSR Register value
\r
381 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
\r
385 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
\r
390 /** \brief Get APSR Register
\r
392 This function returns the content of the APSR Register.
\r
394 \return APSR Register value
\r
396 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
\r
400 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
\r
405 /** \brief Get xPSR Register
\r
407 This function returns the content of the xPSR Register.
\r
409 \return xPSR Register value
\r
411 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
\r
415 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
\r
420 /** \brief Get Process Stack Pointer
\r
422 This function returns the current value of the Process Stack Pointer (PSP).
\r
424 \return PSP Register value
\r
426 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
\r
428 register uint32_t result;
\r
430 __ASM volatile ("MRS %0, psp\n" : "=r" (result) );
\r
435 /** \brief Set Process Stack Pointer
\r
437 This function assigns the given value to the Process Stack Pointer (PSP).
\r
439 \param [in] topOfProcStack Process Stack Pointer value to set
\r
441 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
\r
443 __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
\r
447 /** \brief Get Main Stack Pointer
\r
449 This function returns the current value of the Main Stack Pointer (MSP).
\r
451 \return MSP Register value
\r
453 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
\r
455 register uint32_t result;
\r
457 __ASM volatile ("MRS %0, msp\n" : "=r" (result) );
\r
462 /** \brief Set Main Stack Pointer
\r
464 This function assigns the given value to the Main Stack Pointer (MSP).
\r
466 \param [in] topOfMainStack Main Stack Pointer value to set
\r
468 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
\r
470 __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
\r
474 /** \brief Get Priority Mask
\r
476 This function returns the current state of the priority mask bit from the Priority Mask Register.
\r
478 \return Priority Mask value
\r
480 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
\r
484 __ASM volatile ("MRS %0, primask" : "=r" (result) );
\r
489 /** \brief Set Priority Mask
\r
491 This function assigns the given value to the Priority Mask Register.
\r
493 \param [in] priMask Priority Mask
\r
495 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
\r
497 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
\r
501 #if (__CORTEX_M >= 0x03)
\r
503 /** \brief Enable FIQ
\r
505 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
506 Can only be executed in Privileged modes.
\r
508 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
\r
510 __ASM volatile ("cpsie f" : : : "memory");
\r
514 /** \brief Disable FIQ
\r
516 This function disables FIQ interrupts by setting the F-bit in the CPSR.
\r
517 Can only be executed in Privileged modes.
\r
519 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
\r
521 __ASM volatile ("cpsid f" : : : "memory");
\r
525 /** \brief Get Base Priority
\r
527 This function returns the current value of the Base Priority register.
\r
529 \return Base Priority register value
\r
531 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
\r
535 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
\r
540 /** \brief Set Base Priority
\r
542 This function assigns the given value to the Base Priority register.
\r
544 \param [in] basePri Base Priority value to set
\r
546 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
\r
548 __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
\r
552 /** \brief Set Base Priority with condition
\r
554 This function assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
\r
555 or the new value increases the BASEPRI priority level.
\r
557 \param [in] basePri Base Priority value to set
\r
559 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t value)
\r
561 __ASM volatile ("MSR basepri_max, %0" : : "r" (value) : "memory");
\r
565 /** \brief Get Fault Mask
\r
567 This function returns the current value of the Fault Mask register.
\r
569 \return Fault Mask register value
\r
571 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
\r
575 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
\r
580 /** \brief Set Fault Mask
\r
582 This function assigns the given value to the Fault Mask register.
\r
584 \param [in] faultMask Fault Mask value to set
\r
586 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
588 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
\r
591 #endif /* (__CORTEX_M >= 0x03) */
\r
594 #if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07)
\r
596 /** \brief Get FPSCR
\r
598 This function returns the current value of the Floating Point Status/Control register.
\r
600 \return Floating Point Status/Control register value
\r
602 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
\r
604 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
607 /* Empty asm statement works as a scheduling barrier */
\r
608 __ASM volatile ("");
\r
609 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
\r
610 __ASM volatile ("");
\r
618 /** \brief Set FPSCR
\r
620 This function assigns the given value to the Floating Point Status/Control register.
\r
622 \param [in] fpscr Floating Point Status/Control value to set
\r
624 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
\r
626 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
627 /* Empty asm statement works as a scheduling barrier */
\r
628 __ASM volatile ("");
\r
629 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
\r
630 __ASM volatile ("");
\r
634 #endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */
\r
637 #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
\r
638 /* IAR iccarm specific functions */
\r
639 #include <cmsis_iar.h>
\r
642 #elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
\r
643 /* TI CCS specific functions */
\r
644 #include <cmsis_ccs.h>
\r
647 #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
\r
648 /* TASKING carm specific functions */
\r
650 * The CMSIS functions have been implemented as intrinsics in the compiler.
\r
651 * Please use "carm -?i" to get an up to date list of all intrinsics,
\r
652 * Including the CMSIS ones.
\r
656 #elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/
\r
657 /* Cosmic specific functions */
\r
658 #include <cmsis_csm.h>
\r
662 /*@} end of CMSIS_Core_RegAccFunctions */
\r
664 #endif /* __CORE_CMFUNC_H */
\r