Skip to content

Commit 7e15659

Browse files
committed
Merge pull request #200 from Makuna/esp8266
true noInterrupts() interrupts() support
2 parents 5969f56 + 9977276 commit 7e15659

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

cores/esp8266/Arduino.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,17 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607
124124
void ets_intr_lock();
125125
void ets_intr_unlock();
126126

127-
#define interrupts() ets_intr_unlock();
128-
#define noInterrupts() ets_intr_lock();
127+
// level (0-15),
128+
// level 15 will disable ALL interrupts,
129+
// level 0 will disable most software interrupts
130+
//
131+
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
132+
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory")
133+
134+
extern uint32_t interruptsState;
135+
136+
#define interrupts() xt_enable_interrupts(interruptsState)
137+
#define noInterrupts() xt_disable_interrupts(interruptsState, 15)
129138

130139
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
131140
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )

cores/esp8266/Esp.h

+8
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,16 @@ class EspClass {
9595
FlashMode_t getFlashChipMode(void);
9696
uint32_t getFlashChipSizeByChipId(void);
9797

98+
inline uint32_t getCycleCount(void);
9899
};
99100

101+
uint32_t EspClass::getCycleCount(void)
102+
{
103+
uint32_t ccount;
104+
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
105+
return ccount;
106+
}
107+
100108
extern EspClass ESP;
101109

102110
#endif //ESP_H

cores/esp8266/core_esp8266_wiring_digital.c

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ extern void __detachInterrupt(uint8_t pin) {
139139
}
140140
}
141141

142+
// stored state for the noInterrupts/interrupts methods
143+
uint32_t interruptsState = 0;
144+
142145
void initPins() {
143146
//Disable UART interrupts
144147
system_set_os_print(0);

0 commit comments

Comments
 (0)