1 /**************************************************************************//**
\r
2 * @file core_cmFunc.h
\r
3 * @brief CMSIS Cortex-M Core Function Access Header File
\r
5 * @date 26. July 2011
\r
8 * Copyright (C) 2009-2011 ARM Limited. All rights reserved.
\r
11 * ARM Limited (ARM) is supplying this software for use with Cortex-M
\r
12 * processor based microcontrollers. This file can be freely distributed
\r
13 * within development tools that are supporting such ARM based processors.
\r
16 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
\r
17 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
\r
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
\r
19 * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
\r
20 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
\r
22 ******************************************************************************/
\r
24 #ifndef __CORE_CMFUNC_H
\r
25 #define __CORE_CMFUNC_H
\r
28 /* ########################### Core Function Access ########################### */
\r
29 /** \ingroup CMSIS_Core_FunctionInterface
\r
30 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
\r
34 #if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/
\r
35 /* ARM armcc specific functions */
\r
37 #if (__ARMCC_VERSION < 400677)
\r
38 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
\r
41 /* intrinsic void __enable_irq(); */
\r
42 /* intrinsic void __disable_irq(); */
\r
44 /** \brief Get Control Register
\r
46 This function returns the content of the Control Register.
\r
48 \return Control Register value
\r
50 static __INLINE uint32_t __get_CONTROL(void)
\r
52 register uint32_t __regControl __ASM("control");
\r
53 return(__regControl);
\r
57 /** \brief Set Control Register
\r
59 This function writes the given value to the Control Register.
\r
61 \param [in] control Control Register value to set
\r
63 static __INLINE void __set_CONTROL(uint32_t control)
\r
65 register uint32_t __regControl __ASM("control");
\r
66 __regControl = control;
\r
70 /** \brief Get ISPR Register
\r
72 This function returns the content of the ISPR Register.
\r
74 \return ISPR Register value
\r
76 static __INLINE uint32_t __get_IPSR(void)
\r
78 register uint32_t __regIPSR __ASM("ipsr");
\r
83 /** \brief Get APSR Register
\r
85 This function returns the content of the APSR Register.
\r
87 \return APSR Register value
\r
89 static __INLINE uint32_t __get_APSR(void)
\r
91 register uint32_t __regAPSR __ASM("apsr");
\r
96 /** \brief Get xPSR Register
\r
98 This function returns the content of the xPSR Register.
\r
100 \return xPSR Register value
\r
102 static __INLINE uint32_t __get_xPSR(void)
\r
104 register uint32_t __regXPSR __ASM("xpsr");
\r
109 /** \brief Get Process Stack Pointer
\r
111 This function returns the current value of the Process Stack Pointer (PSP).
\r
113 \return PSP Register value
\r
115 static __INLINE uint32_t __get_PSP(void)
\r
117 register uint32_t __regProcessStackPointer __ASM("psp");
\r
118 return(__regProcessStackPointer);
\r
122 /** \brief Set Process Stack Pointer
\r
124 This function assigns the given value to the Process Stack Pointer (PSP).
\r
126 \param [in] topOfProcStack Process Stack Pointer value to set
\r
128 static __INLINE void __set_PSP(uint32_t topOfProcStack)
\r
130 register uint32_t __regProcessStackPointer __ASM("psp");
\r
131 __regProcessStackPointer = topOfProcStack;
\r
135 /** \brief Get Main Stack Pointer
\r
137 This function returns the current value of the Main Stack Pointer (MSP).
\r
139 \return MSP Register value
\r
141 static __INLINE uint32_t __get_MSP(void)
\r
143 register uint32_t __regMainStackPointer __ASM("msp");
\r
144 return(__regMainStackPointer);
\r
148 /** \brief Set Main Stack Pointer
\r
150 This function assigns the given value to the Main Stack Pointer (MSP).
\r
152 \param [in] topOfMainStack Main Stack Pointer value to set
\r
154 static __INLINE void __set_MSP(uint32_t topOfMainStack)
\r
156 register uint32_t __regMainStackPointer __ASM("msp");
\r
157 __regMainStackPointer = topOfMainStack;
\r
161 /** \brief Get Priority Mask
\r
163 This function returns the current state of the priority mask bit from the Priority Mask Register.
\r
165 \return Priority Mask value
\r
167 static __INLINE uint32_t __get_PRIMASK(void)
\r
169 register uint32_t __regPriMask __ASM("primask");
\r
170 return(__regPriMask);
\r
174 /** \brief Set Priority Mask
\r
176 This function assigns the given value to the Priority Mask Register.
\r
178 \param [in] priMask Priority Mask
\r
180 static __INLINE void __set_PRIMASK(uint32_t priMask)
\r
182 register uint32_t __regPriMask __ASM("primask");
\r
183 __regPriMask = (priMask);
\r
187 #if (__CORTEX_M >= 0x03)
\r
189 /** \brief Enable FIQ
\r
191 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
192 Can only be executed in Privileged modes.
\r
194 #define __enable_fault_irq __enable_fiq
\r
197 /** \brief Disable FIQ
\r
199 This function disables FIQ interrupts by setting the F-bit in the CPSR.
\r
200 Can only be executed in Privileged modes.
\r
202 #define __disable_fault_irq __disable_fiq
\r
205 /** \brief Get Base Priority
\r
207 This function returns the current value of the Base Priority register.
\r
209 \return Base Priority register value
\r
211 static __INLINE uint32_t __get_BASEPRI(void)
\r
213 register uint32_t __regBasePri __ASM("basepri");
\r
214 return(__regBasePri);
\r
218 /** \brief Set Base Priority
\r
220 This function assigns the given value to the Base Priority register.
\r
222 \param [in] basePri Base Priority value to set
\r
224 static __INLINE void __set_BASEPRI(uint32_t basePri)
\r
226 register uint32_t __regBasePri __ASM("basepri");
\r
227 __regBasePri = (basePri & 0xff);
\r
231 /** \brief Get Fault Mask
\r
233 This function returns the current value of the Fault Mask register.
\r
235 \return Fault Mask register value
\r
237 static __INLINE uint32_t __get_FAULTMASK(void)
\r
239 register uint32_t __regFaultMask __ASM("faultmask");
\r
240 return(__regFaultMask);
\r
244 /** \brief Set Fault Mask
\r
246 This function assigns the given value to the Fault Mask register.
\r
248 \param [in] faultMask Fault Mask value to set
\r
250 static __INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
252 register uint32_t __regFaultMask __ASM("faultmask");
\r
253 __regFaultMask = (faultMask & (uint32_t)1);
\r
256 #endif /* (__CORTEX_M >= 0x03) */
\r
259 #if (__CORTEX_M == 0x04)
\r
261 /** \brief Get FPSCR
\r
263 This function returns the current value of the Floating Point Status/Control register.
\r
265 \return Floating Point Status/Control register value
\r
267 static __INLINE uint32_t __get_FPSCR(void)
\r
269 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
270 register uint32_t __regfpscr __ASM("fpscr");
\r
271 return(__regfpscr);
\r
278 /** \brief Set FPSCR
\r
280 This function assigns the given value to the Floating Point Status/Control register.
\r
282 \param [in] fpscr Floating Point Status/Control value to set
\r
284 static __INLINE void __set_FPSCR(uint32_t fpscr)
\r
286 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
287 register uint32_t __regfpscr __ASM("fpscr");
\r
288 __regfpscr = (fpscr);
\r
292 #endif /* (__CORTEX_M == 0x04) */
\r
295 #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/
\r
296 /* IAR iccarm specific functions */
\r
298 #include <cmsis_iar.h>
\r
300 #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/
\r
301 /* GNU gcc specific functions */
\r
303 /** \brief Enable IRQ Interrupts
\r
305 This function enables IRQ interrupts by clearing the I-bit in the CPSR.
\r
306 Can only be executed in Privileged modes.
\r
308 __attribute__( ( always_inline ) ) static __INLINE void __enable_irq(void)
\r
310 __ASM volatile ("cpsie i");
\r
314 /** \brief Disable IRQ Interrupts
\r
316 This function disables IRQ interrupts by setting the I-bit in the CPSR.
\r
317 Can only be executed in Privileged modes.
\r
319 __attribute__( ( always_inline ) ) static __INLINE void __disable_irq(void)
\r
321 __ASM volatile ("cpsid i");
\r
325 /** \brief Get Control Register
\r
327 This function returns the content of the Control Register.
\r
329 \return Control Register value
\r
331 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_CONTROL(void)
\r
335 __ASM volatile ("MRS %0, control" : "=r" (result) );
\r
340 /** \brief Set Control Register
\r
342 This function writes the given value to the Control Register.
\r
344 \param [in] control Control Register value to set
\r
346 __attribute__( ( always_inline ) ) static __INLINE void __set_CONTROL(uint32_t control)
\r
348 __ASM volatile ("MSR control, %0" : : "r" (control) );
\r
352 /** \brief Get ISPR Register
\r
354 This function returns the content of the ISPR Register.
\r
356 \return ISPR Register value
\r
358 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_IPSR(void)
\r
362 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
\r
367 /** \brief Get APSR Register
\r
369 This function returns the content of the APSR Register.
\r
371 \return APSR Register value
\r
373 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_APSR(void)
\r
377 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
\r
382 /** \brief Get xPSR Register
\r
384 This function returns the content of the xPSR Register.
\r
386 \return xPSR Register value
\r
388 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_xPSR(void)
\r
392 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
\r
397 /** \brief Get Process Stack Pointer
\r
399 This function returns the current value of the Process Stack Pointer (PSP).
\r
401 \return PSP Register value
\r
403 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_PSP(void)
\r
405 register uint32_t result;
\r
407 __ASM volatile ("MRS %0, psp\n" : "=r" (result) );
\r
412 /** \brief Set Process Stack Pointer
\r
414 This function assigns the given value to the Process Stack Pointer (PSP).
\r
416 \param [in] topOfProcStack Process Stack Pointer value to set
\r
418 __attribute__( ( always_inline ) ) static __INLINE void __set_PSP(uint32_t topOfProcStack)
\r
420 __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) );
\r
424 /** \brief Get Main Stack Pointer
\r
426 This function returns the current value of the Main Stack Pointer (MSP).
\r
428 \return MSP Register value
\r
430 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_MSP(void)
\r
432 register uint32_t result;
\r
434 __ASM volatile ("MRS %0, msp\n" : "=r" (result) );
\r
439 /** \brief Set Main Stack Pointer
\r
441 This function assigns the given value to the Main Stack Pointer (MSP).
\r
443 \param [in] topOfMainStack Main Stack Pointer value to set
\r
445 __attribute__( ( always_inline ) ) static __INLINE void __set_MSP(uint32_t topOfMainStack)
\r
447 __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) );
\r
451 /** \brief Get Priority Mask
\r
453 This function returns the current state of the priority mask bit from the Priority Mask Register.
\r
455 \return Priority Mask value
\r
457 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_PRIMASK(void)
\r
461 __ASM volatile ("MRS %0, primask" : "=r" (result) );
\r
466 /** \brief Set Priority Mask
\r
468 This function assigns the given value to the Priority Mask Register.
\r
470 \param [in] priMask Priority Mask
\r
472 __attribute__( ( always_inline ) ) static __INLINE void __set_PRIMASK(uint32_t priMask)
\r
474 __ASM volatile ("MSR primask, %0" : : "r" (priMask) );
\r
478 #if (__CORTEX_M >= 0x03)
\r
480 /** \brief Enable FIQ
\r
482 This function enables FIQ interrupts by clearing the F-bit in the CPSR.
\r
483 Can only be executed in Privileged modes.
\r
485 __attribute__( ( always_inline ) ) static __INLINE void __enable_fault_irq(void)
\r
487 __ASM volatile ("cpsie f");
\r
491 /** \brief Disable FIQ
\r
493 This function disables FIQ interrupts by setting the F-bit in the CPSR.
\r
494 Can only be executed in Privileged modes.
\r
496 __attribute__( ( always_inline ) ) static __INLINE void __disable_fault_irq(void)
\r
498 __ASM volatile ("cpsid f");
\r
502 /** \brief Get Base Priority
\r
504 This function returns the current value of the Base Priority register.
\r
506 \return Base Priority register value
\r
508 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_BASEPRI(void)
\r
512 __ASM volatile ("MRS %0, basepri_max" : "=r" (result) );
\r
517 /** \brief Set Base Priority
\r
519 This function assigns the given value to the Base Priority register.
\r
521 \param [in] basePri Base Priority value to set
\r
523 __attribute__( ( always_inline ) ) static __INLINE void __set_BASEPRI(uint32_t value)
\r
525 __ASM volatile ("MSR basepri, %0" : : "r" (value) );
\r
529 /** \brief Get Fault Mask
\r
531 This function returns the current value of the Fault Mask register.
\r
533 \return Fault Mask register value
\r
535 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_FAULTMASK(void)
\r
539 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
\r
544 /** \brief Set Fault Mask
\r
546 This function assigns the given value to the Fault Mask register.
\r
548 \param [in] faultMask Fault Mask value to set
\r
550 __attribute__( ( always_inline ) ) static __INLINE void __set_FAULTMASK(uint32_t faultMask)
\r
552 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) );
\r
555 #endif /* (__CORTEX_M >= 0x03) */
\r
558 #if (__CORTEX_M == 0x04)
\r
560 /** \brief Get FPSCR
\r
562 This function returns the current value of the Floating Point Status/Control register.
\r
564 \return Floating Point Status/Control register value
\r
566 __attribute__( ( always_inline ) ) static __INLINE uint32_t __get_FPSCR(void)
\r
568 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
571 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
\r
579 /** \brief Set FPSCR
\r
581 This function assigns the given value to the Floating Point Status/Control register.
\r
583 \param [in] fpscr Floating Point Status/Control value to set
\r
585 __attribute__( ( always_inline ) ) static __INLINE void __set_FPSCR(uint32_t fpscr)
\r
587 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
\r
588 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) );
\r
592 #endif /* (__CORTEX_M == 0x04) */
\r
595 #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/
\r
596 /* TASKING carm specific functions */
\r
599 * The CMSIS functions have been implemented as intrinsics in the compiler.
\r
600 * Please use "carm -?i" to get an up to date list of all instrinsics,
\r
601 * Including the CMSIS ones.
\r
606 /*@} end of CMSIS_Core_RegAccFunctions */
\r
609 #endif /* __CORE_CMFUNC_H */
\r