From 3767791fbc4ce348095ea9f305817f9f89c594ac Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Mon, 2 Dec 2019 11:05:21 +0100 Subject: [PATCH] Allow constexpr evalution to occur. optimistic_yield is always called with a literal parameter value. --- cores/esp8266/Arduino.h | 19 ++++++++++++++++++- cores/esp8266/core_esp8266_main.cpp | 9 ++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 54919ba10..a7e5ca23b 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -204,7 +204,24 @@ void setup(void); void loop(void); void yield(void); -void optimistic_yield(uint32_t interval_us); + +#ifndef F_CPU +// single function needed from SDK user_interface.h +extern "C" uint8 system_get_cpu_freq(void); +#endif + +void __optimistic_yield(uint32_t intvl_cycles); + +void inline optimistic_yield(uint32_t interval_us) __attribute__((always_inline)); +void inline optimistic_yield(uint32_t interval_us) { + __optimistic_yield(interval_us * +#if defined(F_CPU) + clockCyclesPerMicrosecond() +#else + getCpuFreqMHz() +#endif + ); +} #define _PORT_GPIO16 1 #define digitalPinToPort(pin) (((pin)==16)?(_PORT_GPIO16):(0)) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index aca69a216..48a20dd1f 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -57,7 +57,7 @@ cont_t* g_pcont __attribute__((section(".noinit"))); /* Event queue used by the main (arduino) task */ static os_event_t s_loop_queue[LOOP_QUEUE_SIZE]; -/* Used to implement optimistic_yield */ +/* Used to implement __optimistic_yield */ static uint32_t s_cycles_since_yield_start; /* For ets_intr_lock_nest / ets_intr_unlock_nest @@ -125,10 +125,9 @@ extern "C" void __yield() { extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); -extern "C" void optimistic_yield(uint32_t interval_us) { - const uint32_t interval_cycles = interval_us * ESP.getCpuFreqMHz(); - if (can_yield() && - (ESP.getCycleCount() - s_cycles_since_yield_start) > interval_cycles) +extern "C" void __optimistic_yield(uint32_t intvl_cycles) { + if ((ESP.getCycleCount() - s_cycles_since_yield_start) > intvl_cycles && + can_yield()) { yield(); }