@@ -51,8 +51,7 @@ constexpr int32_t MAXIRQTICKSCCYS = microsecondsToClockCycles(10000);
51
51
// Maximum servicing time for any single IRQ
52
52
constexpr uint32_t ISRTIMEOUTCCYS = microsecondsToClockCycles(18 );
53
53
// The latency between in-ISR rearming of the timer and the earliest firing
54
- constexpr int32_t IRQLATENCYCCYS = ISCPUFREQ160MHZ ?
55
- microsecondsToClockCycles (2 ) >> 1 : microsecondsToClockCycles(2 );
54
+ constexpr int32_t IRQLATENCYCCYS = microsecondsToClockCycles(2 );
56
55
// The SDK and hardware take some time to actually get to our NMI code
57
56
constexpr int32_t DELTAIRQCCYS = ISCPUFREQ160MHZ ?
58
57
microsecondsToClockCycles (2 ) >> 1 : microsecondsToClockCycles(2 );
@@ -256,7 +255,7 @@ static inline ICACHE_RAM_ATTR int32_t scaleCcys(const int32_t ccys, const bool i
256
255
257
256
static ICACHE_RAM_ATTR void timer1Interrupt () {
258
257
const uint32_t isrStartCcy = ESP.getCycleCount ();
259
- int32_t clockDrift = isrStartCcy - waveform.nextEventCcy - DELTAIRQCCYS ;
258
+ int32_t clockDrift = isrStartCcy - waveform.nextEventCcy ;
260
259
const bool isCPU2X = CPU2X & 1 ;
261
260
if ((waveform.toSetBits && !(waveform.enabled & waveform.toSetBits )) || waveform.toDisableBits ) {
262
261
// Handle enable/disable requests from main app.
@@ -415,14 +414,21 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
415
414
}
416
415
417
416
// Timer is 80MHz fixed. 160MHz CPU frequency need scaling.
417
+ int32_t deltaIrqCcys = DELTAIRQCCYS;
418
+ int32_t irqLatencyCcys = IRQLATENCYCCYS;
418
419
if (isCPU2X) {
419
420
nextEventCcys >>= 1 ;
421
+ deltaIrqCcys >>= 1 ;
422
+ irqLatencyCcys >>= 1 ;
420
423
}
421
424
422
425
// Firing timer too soon, the NMI occurs before ISR has returned.
423
- if (nextEventCcys < IRQLATENCYCCYS) {
424
- waveform.nextEventCcy = now + IRQLATENCYCCYS;
425
- nextEventCcys = IRQLATENCYCCYS;
426
+ if (nextEventCcys < irqLatencyCcys + deltaIrqCcys) {
427
+ waveform.nextEventCcy = now + IRQLATENCYCCYS + DELTAIRQCCYS;
428
+ nextEventCcys = irqLatencyCcys;
429
+ }
430
+ else {
431
+ nextEventCcys -= deltaIrqCcys;
426
432
}
427
433
428
434
// Register access is fast and edge IRQ was configured before.
0 commit comments