1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-05 12:42:22 +03:00

add regular scheduled functions, now also callable on yield() (#6039)

* add regular scheduled functions, now also callable on `yield()`

added bool schedule_function_us(std::function<bool(void)> fn, uint32_t repeat_us)
lambda must return true to be not removed from the schedule function list
if repeat_us is 0, then the function is called only once.

Legacy schedule_function() is preserved

This addition allows network drivers like ethernet chips on lwIP to be regularly called
- even if some user code loops on receiving data without getting out from main loop
  (callable from yield())
- without the need to call the driver handling function
  (transparent)

This may be also applicable with common libraries (mDNS, Webserver, )
This commit is contained in:
david gauchard
2019-05-23 22:03:53 +02:00
committed by GitHub
parent 6191fbbd92
commit b55199227b
13 changed files with 132 additions and 255 deletions

View File

@ -91,13 +91,15 @@ extern "C" void esp_yield() {
}
extern "C" void esp_schedule() {
// always on CONT stack here
run_scheduled_functions();
ets_post(LOOP_TASK_PRIORITY, 0, 0);
}
extern "C" void __yield() {
if (cont_can_yield(g_pcont)) {
esp_schedule();
esp_yield();
cont_yield(g_pcont); //esp_yield();
}
else {
panic();
@ -122,7 +124,6 @@ static void loop_wrapper() {
setup_done = true;
}
loop();
run_scheduled_functions();
esp_schedule();
}