1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +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

@ -15,6 +15,7 @@
#include <sys/time.h>
#include "Arduino.h"
#include <functional>
#include <unistd.h>
@ -53,10 +54,31 @@ extern "C" void optimistic_yield (uint32_t interval_us)
(void)interval_us;
}
extern "C" void esp_suspend()
{
}
extern "C" void esp_schedule()
{
}
extern "C" void esp_yield()
{
}
extern "C" void esp_delay (unsigned long ms)
{
usleep(ms * 1000);
}
bool esp_try_delay(const uint32_t start_ms, const uint32_t timeout_ms, const uint32_t intvl_ms) {
uint32_t expired = millis() - start_ms;
if (expired >= timeout_ms) {
return true;
}
esp_delay(std::min((timeout_ms - expired), intvl_ms));
return false;
}
extern "C" void __panic_func(const char* file, int line, const char* func) {
(void)file;
@ -67,7 +89,7 @@ extern "C" void __panic_func(const char* file, int line, const char* func) {
extern "C" void delay(unsigned long ms)
{
usleep(ms * 1000);
esp_delay(ms);
}
extern "C" void delayMicroseconds(unsigned int us)
@ -77,6 +99,6 @@ extern "C" void delayMicroseconds(unsigned int us)
#include "cont.h"
cont_t* g_pcont = NULL;
extern "C" void cont_yield(cont_t*)
extern "C" void cont_suspend(cont_t*)
{
}

View File

@ -24,9 +24,6 @@
class ClientContext;
class WiFiClient;
extern "C" void esp_yield();
extern "C" void esp_schedule();
#include <assert.h>
bool getDefaultPrivateGlobalSyncValue ();

View File

@ -498,10 +498,6 @@ extern "C"
(void)intr;
}
void esp_schedule(void)
{
}
void dns_setserver(u8_t numdns, ip_addr_t *dnsserver)
{
(void)numdns;