Skip to content

Commit 689187f

Browse files
committed
Prepare for runtime CPU clock rate selection
1 parent 26f6ac8 commit 689187f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cores/esp8266/Esp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ class EspClass {
209209

210210
uint8_t EspClass::getCpuFreqMHz()
211211
{
212+
#if defined(F_CPU)
212213
return clockCyclesPerMicrosecond();
214+
#elif !defined(F_CPU)
215+
return system_get_cpu_freq();
216+
#endif
213217
}
214218

215219
uint32_t EspClass::getCycleCount()

cores/esp8266/core_esp8266_main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,17 @@ void initVariant() __attribute__((weak));
8181
void initVariant() {
8282
}
8383

84-
void preloop_update_frequency() __attribute__((weak));
85-
void preloop_update_frequency() {
84+
extern "C" void __preloop_update_frequency() {
8685
#if defined(F_CPU) && (F_CPU == 160000000L)
87-
REG_SET_BIT(0x3ff00014, BIT(0));
8886
ets_update_cpu_frequency(160);
87+
REG_SET_BIT(0x3ff00014, BIT(0));
88+
#elif !defined(F_CPU)
89+
if (system_get_cpu_freq() == 160) REG_SET_BIT(0x3ff00014, BIT(0));
8990
#endif
9091
}
9192

93+
extern "C" void preloop_update_frequency() __attribute__((weak, alias("__preloop_update_frequency")));
94+
9295
extern "C" bool can_yield() {
9396
return cont_can_yield(g_pcont);
9497
}

0 commit comments

Comments
 (0)