Skip to content

Commit 3767791

Browse files
committed
Allow constexpr evalution to occur. optimistic_yield is always called with a literal parameter value.
1 parent 3d7423b commit 3767791

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

cores/esp8266/Arduino.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,24 @@ void setup(void);
204204
void loop(void);
205205

206206
void yield(void);
207-
void optimistic_yield(uint32_t interval_us);
207+
208+
#ifndef F_CPU
209+
// single function needed from SDK user_interface.h
210+
extern "C" uint8 system_get_cpu_freq(void);
211+
#endif
212+
213+
void __optimistic_yield(uint32_t intvl_cycles);
214+
215+
void inline optimistic_yield(uint32_t interval_us) __attribute__((always_inline));
216+
void inline optimistic_yield(uint32_t interval_us) {
217+
__optimistic_yield(interval_us *
218+
#if defined(F_CPU)
219+
clockCyclesPerMicrosecond()
220+
#else
221+
getCpuFreqMHz()
222+
#endif
223+
);
224+
}
208225

209226
#define _PORT_GPIO16 1
210227
#define digitalPinToPort(pin) (((pin)==16)?(_PORT_GPIO16):(0))

cores/esp8266/core_esp8266_main.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cont_t* g_pcont __attribute__((section(".noinit")));
5757
/* Event queue used by the main (arduino) task */
5858
static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
5959

60-
/* Used to implement optimistic_yield */
60+
/* Used to implement __optimistic_yield */
6161
static uint32_t s_cycles_since_yield_start;
6262

6363
/* For ets_intr_lock_nest / ets_intr_unlock_nest
@@ -125,10 +125,9 @@ extern "C" void __yield() {
125125

126126
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
127127

128-
extern "C" void optimistic_yield(uint32_t interval_us) {
129-
const uint32_t interval_cycles = interval_us * ESP.getCpuFreqMHz();
130-
if (can_yield() &&
131-
(ESP.getCycleCount() - s_cycles_since_yield_start) > interval_cycles)
128+
extern "C" void __optimistic_yield(uint32_t intvl_cycles) {
129+
if ((ESP.getCycleCount() - s_cycles_since_yield_start) > intvl_cycles &&
130+
can_yield())
132131
{
133132
yield();
134133
}

0 commit comments

Comments
 (0)