mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Use F_CPU if (?) CPU frequency switch is compile-time only (#6833)
* At least the F_CPU define in host mock.h is needed by host Arduino.h - need to include Arduino.h further down in mock.h for this to work. * Geting the include order right * Prepare for runtime CPU clock rate selection * Fix compile for not defined F_CPU If defined F_CPU, make getCpuFreqMHz() a constexpr * Use defines for register CPU2X instead of hex value * Fix build for host - getCpuFreqMHz there was also in conflict with getCycleCount, using F_CPU: tests/host/common/mock.h:#define F_CPU 80000000 (!) * Asymmetrical includes and defines on host * Support restart switch from 160MHz to 80MHz, e.g for OTA. Fixes #579
This commit is contained in:
parent
e5f4514847
commit
6cb16997d8
@ -264,11 +264,12 @@ uint8_t EspClass::getBootMode(void)
|
||||
return system_get_boot_mode();
|
||||
}
|
||||
|
||||
#ifndef F_CPU
|
||||
uint8_t EspClass::getCpuFreqMHz(void)
|
||||
{
|
||||
return system_get_cpu_freq();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uint32_t EspClass::getFlashChipId(void)
|
||||
{
|
||||
|
@ -157,7 +157,14 @@ class EspClass {
|
||||
uint8_t getBootVersion();
|
||||
uint8_t getBootMode();
|
||||
|
||||
#if defined(F_CPU) || defined(CORE_MOCK)
|
||||
constexpr uint8_t getCpuFreqMHz() const
|
||||
{
|
||||
return clockCyclesPerMicrosecond();
|
||||
}
|
||||
#else
|
||||
uint8_t getCpuFreqMHz();
|
||||
#endif
|
||||
|
||||
uint32_t getFlashChipId();
|
||||
uint8_t getFlashChipVendorId();
|
||||
@ -201,6 +208,7 @@ class EspClass {
|
||||
};
|
||||
|
||||
#ifndef CORE_MOCK
|
||||
|
||||
uint32_t EspClass::getCycleCount()
|
||||
{
|
||||
return esp_get_cycle_count();
|
||||
|
@ -76,7 +76,7 @@ struct TimeSourceCycles
|
||||
|
||||
using timeType = decltype(ESP.getCycleCount());
|
||||
static timeType time() {return ESP.getCycleCount();}
|
||||
static constexpr timeType ticksPerSecond = F_CPU; // 80'000'000 or 160'000'000 Hz
|
||||
static constexpr timeType ticksPerSecond = ESP.getCpuFreqMHz() * 1000000UL; // 80'000'000 or 160'000'000 Hz
|
||||
static constexpr timeType ticksPerSecondMax = 160000000; // 160MHz
|
||||
};
|
||||
|
||||
|
@ -81,14 +81,25 @@ void initVariant() __attribute__((weak));
|
||||
void initVariant() {
|
||||
}
|
||||
|
||||
void preloop_update_frequency() __attribute__((weak));
|
||||
void preloop_update_frequency() {
|
||||
extern "C" void __preloop_update_frequency() {
|
||||
#if defined(F_CPU) && (F_CPU == 160000000L)
|
||||
REG_SET_BIT(0x3ff00014, BIT(0));
|
||||
ets_update_cpu_frequency(160);
|
||||
CPU2X |= 1UL;
|
||||
#elif defined(F_CPU)
|
||||
ets_update_cpu_frequency(80);
|
||||
CPU2X &= ~1UL;
|
||||
#elif !defined(F_CPU)
|
||||
if (system_get_cpu_freq() == 160) {
|
||||
CPU2X |= 1UL;
|
||||
}
|
||||
else {
|
||||
CPU2X &= ~1UL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void preloop_update_frequency() __attribute__((weak, alias("__preloop_update_frequency")));
|
||||
|
||||
extern "C" bool can_yield() {
|
||||
return cont_can_yield(g_pcont);
|
||||
}
|
||||
|
@ -118,11 +118,6 @@ uint32_t EspClass::getFreeSketchSpace()
|
||||
return 4 * 1024 * 1024;
|
||||
}
|
||||
|
||||
uint8_t EspClass::getCpuFreqMHz()
|
||||
{
|
||||
return F_CPU / 1000000;
|
||||
}
|
||||
|
||||
const char *EspClass::getSdkVersion()
|
||||
{
|
||||
return "2.5.0";
|
||||
|
Loading…
x
Reference in New Issue
Block a user