Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54bd664

Browse filesBrowse files
committed
Handle time-of-flight in the right spot.
1 parent ad9af53 commit 54bd664
Copy full SHA for 54bd664

File tree

Expand file treeCollapse file tree

1 file changed

+12
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-6
lines changed

‎cores/esp8266/core_esp8266_waveform.cpp

Copy file name to clipboardExpand all lines: cores/esp8266/core_esp8266_waveform.cpp
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ constexpr int32_t MAXIRQTICKSCCYS = microsecondsToClockCycles(10000);
5151
// Maximum servicing time for any single IRQ
5252
constexpr uint32_t ISRTIMEOUTCCYS = microsecondsToClockCycles(18);
5353
// 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);
5655
// The SDK and hardware take some time to actually get to our NMI code
5756
constexpr int32_t DELTAIRQCCYS = ISCPUFREQ160MHZ ?
5857
microsecondsToClockCycles(2) >> 1 : microsecondsToClockCycles(2);
@@ -256,7 +255,7 @@ static inline ICACHE_RAM_ATTR int32_t scaleCcys(const int32_t ccys, const bool i
256255

257256
static ICACHE_RAM_ATTR void timer1Interrupt() {
258257
const uint32_t isrStartCcy = ESP.getCycleCount();
259-
int32_t clockDrift = isrStartCcy - waveform.nextEventCcy - DELTAIRQCCYS;
258+
int32_t clockDrift = isrStartCcy - waveform.nextEventCcy;
260259
const bool isCPU2X = CPU2X & 1;
261260
if ((waveform.toSetBits && !(waveform.enabled & waveform.toSetBits)) || waveform.toDisableBits) {
262261
// Handle enable/disable requests from main app.
@@ -415,14 +414,21 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
415414
}
416415

417416
// Timer is 80MHz fixed. 160MHz CPU frequency need scaling.
417+
int32_t deltaIrqCcys = DELTAIRQCCYS;
418+
int32_t irqLatencyCcys = IRQLATENCYCCYS;
418419
if (isCPU2X) {
419420
nextEventCcys >>= 1;
421+
deltaIrqCcys >>= 1;
422+
irqLatencyCcys >>= 1;
420423
}
421424

422425
// 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;
426432
}
427433

428434
// Register access is fast and edge IRQ was configured before.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.