diff --git a/cores/esp8266/PolledTimeout.h b/cores/esp8266/PolledTimeout.h index fe9c9ca4bc..c8069f7b8c 100644 --- a/cores/esp8266/PolledTimeout.h +++ b/cores/esp8266/PolledTimeout.h @@ -44,7 +44,7 @@ struct DoNothing struct YieldOrSkip { - static void execute() {delay(0);} + static void execute() {yield();} }; template diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index a95c4b2c11..2da1877c44 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -113,13 +113,10 @@ extern "C" IRAM_ATTR void esp_schedule() { } extern "C" void __yield() { + esp_schedule(); if (can_yield()) { - esp_schedule(); esp_yield_within_cont(); } - else { - panic(); - } } extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); diff --git a/cores/esp8266/core_esp8266_waveform.cpp b/cores/esp8266/core_esp8266_waveform.cpp index 59fce8695e..577799ea64 100644 --- a/cores/esp8266/core_esp8266_waveform.cpp +++ b/cores/esp8266/core_esp8266_waveform.cpp @@ -139,7 +139,7 @@ int startWaveform(uint8_t pin, uint32_t timeHighUS, uint32_t timeLowUS, uint32_t } } while (waveformToEnable) { - delay(0); // Wait for waveform to update + yield(); // Wait for waveform to update } } diff --git a/cores/esp8266/uart.cpp b/cores/esp8266/uart.cpp index fd8170b586..aa3e1e3cc9 100644 --- a/cores/esp8266/uart.cpp +++ b/cores/esp8266/uart.cpp @@ -528,7 +528,7 @@ uart_wait_tx_empty(uart_t* uart) return; while(uart_tx_fifo_available(uart->uart_nr) > 0) - delay(0); + yield(); } @@ -892,7 +892,7 @@ inline void uart_write_char_delay(const int uart_nr, char c) { while(uart_tx_fifo_full(uart_nr)) - delay(0); + yield(); USF(uart_nr) = c; diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index ff46822c3e..09e13c4d21 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -854,7 +854,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) len -= readBytes; } - delay(0); + yield(); } else { delay(1); } @@ -1000,7 +1000,7 @@ int HTTPClient::writeToStream(Stream * stream) return returnError(HTTPC_ERROR_READ_TIMEOUT); } - delay(0); + yield(); } } else { return returnError(HTTPC_ERROR_ENCODING); @@ -1387,7 +1387,7 @@ int HTTPClient::handleHeaderResponse() if((millis() - lastDataTime) > _tcpTimeout) { return HTTPC_ERROR_READ_TIMEOUT; } - delay(0); + yield(); } } @@ -1483,7 +1483,7 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) len -= bytesRead; } - delay(0); + yield(); } free(buff); diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h index 966a73eefc..9baed408ab 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h @@ -119,7 +119,7 @@ void ESP8266HTTPUpdateServerTemplate::setup(ESP8266WebServerTemplate Update.end(); if (_serial_output) Serial.println("Update was aborted"); } - delay(0); + yield(); }); } diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp index 4b2eb54ce7..6a14bc975c 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp @@ -523,9 +523,9 @@ bool ESP8266WiFiGenericClass::forceSleepBegin(uint32 sleepUs) { } wifi_fpm_set_sleep_type(MODEM_SLEEP_T); - delay(0); + yield(); wifi_fpm_open(); - delay(0); + yield(); auto ret = wifi_fpm_do_sleep(sleepUs); if (ret != 0) { diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp index 531e76239a..6d09abb446 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp @@ -65,7 +65,7 @@ wl_status_t ESP8266WiFiMulti::run(void) { DEBUG_WIFI_MULTI("[WIFI] no networks found\n"); WiFi.scanDelete(); DEBUG_WIFI_MULTI("\n\n"); - delay(0); + yield(); WiFi.disconnect(); DEBUG_WIFI_MULTI("[WIFI] start scan\n"); // scan wifi async mode @@ -81,7 +81,7 @@ wl_status_t ESP8266WiFiMulti::run(void) { int32_t bestChannel; DEBUG_WIFI_MULTI("[WIFI] scan done\n"); - delay(0); + yield(); DEBUG_WIFI_MULTI("[WIFI] %d networks found\n", scanResult); for(int8_t i = 0; i < scanResult; ++i) { @@ -118,14 +118,14 @@ wl_status_t ESP8266WiFiMulti::run(void) { } DEBUG_WIFI_MULTI(" %d: [%d][%02X:%02X:%02X:%02X:%02X:%02X] %s (%d) %c\n", i, chan_scan, BSSID_scan[0], BSSID_scan[1], BSSID_scan[2], BSSID_scan[3], BSSID_scan[4], BSSID_scan[5], ssid_scan.c_str(), rssi_scan, (sec_scan == ENC_TYPE_NONE) ? ' ' : '*'); - delay(0); + yield(); } // clean up ram WiFi.scanDelete(); DEBUG_WIFI_MULTI("\n\n"); - delay(0); + yield(); if(bestNetwork.ssid) { DEBUG_WIFI_MULTI("[WIFI] Connecting BSSID: %02X:%02X:%02X:%02X:%02X:%02X SSID: %s Channel: %d (%d)\n", bestBSSID[0], bestBSSID[1], bestBSSID[2], bestBSSID[3], bestBSSID[4], bestBSSID[5], bestNetwork.ssid, bestChannel, bestNetworkDb); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp index 65878a3d5b..cc49ebc77b 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp @@ -94,7 +94,7 @@ 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 + yield(); // time for the OS to trigger the scan return WIFI_SCAN_RUNNING; } diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h index 6ce97115f9..686c35da13 100644 --- a/libraries/ESP8266WiFi/src/include/ClientContext.h +++ b/libraries/ESP8266WiFi/src/include/ClientContext.h @@ -342,7 +342,7 @@ class ClientContext last_sent = millis(); } - delay(0); // from sys or os context + yield(); // from sys or os context if ((state() != ESTABLISHED) || (sndbuf == TCP_SND_BUF)) { break; diff --git a/libraries/SDFS/src/SDFSFormatter.h b/libraries/SDFS/src/SDFSFormatter.h index d1fe6c94a7..14a797ba08 100644 --- a/libraries/SDFS/src/SDFSFormatter.h +++ b/libraries/SDFS/src/SDFSFormatter.h @@ -76,7 +76,7 @@ class SDFSFormatter { esp8266::polledTimeout::periodicFastMs timeToYield(5); // Yield every 5ms of runtime for (uint32_t i = 0; i < count; i++) { if (timeToYield) { - delay(0); // WDT feed + yield(); // WDT feed } if (!card->writeData(cache->data)) { DEBUGV("SDFS: Clear FAT/DIR writeData failed"); @@ -383,7 +383,7 @@ class SDFSFormatter { if (!card->erase(firstBlock, lastBlock)) { return false; // Erase fail } - delay(0); // yield to the OS to avoid WDT + yield(); // yield to the OS to avoid WDT firstBlock += ERASE_SIZE; } while (firstBlock < cardSizeBlocks); diff --git a/libraries/esp8266/examples/SerialStress/SerialStress.ino b/libraries/esp8266/examples/SerialStress/SerialStress.ino index 1412abd2be..10823ede78 100644 --- a/libraries/esp8266/examples/SerialStress/SerialStress.ino +++ b/libraries/esp8266/examples/SerialStress/SerialStress.ino @@ -128,7 +128,7 @@ void loop() { if ((out_idx += local_written_size) == BUFFER_SIZE) { out_idx = 0; } - delay(0); + yield(); DEBUG(logger->printf("----------\n"));