8000 Fix WDT when at 160MHz CPU clock the Timer1 is set below 1µs. · dok-net/arduino-esp8266@4319113 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4319113

Browse files
committed
Fix WDT when at 160MHz CPU clock the Timer1 is set below 1µs.
1 parent ff365b0 commit 4319113

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cores/esp8266/core_esp8266_waveform.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ constexpr int32_t MAXIRQTICKSCCYS = microsecondsToClockCycles(10000);
4949
// Maximum servicing time for any single IRQ
5050
constexpr uint32_t ISRTIMEOUTCCYS = microsecondsToClockCycles(18);
5151
// The latency between in-ISR rearming of the timer and the earliest firing
52-
constexpr int32_t IRQLATENCYCCYS = clockCyclesPerMicrosecond() == 160 ?
53-
microsecondsToClockCycles(1) >> 1 : microsecondsToClockCycles(1);
52+
constexpr int32_t IRQLATENCYCCYS = microsecondsToClockCycles(1);
5453

5554
// for INFINITE, the NMI proceeds on the waveform without expiry deadline.
5655
// for EXPIRES, the NMI expires the waveform automatically on the expiry ccy.
@@ -406,12 +405,17 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
406405
nextTimerCcys = callbackCcys;
407406
}
408407

408+
// Timer is 80MHz fixed. 160MHz CPU frequency need scaling.
409+
constexpr bool cpuFreq160MHz = clockCyclesPerMicrosecond() == 160;
410+
if (cpuFreq160MHz || CPU2X & 1) {
411+
nextTimerCcys >>= 1;
412+
}
413+
409414
// Firing timer too soon, the NMI occurs before ISR has returned.
410415
if (nextTimerCcys <= IRQLATENCYCCYS) {
411416
nextTimerCcys = IRQLATENCYCCYS;
412417
}
413418

414419
// Register access is fast and edge IRQ was configured before.
415-
// Timer is 80MHz fixed. 160MHz binaries need scaling.
416-
T1L = (CPU2X & 1) ? nextTimerCcys >> 1 : nextTimerCcys;
420+
T1L = nextTimerCcys;
417421
}

0 commit comments

Comments
 (0)
0