diff options
Diffstat (limited to 'ports')
-rw-r--r-- | ports/ARM7/chcore.h | 27 | ||||
-rw-r--r-- | ports/ARM7/chsys.s | 20 | ||||
-rw-r--r-- | ports/ARMCM3/chcore.h | 4 | ||||
-rw-r--r-- | ports/AVR/chcore.h | 2 | ||||
-rw-r--r-- | ports/MSP430/chcore.h | 3 |
5 files changed, 47 insertions, 9 deletions
diff --git a/ports/ARM7/chcore.h b/ports/ARM7/chcore.h index 4f8e187cc..557526863 100644 --- a/ports/ARM7/chcore.h +++ b/ports/ARM7/chcore.h @@ -79,14 +79,33 @@ typedef struct { #ifdef __cplusplus
extern "C" {
#endif
- void chSysLock(void);
- void chSysUnlock(void);
+ uint32_t _lock(void);
+ void _unlock(uint32_t);
+ void _enable(void);
#ifdef __cplusplus
}
#endif
+#ifdef REENTRANT_LOCKS
+#define chSysLock() uint32_t ps = _lock()
+#define chSysUnlock() _unlock(ps)
+#else
+#define chSysLock() _lock()
+#define chSysUnlock() _enable()
+#endif /* !REENTRANT_LOCKS */
+#define chSysEnable() _enable()
#else /* !THUMB */
-#define chSysLock() asm("msr CPSR_c, #0x9F")
-#define chSysUnlock() asm("msr CPSR_c, #0x1F")
+#ifdef REENTRANT_LOCKS
+#define chSysLock() \
+ uint32_t ps; \
+ asm volatile ("mrs %0, CPSR" : "=r" (ps) : ); \
+ asm volatile ("msr CPSR_c, #0x9F");
+#define chSysUnlock() asm volatile ("msr CPSR_c, %0" : : "r" (ps))
+#define chSysEnable() asm volatile ("msr CPSR_c, #0x1F")
+#else
+#define chSysLock() asm volatile ("msr CPSR_c, #0x9F");
+#define chSysUnlock() asm volatile ("msr CPSR_c, #0x1F")
+#define chSysEnable() asm volatile ("msr CPSR_c, #0x1F")
+#endif /* !REENTRANT_LOCKS */
#endif /* THUMB */
#ifdef THUMB
diff --git a/ports/ARM7/chsys.s b/ports/ARM7/chsys.s index d1de7d100..8af9e4b4e 100644 --- a/ports/ARM7/chsys.s +++ b/ports/ARM7/chsys.s @@ -44,19 +44,31 @@ .balign 16
.code 16
.thumb_func
-.global chSysLock
-chSysLock:
+.global _lock
+_lock:
mov r0, pc
bx r0
.code 32
+ mrs r0, CPSR
msr CPSR_c, #MODE_SYS | I_BIT
bx lr
.balign 16
.code 16
.thumb_func
-.global chSysUnlock
-chSysUnlock:
+.global _unlock
+_unlock:
+ mov r1, pc
+ bx r1
+.code 32
+ msr CPSR_c, r0
+ bx lr
+
+.balign 16
+.code 16
+.thumb_func
+.global _enable
+_enable:
mov r0, pc
bx r0
.code 32
diff --git a/ports/ARMCM3/chcore.h b/ports/ARMCM3/chcore.h index 1e451dfc7..0f07ba369 100644 --- a/ports/ARMCM3/chcore.h +++ b/ports/ARMCM3/chcore.h @@ -97,6 +97,10 @@ typedef struct { register uint32_t tmp asm ("r3") = BASEPRI_USER; \ asm volatile ("msr BASEPRI, %0" : : "r" (tmp)); \ } +#define chSysEnable() { \ + register uint32_t tmp asm ("r3") = BASEPRI_USER; \ + asm volatile ("msr BASEPRI, %0" : : "r" (tmp)); \ +} #define chSysSwitchI(otp, ntp) { \ register Thread *_otp asm ("r0") = (otp); \ register Thread *_ntp asm ("r1") = (ntp); \ diff --git a/ports/AVR/chcore.h b/ports/AVR/chcore.h index cb2920a2d..fe0f13e1f 100644 --- a/ports/AVR/chcore.h +++ b/ports/AVR/chcore.h @@ -108,6 +108,8 @@ typedef struct { #define chSysUnlock() asm volatile ("sei")
+#define chSysEnable() asm volatile ("sei")
+
#define chSysIRQEnterI() \
asm ("" : : : "r18", "r19", "r20", "r21", "r22", "r23", "r24", \
"r25", "r26", "r27", "r30", "r31");
diff --git a/ports/MSP430/chcore.h b/ports/MSP430/chcore.h index 3a9d587b8..0d07204d2 100644 --- a/ports/MSP430/chcore.h +++ b/ports/MSP430/chcore.h @@ -81,10 +81,11 @@ typedef struct { #define chSysLock() asm volatile ("dint")
#define chSysUnlock() asm volatile ("eint")
+#define chSysEnable() asm volatile ("eint")
#define chSysIRQEnterI()
#define chSysIRQExitI() { \
- if (chSchRescRequiredI()) \
+ if (chSchRescRequiredI()) \
chSchDoRescheduleI(); \
}
|