1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-10-18 09:50:40 +03:00

Implement esp_yield() as a replacement for delay(0)

esp_yield() now also calls esp_schedule(), original esp_yield() function renamed to esp_suspend().

Don't use delay(0) in the Core internals, libraries and examples. Use yield() when the code is
supposed to be called from CONT, use esp_yield() when the code can be called from either CONT or SYS.
Clean-up esp_yield() and esp_schedule() declarations across the code and use coredecls.h instead.

Implement helper functions for libraries that were previously using esp_yield(), esp_schedule() and
esp_delay() directly to wait for certain SYS context tasks to complete. Correctly use esp_delay()
for timeouts, make sure scheduled functions have a chance to run (e.g. LwIP_Ethernet uses recurrent)

Related issues:
- #6107 - discussion about the esp_yield() and esp_delay() usage in ClientContext
- #6212 - discussion about replacing delay() with a blocking loop
- #6680 - pull request introducing LwIP-based Ethernet
- #7146 - discussion that originated UART code changes
- #7969 - proposal to remove delay(0) from the example code
- #8291 - discussion related to the run_scheduled_recurrent_functions() usage in LwIP Ethernet
- #8317 - yieldUntil() implementation, similar to the esp_delay() overload with a timeout and a 0 interval
This commit is contained in:
Dirk O. Kaar
2021-10-16 23:19:01 +02:00
committed by GitHub
parent 40b26b769c
commit c312a2eaf1
32 changed files with 286 additions and 213 deletions

View File

@@ -36,9 +36,7 @@ extern "C" {
}
#include "debug.h"
extern "C" void esp_schedule();
extern "C" void esp_yield();
#include <coredecls.h>
// -----------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------- Private functions ------------------------------------------------
@@ -94,11 +92,13 @@ int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, uint8 ch
ESP8266WiFiScanClass::_scanStarted = true;
if(ESP8266WiFiScanClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
esp_yield(); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}
esp_yield(); // will resume when _scanDone fires
// will resume when _scanDone fires
esp_suspend([]() { return !ESP8266WiFiScanClass::_scanComplete && ESP8266WiFiScanClass::_scanStarted; });
return ESP8266WiFiScanClass::_scanCount;
} else {
return WIFI_SCAN_FAILED;
@@ -322,7 +322,7 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {
ESP8266WiFiScanClass::_scanStarted = false;
ESP8266WiFiScanClass::_scanComplete = true;
if(!ESP8266WiFiScanClass::_scanAsync) {
if (!ESP8266WiFiScanClass::_scanAsync) {
esp_schedule(); // resume scanNetworks
} else if (ESP8266WiFiScanClass::_onComplete) {
ESP8266WiFiScanClass::_onComplete(ESP8266WiFiScanClass::_scanCount);