Skip to content

Commit 4df7186

Browse files
committed
delay0isyield squash commit.
1 parent 9d024d1 commit 4df7186

23 files changed

+58
-55
lines changed

cores/esp8266/Esp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ void EspClass::wdtFeed(void)
115115
system_soft_wdt_feed();
116116
}
117117

118-
extern "C" void esp_yield();
119-
120118
void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
121119
{
122120
system_deep_sleep_set_option(static_cast<int>(mode));

cores/esp8266/PolledTimeout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <limits> // std::numeric_limits
2828
#include <type_traits> // std::is_unsigned
2929
#include <core_esp8266_features.h>
30+
#include <coredecls.h>
3031

3132
namespace esp8266
3233
{
@@ -45,7 +46,7 @@ struct DoNothing
4546

4647
struct YieldOrSkip
4748
{
48-
static void execute() {delay(0);}
49+
static void execute() {esp_break();}
4950
};
5051

5152
template <unsigned long delayMs>

cores/esp8266/core_esp8266_main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ extern "C" IRAM_ATTR void esp_schedule() {
128128
ets_post(LOOP_TASK_PRIORITY, 0, 0);
129129
}
130130

131+
// Replacement for delay(0). In CONT, same as yield(). Whereas yield() panics
132+
// in SYS, esp_break() is safe to call and only schedules CONT. Use yield()
133+
// whereever only called from CONT, use esp_break() if code is called from SYS
134+
// or both CONT and SYS.
135+
extern "C" void esp_break() {
136+
esp_schedule();
137+
esp_yield();
138+
}
139+
131140
extern "C" void __yield() {
132141
if (can_yield()) {
133142
esp_schedule();

cores/esp8266/core_esp8266_postmortem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ static void print_stack(uint32_t start, uint32_t end) {
245245
}
246246
}
247247

248-
static void uart_write_char_d(char c) {
248+
static void ICACHE_RAM_ATTR uart_write_char_d(char c) {
249249
uart0_write_char_d(c);
250250
uart1_write_char_d(c);
251251
}
252252

253-
static void uart0_write_char_d(char c) {
253+
static void ICACHE_RAM_ATTR uart0_write_char_d(char c) {
254254
while (((USS(0) >> USTXC) & 0xff)) { }
255255

256256
if (c == '\n') {
@@ -259,7 +259,7 @@ static void uart0_write_char_d(char c) {
259259
USF(0) = c;
260260
}
261261

262-
static void uart1_write_char_d(char c) {
262+
static void ICACHE_RAM_ATTR uart1_write_char_d(char c) {
263263
while (((USS(1) >> USTXC) & 0xff) >= 0x7e) { }
264264

265265
if (c == '\n') {

cores/esp8266/core_esp8266_waveform_phase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t highCcys, uint32_t lowCc
211211
}
212212
std::atomic_thread_fence(std::memory_order_acq_rel);
213213
while (waveform.toSetBits) {
214-
delay(0); // Wait for waveform to update
214+
yield(); // Wait for waveform to update
215215
std::atomic_thread_fence(std::memory_order_acquire);
216216
}
217217
return true;

cores/esp8266/core_esp8266_waveform_pwm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static IRAM_ATTR void _notifyPWM(PWMState *p, bool idle) {
162162
forceTimerInterrupt();
163163
while (pwmState.pwmUpdate) {
164164
if (idle) {
165-
delay(0);
165+
yield();
166166
}
167167
MEMBARRIER();
168168
}
@@ -372,7 +372,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t timeHighCycles, uint32_t
372372
if (wvfState.waveformEnabled & mask) {
373373
// Make sure no waveform changes are waiting to be applied
374374
while (wvfState.waveformToChange) {
375-
delay(0); // Wait for waveform to update
375+
yield(); // Wait for waveform to update
376376
// No mem barrier here, the call to a global function implies global state updated
377377
}
378378
wvfState.waveformNewHigh = timeHighCycles;
@@ -392,7 +392,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t timeHighCycles, uint32_t
392392
initTimer();
393393
forceTimerInterrupt();
394394
while (wvfState.waveformToEnable) {
395-
delay(0); // Wait for waveform to update
395+
yield(); // Wait for waveform to update
396396
// No mem barrier here, the call to a global function implies global state updated
397397
}
398398
}

cores/esp8266/core_esp8266_wiring.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
#include "osapi.h"
2525
#include "user_interface.h"
2626
#include "cont.h"
27+
#include "coredecls.h"
2728

2829
extern "C" {
2930

30-
extern void ets_delay_us(uint32_t us);
31-
extern void esp_schedule();
32-
extern void esp_yield();
33-
3431
static os_timer_t delay_timer;
3532
static os_timer_t micros_overflow_timer;
3633
static uint32_t micros_at_last_overflow_tick = 0;

cores/esp8266/coredecls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern "C" {
1515
bool can_yield();
1616
void esp_yield();
1717
void esp_schedule();
18+
void esp_break();
1819
void tune_timeshift64 (uint64_t now_us);
1920
void disable_extra4k_at_link_time (void) __attribute__((noinline));
2021
bool sntp_set_timezone_in_seconds(int32_t timezone);

cores/esp8266/uart.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
*
4242
*/
4343
#include "Arduino.h"
44+
#include "coredecls.h"
4445
#include <pgmspace.h>
4546
#include "gdb_hooks.h"
4647
#include "uart.h"
@@ -493,13 +494,13 @@ uart_stop_isr(uart_t* uart)
493494
-tools/sdk/uart_register.h
494495
-cores/esp8266/esp8266_peri.h
495496
*/
496-
inline size_t
497+
inline __attribute__((always_inline)) size_t
497498
uart_tx_fifo_available(const int uart_nr)
498499
{
499500
return (USS(uart_nr) >> USTXC) & 0xff;
500501
}
501502

502-
inline bool
503+
inline __attribute__((always_inline)) bool
503504
uart_tx_fifo_full(const int uart_nr)
504505
{
505506
return uart_tx_fifo_available(uart_nr) >= 0x7f;
@@ -566,7 +567,7 @@ uart_wait_tx_empty(uart_t* uart)
566567
return;
567568

568569
while(uart_tx_fifo_available(uart->uart_nr) > 0)
569-
delay(0);
570+
esp_break();
570571

571572
}
572573

@@ -943,23 +944,23 @@ uart_ignore_char(char c)
943944
(void) c;
944945
}
945946

946-
inline void
947+
inline __attribute__((always_inline)) void
947948
uart_write_char_delay(const int uart_nr, char c)
948949
{
949950
while(uart_tx_fifo_full(uart_nr))
950-
delay(0);
951+
esp_break();
951952

952953
USF(uart_nr) = c;
953954

954955
}
955956

956-
static void
957+
static void ICACHE_RAM_ATTR
957958
uart0_write_char(char c)
958959
{
959960
uart_write_char_delay(0, c);
960961
}
961962

962-
static void
963+
static void ICACHE_RAM_ATTR
963964
uart1_write_char(char c)
964965
{
965966
uart_write_char_delay(1, c);

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*
2323
*/
2424
#include <Arduino.h>
25+
#include <coredecls.h>
2526

2627
#include "ESP8266HTTPClient.h"
2728
#include <ESP8266WiFi.h>
@@ -567,6 +568,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
567568
if (transferred != size)
568569
{
569570
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] short write, asked for %d but got %d failed.\n", size, transferred);
571+
esp_break();
570572
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
571573
}
572574

@@ -709,7 +711,7 @@ int HTTPClient::writeToPrint(Print * print)
709711
return returnError(HTTPC_ERROR_READ_TIMEOUT);
710712
}
711713

712-
delay(0);
714+
esp_break();
713715
}
714716
} else {
715717
return returnError(HTTPC_ERROR_ENCODING);
@@ -1074,7 +1076,7 @@ int HTTPClient::handleHeaderResponse()
10741076
if((millis() - lastDataTime) > _tcpTimeout) {
10751077
return HTTPC_ERROR_READ_TIMEOUT;
10761078
}
1077-
delay(0);
1079+
esp_break();
10781080
}
10791081
}
10801082

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <Arduino.h>
2+
#include <coredecls.h>
23
#include <WiFiClient.h>
34
#include <WiFiServer.h>
45
#include <ESP8266WebServer.h>
@@ -119,7 +120,7 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
119120
Update.end();
120121
if (_serial_output) Serial.println("Update was aborted");
121122
}
122-
delay(0);
123+
esp_break();
123124
});
124125
}
125126

libraries/ESP8266WiFi/examples/WiFiScan/WiFiScan.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void loop() {
4949
(encryptionType == ENC_TYPE_NONE) ? ' ' : '*',
5050
hidden ? 'H' : 'V',
5151
ssid.c_str());
52-
delay(0);
52+
yield();
5353
}
5454
} else {
5555
Serial.printf(PSTR("WiFi scan error %d"), scanResult);

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ extern "C" {
4949
#include "debug.h"
5050
#include "include/WiFiState.h"
5151

52-
extern "C" void esp_schedule();
53-
extern "C" void esp_yield();
54-
55-
5652
// -----------------------------------------------------------------------------------------------------------------------
5753
// ------------------------------------------------- Generic WiFi function -----------------------------------------------
5854
// -----------------------------------------------------------------------------------------------------------------------
@@ -518,9 +514,9 @@ bool ESP8266WiFiGenericClass::forceSleepBegin(uint32 sleepUs) {
518514
}
519515

520516
wifi_fpm_set_sleep_type(MODEM_SLEEP_T);
521-
delay(0);
517+
esp_break();
522518
wifi_fpm_open();
523-
delay(0);
519+
esp_break();
524520
auto ret = wifi_fpm_do_sleep(sleepUs);
525521
if (ret != 0)
526522
{

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "PolledTimeout.h"
2727
#include "ESP8266WiFiMulti.h"
28+
#include <coredecls.h>
2829
#include <limits.h>
2930
#include <string.h>
3031

@@ -91,7 +92,7 @@ static wl_status_t waitWiFiConnect(uint32_t connectTimeoutMs)
9192
// Wait for WiFi status change or timeout
9293
do {
9394
// Refresh watchdog
94-
delay(0);
95+
esp_break();
9596

9697
// Get WiFi status
9798
status = WiFi.status();
@@ -249,7 +250,7 @@ int8_t ESP8266WiFiMulti::startScan()
249250
// Wait for WiFi scan change or timeout
250251
do {
251252
// Refresh watchdog
252-
delay(0);
253+
esp_break();
253254

254255
// Check scan timeout which may occur when scan does not report completion
255256
if (scanTimeout) {
@@ -535,7 +536,7 @@ void ESP8266WiFiMulti::printWiFiScan()
535536
rssi,
536537
(encryptionType == ENC_TYPE_NONE) ? ' ' : '*',
537538
ssid.c_str());
538-
delay(0);
539+
esp_break();
539540
}
540541
#endif
541542
}

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "PolledTimeout.h"
2929
#include "LwipIntf.h"
3030

31+
#include <coredecls.h>
32+
3133
#include "c_types.h"
3234
#include "ets_sys.h"
3335
#include "os_type.h"
@@ -44,9 +46,6 @@ extern "C" {
4446

4547
#include "debug.h"
4648

47-
extern "C" void esp_schedule();
48-
extern "C" void esp_yield();
49-
5049
// -----------------------------------------------------------------------------------------------------------------------
5150
// ---------------------------------------------------- Private functions ------------------------------------------------
5251
// -----------------------------------------------------------------------------------------------------------------------

libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "ESP8266WiFiGeneric.h"
2727
#include "ESP8266WiFiScan.h"
2828

29+
#include <coredecls.h>
30+
2931
extern "C" {
3032
#include "c_types.h"
3133
#include "ets_sys.h"
@@ -37,9 +39,6 @@ extern "C" {
3739

3840
#include "debug.h"
3941

40-
extern "C" void esp_schedule();
41-
extern "C" void esp_yield();
42-
4342
// -----------------------------------------------------------------------------------------------------------------------
4443
// ---------------------------------------------------- Private functions ------------------------------------------------
4544
// -----------------------------------------------------------------------------------------------------------------------
@@ -94,7 +93,7 @@ int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, uint8 ch
9493
ESP8266WiFiScanClass::_scanStarted = true;
9594

9695
if(ESP8266WiFiScanClass::_scanAsync) {
97-
delay(0); // time for the OS to trigger the scan
96+
esp_break(); // time for the OS to trigger the scan
9897
return WIFI_SCAN_RUNNING;
9998
}
10099

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extern "C" {
4444
#include "lwip/netif.h"
4545
#include <include/ClientContext.h>
4646
#include "c_types.h"
47-
#include "coredecls.h"
4847
#include <mmu_iram.h>
4948
#include <umm_malloc/umm_malloc.h>
5049
#include <umm_malloc/umm_heap_select.h>

libraries/ESP8266WiFi/src/include/ClientContext.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ class WiFiClient;
2626

2727
typedef void (*discard_cb_t)(void*, ClientContext*);
2828

29-
extern "C" void esp_yield();
30-
extern "C" void esp_schedule();
31-
3229
#include <assert.h>
3330
#include <esp_priv.h>
3431

32+
#include <coredecls.h>
33+
3534
bool getDefaultPrivateGlobalSyncValue ();
3635

3736
class ClientContext
@@ -352,7 +351,7 @@ class ClientContext
352351
last_sent = millis();
353352
}
354353

355-
delay(0); // from sys or os context
354+
esp_break(); // from sys or os context
356355

357356
if ((state() != ESTABLISHED) || (sndbuf == TCP_SND_BUF)) {
358357
// peer has closed or all bytes are sent and acked

libraries/ESP8266WiFi/src/include/UdpContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class UdpContext
411411
err_t err;
412412
esp8266::polledTimeout::oneShotFastMs timeout(timeoutMs);
413413
while (((err = trySend(addr, port, /* keep buffer on error */true)) != ERR_OK) && !timeout)
414-
delay(0);
414+
esp_break();
415415
if (err != ERR_OK)
416416
cancelBuffer(); // get rid of buffer kept on error after timeout
417417
return err == ERR_OK;

libraries/esp8266/examples/SerialStress/SerialStress.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void loop() {
122122
if ((out_idx += local_written_size) == BUFFER_SIZE) {
123123
out_idx = 0;
124124
}
125-
delay(0);
125+
yield();
126126

127127
DEBUG(logger->printf("----------\n"));
128128

0 commit comments

Comments
 (0)