38 #ifndef __CORE_CMFUNC_H
39 #define __CORE_CMFUNC_H
48 #if defined ( __CC_ARM )
51 #if (__ARMCC_VERSION < 400677)
52 #error "Please use ARM Compiler Toolchain V4.0.677 or later!"
64 __STATIC_INLINE uint32_t __get_CONTROL(
void)
66 register uint32_t __regControl __ASM(
"control");
77 __STATIC_INLINE
void __set_CONTROL(uint32_t control)
79 register uint32_t __regControl __ASM(
"control");
80 __regControl = control;
90 __STATIC_INLINE uint32_t __get_IPSR(
void)
92 register uint32_t __regIPSR __ASM(
"ipsr");
103 __STATIC_INLINE uint32_t __get_APSR(
void)
105 register uint32_t __regAPSR __ASM(
"apsr");
116 __STATIC_INLINE uint32_t __get_xPSR(
void)
118 register uint32_t __regXPSR __ASM(
"xpsr");
129 __STATIC_INLINE uint32_t __get_PSP(
void)
131 register uint32_t __regProcessStackPointer __ASM(
"psp");
132 return(__regProcessStackPointer);
142 __STATIC_INLINE
void __set_PSP(uint32_t topOfProcStack)
144 register uint32_t __regProcessStackPointer __ASM(
"psp");
145 __regProcessStackPointer = topOfProcStack;
155 __STATIC_INLINE uint32_t __get_MSP(
void)
157 register uint32_t __regMainStackPointer __ASM(
"msp");
158 return(__regMainStackPointer);
168 __STATIC_INLINE
void __set_MSP(uint32_t topOfMainStack)
170 register uint32_t __regMainStackPointer __ASM(
"msp");
171 __regMainStackPointer = topOfMainStack;
181 __STATIC_INLINE uint32_t __get_PRIMASK(
void)
183 register uint32_t __regPriMask __ASM(
"primask");
184 return(__regPriMask);
194 __STATIC_INLINE
void __set_PRIMASK(uint32_t priMask)
196 register uint32_t __regPriMask __ASM(
"primask");
197 __regPriMask = (priMask);
201 #if (__CORTEX_M >= 0x03)
208 #define __enable_fault_irq __enable_fiq
216 #define __disable_fault_irq __disable_fiq
225 __STATIC_INLINE uint32_t __get_BASEPRI(
void)
227 register uint32_t __regBasePri __ASM(
"basepri");
228 return(__regBasePri);
238 __STATIC_INLINE
void __set_BASEPRI(uint32_t basePri)
240 register uint32_t __regBasePri __ASM(
"basepri");
241 __regBasePri = (basePri & 0xff);
251 __STATIC_INLINE uint32_t __get_FAULTMASK(
void)
253 register uint32_t __regFaultMask __ASM(
"faultmask");
254 return(__regFaultMask);
264 __STATIC_INLINE
void __set_FAULTMASK(uint32_t faultMask)
266 register uint32_t __regFaultMask __ASM(
"faultmask");
267 __regFaultMask = (faultMask & (uint32_t)1);
273 #if (__CORTEX_M == 0x04)
281 __STATIC_INLINE uint32_t __get_FPSCR(
void)
283 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
284 register uint32_t __regfpscr __ASM(
"fpscr");
298 __STATIC_INLINE
void __set_FPSCR(uint32_t fpscr)
300 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
301 register uint32_t __regfpscr __ASM(
"fpscr");
302 __regfpscr = (fpscr);
309 #elif defined ( __ICCARM__ )
312 #include <cmsis_iar.h>
315 #elif defined ( __TMS470__ )
318 #include <cmsis_ccs.h>
321 #elif defined ( __GNUC__ )
329 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __enable_irq(
void)
331 __ASM
volatile (
"cpsie i" : : :
"memory");
340 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __disable_irq(
void)
342 __ASM
volatile (
"cpsid i" : : :
"memory");
352 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(
void)
356 __ASM
volatile (
"MRS %0, control" :
"=r" (result) );
367 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_CONTROL(uint32_t control)
369 __ASM
volatile (
"MSR control, %0" : :
"r" (control) :
"memory");
379 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(
void)
383 __ASM
volatile (
"MRS %0, ipsr" :
"=r" (result) );
394 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(
void)
398 __ASM
volatile (
"MRS %0, apsr" :
"=r" (result) );
409 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(
void)
413 __ASM
volatile (
"MRS %0, xpsr" :
"=r" (result) );
424 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(
void)
426 register uint32_t result;
428 __ASM
volatile (
"MRS %0, psp\n" :
"=r" (result) );
439 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_PSP(uint32_t topOfProcStack)
441 __ASM
volatile (
"MSR psp, %0\n" : :
"r" (topOfProcStack) :
"sp");
451 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(
void)
453 register uint32_t result;
455 __ASM
volatile (
"MRS %0, msp\n" :
"=r" (result) );
466 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_MSP(uint32_t topOfMainStack)
468 __ASM
volatile (
"MSR msp, %0\n" : :
"r" (topOfMainStack) :
"sp");
478 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(
void)
482 __ASM
volatile (
"MRS %0, primask" :
"=r" (result) );
493 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_PRIMASK(uint32_t priMask)
495 __ASM
volatile (
"MSR primask, %0" : :
"r" (priMask) :
"memory");
499 #if (__CORTEX_M >= 0x03)
506 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __enable_fault_irq(
void)
508 __ASM
volatile (
"cpsie f" : : :
"memory");
517 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __disable_fault_irq(
void)
519 __ASM
volatile (
"cpsid f" : : :
"memory");
529 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(
void)
533 __ASM
volatile (
"MRS %0, basepri_max" :
"=r" (result) );
544 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_BASEPRI(uint32_t value)
546 __ASM
volatile (
"MSR basepri, %0" : :
"r" (value) :
"memory");
556 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(
void)
560 __ASM
volatile (
"MRS %0, faultmask" :
"=r" (result) );
571 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_FAULTMASK(uint32_t faultMask)
573 __ASM
volatile (
"MSR faultmask, %0" : :
"r" (faultMask) :
"memory");
579 #if (__CORTEX_M == 0x04)
587 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(
void)
589 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
594 __ASM
volatile (
"VMRS %0, fpscr" :
"=r" (result) );
609 __attribute__( ( always_inline ) ) __STATIC_INLINE
void __set_FPSCR(uint32_t fpscr)
611 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
614 __ASM
volatile (
"VMSR fpscr, %0" : :
"r" (fpscr) :
"vfpcc");
622 #elif defined ( __TASKING__ )