|
48 | 48 | constexpr int32_t MAXIRQTICKSCCYS = microsecondsToClockCycles(10000); |
49 | 49 | // Maximum servicing time for any single IRQ |
50 | 50 | constexpr uint32_t ISRTIMEOUTCCYS = microsecondsToClockCycles(18); |
51 | | -// The SDK and hardware take some time to actually get to our NMI code, so |
52 | | -// decrement the next IRQ's timer value by a bit so we can actually catch the |
53 | | -// real CPU cycle count we want for the waveforms. |
54 | | -constexpr int32_t DELTAIRQCCYS = clockCyclesPerMicrosecond() == 160 ? |
55 | | - microsecondsToClockCycles(1) >> 1 : microsecondsToClockCycles(1); |
56 | 51 | // The latency between in-ISR rearming of the timer and the earliest firing |
57 | 52 | constexpr int32_t IRQLATENCYCCYS = clockCyclesPerMicrosecond() == 160 ? |
58 | 53 | microsecondsToClockCycles(1) >> 1 : microsecondsToClockCycles(1); |
@@ -187,7 +182,7 @@ int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys, |
187 | 182 | if (!waveform.timer1Running) { |
188 | 183 | initTimer(); |
189 | 184 | } |
190 | | - else if (T1V > ((clockCyclesPerMicrosecond() == 160) ? (IRQLATENCYCCYS + DELTAIRQCCYS) >> 1 : IRQLATENCYCCYS + DELTAIRQCCYS)) { |
| 185 | + else if (T1V > ((clockCyclesPerMicrosecond() == 160) ? IRQLATENCYCCYS >> 1 : IRQLATENCYCCYS)) { |
191 | 186 | // Must not interfere if Timer is due shortly |
192 | 187 | timer1_write(IRQLATENCYCCYS); |
193 | 188 | } |
@@ -224,7 +219,7 @@ int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) { |
224 | 219 | waveform.toDisableBits = 1UL << pin; |
225 | 220 | std::atomic_thread_fence(std::memory_order_release); |
226 | 221 | // Must not interfere if Timer is due shortly |
227 | | - if (T1V > ((clockCyclesPerMicrosecond() == 160) ? (IRQLATENCYCCYS + DELTAIRQCCYS) >> 1 : IRQLATENCYCCYS + DELTAIRQCCYS)) { |
| 222 | + if (T1V > ((clockCyclesPerMicrosecond() == 160) ? IRQLATENCYCCYS >> 1 : IRQLATENCYCCYS)) { |
228 | 223 | timer1_write(IRQLATENCYCCYS); |
229 | 224 | } |
230 | 225 | while (waveform.toDisableBits) { |
@@ -306,7 +301,7 @@ static ICACHE_RAM_ATTR void timer1Interrupt() { |
306 | 301 | uint32_t now = ESP.getCycleCount(); |
307 | 302 | uint32_t isrNextEventCcy = now; |
308 | 303 | while (busyPins) { |
309 | | - if (static_cast<int32_t>(isrNextEventCcy - now) > IRQLATENCYCCYS + DELTAIRQCCYS) { |
| 304 | + if (static_cast<int32_t>(isrNextEventCcy - now) > IRQLATENCYCCYS) { |
310 | 305 | waveform.nextEventCcy = isrNextEventCcy; |
311 | 306 | break; |
312 | 307 | } |
@@ -412,15 +407,9 @@ static ICACHE_RAM_ATTR void timer1Interrupt() { |
412 | 407 | } |
413 | 408 |
|
414 | 409 | // Firing timer too soon, the NMI occurs before ISR has returned. |
415 | | - if (nextTimerCcys <= IRQLATENCYCCYS + DELTAIRQCCYS) { |
| 410 | + if (nextTimerCcys <= IRQLATENCYCCYS) { |
416 | 411 | nextTimerCcys = IRQLATENCYCCYS; |
417 | 412 | } |
418 | | - else if (nextTimerCcys >= MAXIRQTICKSCCYS + DELTAIRQCCYS) { |
419 | | - nextTimerCcys = MAXIRQTICKSCCYS; |
420 | | - } |
421 | | - else { |
422 | | - nextTimerCcys -= DELTAIRQCCYS; |
423 | | - } |
424 | 413 |
|
425 | 414 | // Register access is fast and edge IRQ was configured before. |
426 | 415 | // Timer is 80MHz fixed. 160MHz binaries need scaling. |
|
0 commit comments