@@ -58,7 +58,7 @@ cont_t* g_pcont __attribute__((section(".noinit")));
58
58
static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
59
59
60
60
/* Used to implement optimistic_yield */
61
- static uint32_t s_micros_since_yield_start ;
61
+ static uint32_t s_cycles_since_yield_start ;
62
62
63
63
/* For ets_intr_lock_nest / ets_intr_unlock_nest
64
64
* Max nesting seen by SDK so far is 2.
@@ -116,7 +116,7 @@ extern "C" void __yield() {
116
116
if (can_yield ()) {
117
117
esp_schedule ();
118
118
esp_yield_within_cont ();
119
- s_micros_since_yield_start = system_get_time ();
119
+ s_cycles_since_yield_start = ESP. getCycleCount ();
120
120
}
121
121
else {
122
122
panic ();
@@ -126,8 +126,9 @@ extern "C" void __yield() {
126
126
extern " C" void yield (void ) __attribute__ ((weak, alias(" __yield" )));
127
127
128
128
extern " C" void optimistic_yield (uint32_t interval_us) {
129
+ const uint32_t interval_cycles = interval_us * ESP.getCpuFreqMHz ();
129
130
if (can_yield () &&
130
- (system_get_time () - s_micros_since_yield_start ) > interval_us )
131
+ (ESP. getCycleCount () - s_cycles_since_yield_start ) > interval_cycles )
131
132
{
132
133
yield ();
133
134
}
@@ -184,7 +185,7 @@ static void loop_wrapper() {
184
185
185
186
static void loop_task (os_event_t *events) {
186
187
(void ) events;
187
- s_micros_since_yield_start = system_get_time ();
188
+ s_cycles_since_yield_start = ESP. getCycleCount ();
188
189
cont_run (g_pcont, &loop_wrapper);
189
190
if (cont_check (g_pcont) != 0 ) {
190
191
panic ();
@@ -212,7 +213,7 @@ extern void __unhandled_exception(const char *str);
212
213
static void __unhandled_exception_cpp ()
213
214
{
214
215
#ifndef __EXCEPTIONS
215
- abort ();
216
+ abort ();
216
217
#else
217
218
static bool terminating;
218
219
if (terminating)
0 commit comments