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 4cf9638

Browse filesBrowse files
committed
Consolidate 160MHz constexpr check, finish 1µs minimum for Timer1 fix.
1 parent 4319113 commit 4cf9638
Copy full SHA for 4cf9638

File tree

Expand file treeCollapse file tree

1 file changed

+8
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-8
lines changed

‎cores/esp8266/core_esp8266_waveform.cpp

Copy file name to clipboardExpand all lines: cores/esp8266/core_esp8266_waveform.cpp
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "ets_sys.h"
4545
#include <atomic>
4646

47+
// Timer is 80MHz fixed. 160MHz CPU frequency need scaling.
48+
constexpr bool ISCPUFREQ160MHZ = clockCyclesPerMicrosecond() == 160;
4749
// Maximum delay between IRQs, Timer1, <= 2^23 / 80MHz
4850
constexpr int32_t MAXIRQTICKSCCYS = microsecondsToClockCycles(10000);
4951
// Maximum servicing time for any single IRQ
@@ -181,7 +183,7 @@ int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys,
181183
if (!waveform.timer1Running) {
182184
initTimer();
183185
}
184-
else if (T1V > ((clockCyclesPerMicrosecond() == 160) ? IRQLATENCYCCYS >> 1 : IRQLATENCYCCYS)) {
186+
else if (T1V > IRQLATENCYCCYS) {
185187
// Must not interfere if Timer is due shortly
186188
timer1_write(IRQLATENCYCCYS);
187189
}
@@ -218,7 +220,7 @@ int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) {
218220
waveform.toDisableBits = 1UL << pin;
219221
std::atomic_thread_fence(std::memory_order_release);
220222
// Must not interfere if Timer is due shortly
221-
if (T1V > ((clockCyclesPerMicrosecond() == 160) ? IRQLATENCYCCYS >> 1 : IRQLATENCYCCYS)) {
223+
if (T1V > IRQLATENCYCCYS) {
222224
timer1_write(IRQLATENCYCCYS);
223225
}
224226
while (waveform.toDisableBits) {
@@ -240,12 +242,11 @@ int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) {
240242
// For dynamic CPU clock frequency switch in loop the scaling logic would have to be adapted.
241243
// Using constexpr makes sure that the CPU clock frequency is compile-time fixed.
242244
static inline ICACHE_RAM_ATTR int32_t scaleCcys(int32_t ccys) {
243-
constexpr bool cpuFreq80MHz = clockCyclesPerMicrosecond() == 80;
244-
if (cpuFreq80MHz) {
245-
return ((CPU2X & 1) ? ccys << 1 : ccys);
245+
if (ISCPUFREQ160MHZ) {
246+
return ((CPU2X & 1) ? ccys : ccys >> 1);
246247
}
247248
else {
248-
return ((CPU2X & 1) ? ccys : ccys >> 1);
249+
return ((CPU2X & 1) ? ccys << 1 : ccys);
249250
}
250251
}
251252

@@ -406,8 +407,7 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
406407
}
407408

408409
// Timer is 80MHz fixed. 160MHz CPU frequency need scaling.
409-
constexpr bool cpuFreq160MHz = clockCyclesPerMicrosecond() == 160;
410-
if (cpuFreq160MHz || CPU2X & 1) {
410+
if (ISCPUFREQ160MHZ || CPU2X & 1) {
411411
nextTimerCcys >>= 1;
412412
}
413413

0 commit comments

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