Skip to content

Commit 5c580a4

Browse files
committed
make compatible with existing interrupt lock class
Support both the normal auto lock at all levels, and the lock at a specific level requiring different syntax
1 parent af204f9 commit 5c580a4

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

hardware/esp8266com/esp8266/cores/esp8266/Arduino.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,6 @@ void ets_intr_unlock();
160160
#define interrupts() xt_rsil(0)
161161
#define noInterrupts() xt_rsil(15)
162162

163-
// this auto class wraps up xt_rsil so your code can be simplier, but can only be
164-
// used in an ino or cpp files. A normal use pattern is like
165-
//
166-
//{
167-
// {
168-
// InterruptLock(1); // this routine will allow level 2 and above
169-
// // do work within interrupt lock here
170-
// }
171-
// do work outside of interrupt lock here outside its scope
172-
//}
173-
//
174-
#define InterruptLock(intrLevel) \
175-
class _AutoDisableIntr { \
176-
public: \
177-
_AutoDisableIntr() { _savedPS = xt_rsil(intrLevel); } \
178-
~_AutoDisableIntr() { xt_wsr_ps(_savedPS); } \
179-
private: \
180-
uint32_t _savedPS; \
181-
}; \
182-
_AutoDisableIntr _autoDisableIntr
183-
184163

185164
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
186165
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )

hardware/esp8266com/esp8266/cores/esp8266/interrupts.h

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,51 @@ extern "C" {
88
#include "ets_sys.h"
99
}
1010

11-
12-
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state))
13-
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
11+
// these auto classes wrap up xt_rsil so your code can be simplier, but can only be
12+
// used in an ino or cpp files.
13+
14+
// InterruptLock is used when you want to completely disable locks
15+
//{
16+
// {
17+
// InterruptLock lock;
18+
// // do work within interrupt lock here
19+
// }
20+
// do work outside of interrupt lock here outside its scope
21+
//}
22+
//
1423

1524
class InterruptLock {
1625
public:
1726
InterruptLock() {
18-
xt_disable_interrupts(_state, 15);
27+
_state = = xt_rsil(15);
1928
}
2029

2130
~InterruptLock() {
22-
xt_enable_interrupts(_state);
31+
xt_wsr_ps(_state);
2332
}
2433

2534
protected:
2635
uint32_t _state;
2736
};
2837

38+
// AutoInterruptLock is when you need to set a specific level, A normal use pattern is like
39+
//
40+
//{
41+
// {
42+
// AutoInterruptLock(1); // this routine will allow level 2 and above
43+
// // do work within interrupt lock here
44+
// }
45+
// do work outside of interrupt lock here outside its scope
46+
//}
47+
//
48+
#define AutoInterruptLock(intrLevel) \
49+
class _AutoDisableIntr { \
50+
public: \
51+
_AutoDisableIntr() { _savedPS = xt_rsil(intrLevel); } \
52+
~_AutoDisableIntr() { xt_wsr_ps(_savedPS); } \
53+
private: \
54+
uint32_t _savedPS; \
55+
}; \
56+
_AutoDisableIntr _autoDisableIntr
2957

3058
#endif //INTERRUPTS_H

0 commit comments

Comments
 (0)