1 /**************************************************************************//**
\r
2 * @file core_cmFunc.h
\r
3 * @brief CMSIS Cortex-M Core Function Access Header File
\r
5 * @date 25. February 2013
\r
9 ******************************************************************************/
\r
10 /* Copyright (c) 2009 - 2013 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)
\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) */
\r
273 #if (__CORTEX_M == 0x04)
\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
306 #endif /* (__CORTEX_M == 0x04) */
\r
309 #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
\r
310 /* IAR iccarm specific functions */
\r
312 #include <cmsis_iar.h>
\r
315 #elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/
\r
316 /* TI CCS specific functions */
\r
318 #include <cmsis_ccs.h>
\r
321 #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
\r
322 /* GNU gcc specific functions */
\r
324 /** \brief Enable IRQ Interrupts
\r
326 This function enables IRQ interrupts by clearing the I-bit in the CPSR.
\r
327 Can only be executed in Privileged modes.
\r
329 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
\r
331 __ASM volatile ("cpsie i" : : : "memory");
\r
335 /** \brief Disable IRQ Interrupts
\r
337 This function disables IRQ interrupts by setting the I-bit in the CPSR.
\r
338 Can only be executed in Privileged modes.
\r
340 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
\r
342 __ASM volatile ("cpsid i" : : : "memory");
\r
346 /** \brief Get Control Register
\r
348 This function returns the content of the Control Register.
\r
350 \return Control Register value
\r
352 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
\r
356 __ASM volatile ("MRS %0, control" : "=r" (result) );
\r
361 /** \brief Set Control Register
\r
363 This function writes the given value to the Control Register.
\r
365 \param [in] control Control Register value to set
\r
367 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
\r
369 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
\r
373 /** \brief Get IPSR Register
\r
375 This function returns the content of the IPSR Register.
\r
377 \return IPSR Register value
\r
379 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
\r
383 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
\r
388 /** \brief Get APSR Register
\r
390 This function returns the content of the APSR Register.
\r
392 \return APSR Register value
\r
394 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
\r
398 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
\r
403 /** \brief Get xPSR Register
\r
405 This function returns the content of the xPSR Register.
\r
407 \return xPSR Register value
\r
409 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
\r
413 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
\r
418 /** \brief Get Process Stack Pointer
\r
420 This function returns the current value of the Process Stack Pointer (PSP).
\r
422 \return PSP Register value
\r
424 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
\r
426 register uint32_t result;
\r
428 __ASM volatile ("MRS %0, psp\n" : "=r" (result) );
\r
433 /** \brief Set Process Stack Pointer
\r
435 This function assigns the given value to the Process Stack Pointer (PSP).
\r
437 \param [in] topOfProcStack Process Stack Pointer value to set
\r
439 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
\r
441 __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
\r
445 /** \brief Get Main Stack Pointer
\r
447 This function returns the current value of the Main Stack Pointer (MSP).
\r
449 \return MSP Register value
\r
451 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
\r
453 register uint32_t result;
\r
455 __ASM volatile ("MRS %0, msp\n" : "=r" (result) );
\r
460 /** \brief Set Main Stack Pointer
\r
462 This function assigns the given value to the Main Stack Pointer (MSP).
\r
464 \param [in] topOfMainStack Main Stack Pointer value to set
\r
466 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
\r
468 __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
\r
472 /** \brief Get Priority Mask
\r
474 This function returns the current state of the priority mask bit from the Priority Mask Register.
\r
476 \return Priority Mask value
\r
478 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
\r
482 __ASM volatile ("MRS %0, primask" : "=r" (result) );
\r
487 /** \brief Set Priority Mask
\r
489 This function assigns the given value to the Priority Mask Register.
\r
491 \param [in] priMask Priority Mask
\r
493 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
\r
495 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
\r
499 #if (__CORTEX_M >= 0x03)
\r
501 /** \brief Enable FIQ
\r
503 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
504 Can only be executed in Privileged modes.
\r
506 __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
\r
508 __ASM volatile ("cpsie f" : : : "memory");
\r
512 /** \brief Disable FIQ
\r
514 This function disables FIQ interrupts by setting the F-bit in the CPSR.
\r
515 Can only be executed in Privileged modes.
\r
517 __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
\r
519 __ASM volatile ("cpsid f" : : : "memory");
\r
523 /** \brief Get Base Priority
\r
525 This function returns the current value of the Base Priority register.
\r
527 \return Base Priority register value
\r
529 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
\r
533 __ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
\r
538 /** \brief Set Base Priority
\r
540 This function assigns the given value to the Base Priority register.
\r
542 \param [in] basePri Base Priority value to set
\r
544 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
\r
546 __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
\r
550 /** \brief Get Fault Mask
\r
552 This function returns the current value of the Fault Mask register.
\r
554 \return Fault Mask register value
\r
556 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
\r
560 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
\r
565 /** \brief Set Fault Mask
\r
567 This function assigns the given value to the Fault Mask register.
\r
569 \param [in] faultMask Fault Mask value to set
\r
571 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
573 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
\r
576 #endif /* (__CORTEX_M >= 0x03) */
\r
579 #if (__CORTEX_M == 0x04)
\r
581 /** \brief Get FPSCR
\r
583 This function returns the current value of the Floating Point Status/Control register.
\r
585 \return Floating Point Status/Control register value
\r
587 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
\r
589 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
592 /* Empty asm statement works as a scheduling barrier */
\r
593 __ASM volatile ("");
\r
594 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
\r
595 __ASM volatile ("");
\r
603 /** \brief Set FPSCR
\r
605 This function assigns the given value to the Floating Point Status/Control register.
\r
607 \param [in] fpscr Floating Point Status/Control value to set
\r
609 __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
\r
611 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
612 /* Empty asm statement works as a scheduling barrier */
\r
613 __ASM volatile ("");
\r
614 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
\r
615 __ASM volatile ("");
\r
619 #endif /* (__CORTEX_M == 0x04) */
\r
622 #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
\r
623 /* TASKING carm specific functions */
\r
626 * The CMSIS functions have been implemented as intrinsics in the compiler.
\r
627 * Please use "carm -?i" to get an up to date list of all instrinsics,
\r
628 * Including the CMSIS ones.
\r
633 /*@} end of CMSIS_Core_RegAccFunctions */
\r
636 #endif /* __CORE_CMFUNC_H */
\r