24 #ifndef __CORE_CMFUNC_H
25 #define __CORE_CMFUNC_H
34 #if defined ( __CC_ARM )
37 #if (__ARMCC_VERSION < 400677)
38 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
50 __STATIC_INLINE
uint32_t __get_CONTROL(
void)
52 register uint32_t __regControl __ASM(
"control");
63 __STATIC_INLINE
void __set_CONTROL(
uint32_t control)
65 register uint32_t __regControl __ASM(
"control");
66 __regControl = control;
76 __STATIC_INLINE
uint32_t __get_IPSR(
void)
78 register uint32_t __regIPSR __ASM(
"ipsr");
89 __STATIC_INLINE
uint32_t __get_APSR(
void)
91 register uint32_t __regAPSR __ASM(
"apsr");
102 __STATIC_INLINE
uint32_t __get_xPSR(
void)
104 register uint32_t __regXPSR __ASM(
"xpsr");
115 __STATIC_INLINE
uint32_t __get_PSP(
void)
117 register uint32_t __regProcessStackPointer __ASM(
"psp");
118 return(__regProcessStackPointer);
128 __STATIC_INLINE
void __set_PSP(
uint32_t topOfProcStack)
130 register uint32_t __regProcessStackPointer __ASM(
"psp");
131 __regProcessStackPointer = topOfProcStack;
141 __STATIC_INLINE
uint32_t __get_MSP(
void)
143 register uint32_t __regMainStackPointer __ASM(
"msp");
144 return(__regMainStackPointer);
154 __STATIC_INLINE
void __set_MSP(
uint32_t topOfMainStack)
156 register uint32_t __regMainStackPointer __ASM(
"msp");
157 __regMainStackPointer = topOfMainStack;
167 __STATIC_INLINE
uint32_t __get_PRIMASK(
void)
169 register uint32_t __regPriMask __ASM(
"primask");
170 return(__regPriMask);
180 __STATIC_INLINE
void __set_PRIMASK(
uint32_t priMask)
182 register uint32_t __regPriMask __ASM(
"primask");
183 __regPriMask = (priMask);
187 #if (__CORTEX_M >= 0x03)
194 #define __enable_fault_irq __enable_fiq
202 #define __disable_fault_irq __disable_fiq
211 __STATIC_INLINE
uint32_t __get_BASEPRI(
void)
213 register uint32_t __regBasePri __ASM(
"basepri");
214 return(__regBasePri);
224 __STATIC_INLINE
void __set_BASEPRI(
uint32_t basePri)
226 register uint32_t __regBasePri __ASM(
"basepri");
227 __regBasePri = (basePri & 0xff);
237 __STATIC_INLINE
uint32_t __get_FAULTMASK(
void)
239 register uint32_t __regFaultMask __ASM(
"faultmask");
240 return(__regFaultMask);
250 __STATIC_INLINE
void __set_FAULTMASK(
uint32_t faultMask)
252 register uint32_t __regFaultMask __ASM(
"faultmask");
253 __regFaultMask = (faultMask & (
uint32_t)1);
259 #if (__CORTEX_M == 0x04)
267 __STATIC_INLINE
uint32_t __get_FPSCR(
void)
269 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
270 register uint32_t __regfpscr __ASM(
"fpscr");
284 __STATIC_INLINE
void __set_FPSCR(
uint32_t fpscr)
286 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
287 register uint32_t __regfpscr __ASM(
"fpscr");
288 __regfpscr = (fpscr);
295 #elif defined ( __ICCARM__ )
298 #include <cmsis_iar.h>
301 #elif defined ( __TMS470__ )
304 #include <cmsis_ccs.h>
307 #elif defined ( __GNUC__ )
315 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __enable_irq(
void)
317 __ASM
volatile (
"cpsie i" : : :
"memory");
326 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __disable_irq(
void)
328 __ASM
volatile (
"cpsid i" : : :
"memory");
338 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_CONTROL(
void)
342 __ASM
volatile (
"MRS %0, control" :
"=r" (result) );
353 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_CONTROL(
uint32_t control)
355 __ASM
volatile (
"MSR control, %0" : :
"r" (control) );
365 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_IPSR(
void)
369 __ASM
volatile (
"MRS %0, ipsr" :
"=r" (result) );
380 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_APSR(
void)
384 __ASM
volatile (
"MRS %0, apsr" :
"=r" (result) );
395 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_xPSR(
void)
399 __ASM
volatile (
"MRS %0, xpsr" :
"=r" (result) );
410 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_PSP(
void)
414 __ASM
volatile (
"MRS %0, psp\n" :
"=r" (result) );
425 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_PSP(
uint32_t topOfProcStack)
427 __ASM
volatile (
"MSR psp, %0\n" : :
"r" (topOfProcStack) );
437 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_MSP(
void)
441 __ASM
volatile (
"MRS %0, msp\n" :
"=r" (result) );
452 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_MSP(
uint32_t topOfMainStack)
454 __ASM
volatile (
"MSR msp, %0\n" : :
"r" (topOfMainStack) );
464 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_PRIMASK(
void)
468 __ASM
volatile (
"MRS %0, primask" :
"=r" (result) );
479 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_PRIMASK(
uint32_t priMask)
481 __ASM
volatile (
"MSR primask, %0" : :
"r" (priMask) );
485 #if (__CORTEX_M >= 0x03)
492 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __enable_fault_irq(
void)
494 __ASM
volatile (
"cpsie f" : : :
"memory");
503 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __disable_fault_irq(
void)
505 __ASM
volatile (
"cpsid f" : : :
"memory");
515 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_BASEPRI(
void)
519 __ASM
volatile (
"MRS %0, basepri_max" :
"=r" (result) );
530 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_BASEPRI(
uint32_t value)
532 __ASM
volatile (
"MSR basepri, %0" : :
"r" (
value) );
542 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_FAULTMASK(
void)
546 __ASM
volatile (
"MRS %0, faultmask" :
"=r" (result) );
557 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_FAULTMASK(
uint32_t faultMask)
559 __ASM
volatile (
"MSR faultmask, %0" : :
"r" (faultMask) );
565 #if (__CORTEX_M == 0x04)
573 __attribute__( ( always_inline ) ) __STATIC_INLINE
uint32_t __get_FPSCR(
void)
575 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
578 __ASM
volatile (
"VMRS %0, fpscr" :
"=r" (result) );
592 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_FPSCR(
uint32_t fpscr)
594 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
595 __ASM
volatile (
"VMSR fpscr, %0" : :
"r" (fpscr) );
602 #elif defined ( __TASKING__ )