@@ -312,7 +312,14 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
312
312
waveform.nextEventCcy = isrStartCcy + MAXIRQTICKSCCYS;
313
313
}
314
314
315
+ uint32_t now = ESP.getCycleCount ();
316
+ uint32_t isrNextEventCcy = now;
315
317
while (busyPins) {
318
+ if (static_cast <int32_t >(isrNextEventCcy - now) > IRQLATENCYCCYS + DELTAIRQCCYS) {
319
+ waveform.nextEventCcy = isrNextEventCcy;
320
+ break ;
321
+ }
322
+ isrNextEventCcy = waveform.nextEventCcy ;
316
323
for (int pin = waveform.startPin ; pin <= waveform.endPin ; ++pin) {
317
324
const uint32_t pinBit = 1UL << pin;
318
325
// If it's not on, ignore
@@ -322,7 +329,6 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
322
329
Waveform& wave = waveform.pins [pin];
323
330
324
331
uint32_t waveNextEventCcy = (waveform.states & pinBit) ? wave.endDutyCcy : wave.nextPeriodCcy ;
325
- const uint32_t now = ESP.getCycleCount ();
326
332
if (WaveformMode::EXPIRES == wave.mode &&
327
333
static_cast <int32_t >(waveNextEventCcy - wave.expiryCcy ) >= 0 &&
328
334
static_cast <int32_t >(now - wave.expiryCcy ) >= 0 ) {
@@ -396,15 +402,19 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
396
402
waveform.nextEventCcy = waveNextEventCcy;
397
403
}
398
404
}
405
+ else if (static_cast <int32_t >(isrNextEventCcy - waveNextEventCcy) > 0 ) {
406
+ isrNextEventCcy = waveNextEventCcy;
407
+ }
399
408
}
409
+ now = ESP.getCycleCount ();
400
410
}
401
411
}
402
412
403
413
int32_t callbackCcys = 0 ;
404
414
if (waveform.timer1CB ) {
405
415
callbackCcys = scaleCcys (microsecondsToClockCycles (waveform.timer1CB ()));
406
416
}
407
- const uint32_t now = ESP.getCycleCount ();
417
+ now = ESP.getCycleCount ();
408
418
int32_t nextTimerCcys = waveform.nextEventCcy - now;
409
419
// Account for unknown duration of timer1CB().
410
420
if (waveform.timer1CB && nextTimerCcys > callbackCcys) {
0 commit comments