8000 Dynamically map pins out from in-ISR handling based on next event tim… · dok-net/arduino-esp8266@25c625d · GitHub
[go: up one dir, main page]

Skip to content

Commit 25c625d

Browse files
committed
Dynamically map pins out from in-ISR handling based on next event timing.
Major performance boost.
1 parent cc10ceb commit 25c625d

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

cores/esp8266/core_esp8266_waveform.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -294,29 +294,26 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
294294

295295
// Exit the loop if the next event, if any, is sufficiently distant.
296296
const uint32_t isrTimeoutCcy = isrStartCcy + ISRTIMEOUTCCYS;
297-
bool busy;
298-
if (!waveform.enabled) {
299-
busy = false;
300-
waveform.nextEventCcy = ESP.getCycleCount() + MAXIRQTICKSCCYS;
301-
}
302-
else {
303-
busy = static_cast<int32_t>(isrTimeoutCcy - waveform.nextEventCcy) > 0;
297+
uint32_t busyPins = waveform.enabled;
298+
if (busyPins) {
299+
if (static_cast<int32_t>(waveform.nextEventCcy - isrTimeoutCcy) >= 0) {
300+
busyPins = 0;
301+
}
302+
else {
303+
waveform.nextEventCcy = ESP.getCycleCount() + MAXIRQTICKSCCYS;
304+
}
304305
if (!(waveform.enabled & (1UL << waveform.nextPin))) {
305306
waveform.nextPin = waveform.startPin;
306307
}
307308
}
308-
while (busy) {
309+
while (busyPins) {
309310
int stopPin = waveform.nextPin;
310311
int pin = waveform.nextPin;
311-
uint32_t now;
312-
do {
313-
now = ESP.getCycleCount();
314-
} while (static_cast<int32_t>(waveform.nextEventCcy - now) > 0);
315-
waveform.nextEventCcy = now + MAXIRQTICKSCCYS;
312+
uint32_t now = ESP.getCycleCount();
316313

317314
do {
318315
// If it's not on, ignore
319-
if (!(waveform.enabled & (1UL << pin)))
316+
if (!(busyPins & (1UL << pin)))
320317
continue;
321318

322319
Waveform& wave = waveform.pins[pin];
@@ -325,7 +322,8 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
325322
if (static_cast<int32_t>(overshootCcys) >= 0) {
326323
if (WaveformMode::EXPIRES == wave.mode && wave.nextEventCcy == wave.expiryCcy) {
327324
// Disable any waveforms that are done
328-
waveform.enabled ^= 1UL << pin;
325+
waveform.enabled &= ~(1UL << pin);
326+
busyPins &= ~(1UL << pin);
329327
}
330328
else {
331329
const uint32_t fwdPeriods = (overshootCcys + wave.dutyCcys) / wave.periodCcys;
@@ -408,14 +406,16 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
408406
}
409407
}
410408

411-
// join events below performance threshold apart
412-
if (static_cast<int32_t>(waveform.nextEventCcy - wave.nextEventCcy) > IRQLATENCYCCYS) {
413-
waveform.nextEventCcy = wave.nextEventCcy;
414-
waveform.nextPin = pin;
409+
if (static_cast<int32_t>(wave.nextEventCcy - isrTimeoutCcy) >= 0) {
410+
busyPins &= ~(1UL << pin);
411+
// join events below performance threshold apart
412+
if (static_cast<int32_t>(waveform.nextEventCcy - wave.nextEventCcy) > IRQLATENCYCCYS) {
413+
waveform.nextEventCcy = wave.nextEventCcy;
414+
waveform.nextPin = pin;
415+
}
415416
}
416-
} while ((pin = (pin < waveform.endPin) ? pin + 1 : waveform.startPin, pin != stopPin));
417417

418-
busy = static_cast<int32_t>(isrTimeoutCcy - waveform.nextEventCcy) > 0;
418+
} while ((pin = (pin < waveform.endPin) ? pin + 1 : waveform.startPin) != stopPin);
419419
}
420420

421421
int32_t nextTimerCcys;

0 commit comments

Comments
 (0)
0