Skip to content

Commit 97d59ae

Browse files
committed
Consolidate renaming of identifiers to clarify strict meaning of suspend vs. yield
1 parent 9bb4894 commit 97d59ae

22 files changed

+78
-76
lines changed

cores/esp8266/Esp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
119119
{
120120
system_deep_sleep_set_option(static_cast<int>(mode));
121121
system_deep_sleep(time_us);
122-
esp_yield();
122+
esp_suspend();
123123
}
124124

125125
void EspClass::deepSleepInstant(uint64_t time_us, WakeMode mode)
126126
{
127127
system_deep_sleep_set_option(static_cast<int>(mode));
128128
system_deep_sleep_instant(time_us);
129-
esp_yield();
129+
esp_suspend();
130130
}
131131

132132
//this calculation was taken verbatim from the SDK api reference for SDK 2.1.0.
@@ -198,7 +198,7 @@ void EspClass::reset(void)
198198
void EspClass::restart(void)
199199
{
200200
system_restart();
201-
esp_yield();
201+
esp_suspend();
202202
}
203203

204204
[[noreturn]] void EspClass::rebootIntoUartDownloadMode()

cores/esp8266/PolledTimeout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct DoNothing
4646

4747
struct YieldOrSkip
4848
{
49-
static void execute() {esp_break();}
49+
static void execute() {esp_yield();}
5050
};
5151

5252
template <unsigned long delayMs>

cores/esp8266/Schedule.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ void run_scheduled_functions()
164164
if (yieldNow)
165165
{
166166
// because scheduled functions might last too long for watchdog etc,
167-
// this is yield() in cont stack:
167+
// this is yield() in cont stack, but need to call cont_suspend directly
168+
// to prevent recursion into run_scheduled_recurrent_functions()
168169
esp_schedule();
169-
cont_yield(g_pcont);
170+
cont_suspend(g_pcont);
170171
}
171172
}
172173
}
@@ -241,9 +242,10 @@ void run_scheduled_recurrent_functions()
241242
if (yieldNow)
242243
{
243244
// because scheduled functions might last too long for watchdog etc,
244-
// this is yield() in cont stack:
245+
// this is yield() in cont stack, but need to call cont_suspend directly
246+
// to prevent recursion into run_scheduled_recurrent_functions()
245247
esp_schedule();
246-
cont_yield(g_pcont);
248+
cont_suspend(g_pcont);
247249
}
248250
} while (current && !done);
249251

cores/esp8266/cont.S

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
.section .irom0.text
2222
.align 4
2323
.literal_position
24-
.global cont_yield
25-
.type cont_yield, @function
26-
cont_yield:
24+
.global cont_suspend
25+
.type cont_suspend, @function
26+
cont_suspend:
2727
/* a1: sp */
2828
/* a2: void* cont_ctx */
2929
/* adjust stack and save registers */
@@ -35,10 +35,10 @@ cont_yield:
3535
s32i a0, a1, 16
3636
s32i a2, a1, 20
3737

38-
/* &cont_continue -> cont_ctx.pc_yield */
38+
/* &cont_continue -> cont_ctx.pc_suspend */
3939
movi a3, cont_continue
4040
s32i a3, a2, 8
41-
/* sp -> cont_ctx.sp_yield */
41+
/* sp -> cont_ctx.sp_suspend */
4242
s32i a1, a2, 12
4343

4444
/* a0 <- cont_ctx.pc_ret */
@@ -56,7 +56,7 @@ cont_continue:
5656
l32i a2, a1, 20
5757
addi a1, a1, 24
5858
ret
59-
.size cont_yield, . - cont_yield
59+
.size cont_suspend, . - cont_suspend
6060

6161
////////////////////////////////////////////////////
6262

@@ -108,7 +108,7 @@ cont_run:
108108
/* sp -> cont_ctx.sp_ret */
109109
s32i a1, a2, 4
110110

111-
/* if cont_ctx.pc_yield != 0, goto cont_resume */
111+
/* if cont_ctx.pc_suspend != 0, goto cont_resume */
112112
l32i a4, a2, 8
113113
bnez a4, cont_resume
114114
/* else */
@@ -119,12 +119,12 @@ cont_run:
119119
jx a2
120120

121121
cont_resume:
122-
/* a1 <- cont_ctx.sp_yield */
122+
/* a1 <- cont_ctx.sp_suspend */
123123
l32i a1, a2, 12
124-
/* reset yield flag, 0 -> cont_ctx.pc_yield */
124+
/* reset yield flag, 0 -> cont_ctx.pc_suspend */
125125
movi a3, 0
126126
s32i a3, a2, 8
127-
/* jump to saved cont_ctx.pc_yield */
127+
/* jump to saved cont_ctx.pc_suspend */
128128
movi a0, cont_ret
129129
jx a4
130130

cores/esp8266/cont.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ typedef struct cont_ {
3535
void (*pc_ret)(void);
3636
unsigned* sp_ret;
3737

38-
void (*pc_yield)(void);
39-
unsigned* sp_yield;
38+
void (*pc_suspend)(void);
39+
unsigned* sp_suspend;
4040

4141
unsigned* stack_end;
4242
unsigned unused1;
@@ -55,12 +55,12 @@ extern cont_t* g_pcont;
5555
void cont_init(cont_t*);
5656

5757
// Run function pfn in a separate stack, or continue execution
58-
// at the point where cont_yield was called
58+
// at the point where cont_suspend was called
5959
void cont_run(cont_t*, void (*pfn)(void));
6060

6161
// Return to the point where cont_run was called, saving the
6262
// execution state (registers and stack)
63-
void cont_yield(cont_t*);
63+
void cont_suspend(cont_t*);
6464

6565
// Check guard bytes around the stack. Return 0 in case everything is ok,
6666
// return 1 if guard bytes were overwritten.
@@ -70,9 +70,9 @@ int cont_check(cont_t* cont);
7070
// and thus weren't used by the user code. i.e. that stack space is free. (high water mark)
7171
int cont_get_free_stack(cont_t* cont);
7272

73-
// Check if yield() may be called. Returns true if we are running inside
73+
// Check if cont_suspend() may be called. Returns true if we are running inside
7474
// continuation stack
75-
bool cont_can_yield(cont_t* cont);
75+
bool cont_can_suspend(cont_t* cont);
7676

7777
// Repaint the stack from the current SP to the end, to allow individual
7878
// routines' stack usages to be calculated by re-painting, checking current

cores/esp8266/cont_util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ int cont_get_free_stack(cont_t* cont) {
6262
return freeWords * 4;
6363
}
6464

65-
bool IRAM_ATTR cont_can_yield(cont_t* cont) {
65+
bool IRAM_ATTR cont_can_suspend(cont_t* cont) {
6666
return !ETS_INTR_WITHINISR() &&
67-
cont->pc_ret != 0 && cont->pc_yield == 0;
67+
cont->pc_ret != 0 && cont->pc_suspend == 0;
6868
}
6969

7070
// No need for this to be in IRAM, not expected to be IRQ called

cores/esp8266/core_esp8266_main.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cont_t* g_pcont __attribute__((section(".noinit")));
6262
static os_event_t s_loop_queue[LOOP_QUEUE_SIZE];
6363

6464
/* Used to implement optimistic_yield */
65-
static uint32_t s_cycles_at_yield_start;
65+
static uint32_t s_cycles_at_resume;
6666

6767
/* For ets_intr_lock_nest / ets_intr_unlock_nest
6868
* Max nesting seen by SDK so far is 2.
@@ -106,41 +106,41 @@ extern "C" void __preloop_update_frequency() {
106106
extern "C" void preloop_update_frequency() __attribute__((weak, alias("__preloop_update_frequency")));
107107

108108
extern "C" bool can_yield() {
109-
return cont_can_yield(g_pcont);
109+
return cont_can_suspend(g_pcont);
110110
}
111111

112-
static inline void esp_yield_within_cont() __attribute__((always_inline));
113-
static void esp_yield_within_cont() {
114-
cont_yield(g_pcont);
115-
s_cycles_at_yield_start = ESP.getCycleCount();
112+
static inline void esp_suspend_within_cont() __attribute__((always_inline));
113+
static void esp_suspend_within_cont() {
114+
cont_suspend(g_pcont);
115+
s_cycles_at_resume = ESP.getCycleCount();
116116
run_scheduled_recurrent_functions();
117117
}
118118

119-
extern "C" void __esp_yield() {
120-
if (can_yield()) {
121-
esp_yield_within_cont();
119+
extern "C" void __esp_suspend() {
120+
if (cont_can_suspend(g_pcont)) {
121+
esp_suspend_within_cont();
122122
}
123123
}
124124

125-
extern "C" void esp_yield() __attribute__ ((weak, alias("__esp_yield")));
125+
extern "C" void esp_suspend() __attribute__ ((weak, alias("__esp_suspend")));
126126

127127
extern "C" IRAM_ATTR void esp_schedule() {
128128
ets_post(LOOP_TASK_PRIORITY, 0, 0);
129129
}
130130

131131
// 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
132+
// in SYS, esp_yield() is safe to call and only schedules CONT. Use yield()
133+
// whereever only called from CONT, use esp_yield() if code is called from SYS
134134
// or both CONT and SYS.
135-
extern "C" void esp_break() {
135+
extern "C" void esp_yield() {
136136
esp_schedule();
137-
esp_yield();
137+
esp_suspend();
138138
}
139139

140140
extern "C" void __yield() {
141-
if (can_yield()) {
141+
if (cont_can_suspend(g_pcont)) {
142142
esp_schedule();
143-
esp_yield_within_cont();
143+
esp_suspend_within_cont();
144144
}
145145
else {
146146
panic();
@@ -156,7 +156,7 @@ extern "C" void optimistic_yield(uint32_t interval_us) {
156156
#else
157157
ESP.getCpuFreqMHz();
158158
#endif
159-
if ((ESP.getCycleCount() - s_cycles_at_yield_start) > intvl_cycles &&
159+
if ((ESP.getCycleCount() - s_cycles_at_resume) > intvl_cycles &&
160160
can_yield())
161161
{
162162
yield();
@@ -216,7 +216,7 @@ static void loop_wrapper() {
216216

217217
static void loop_task(os_event_t *events) {
218218
(void) events;
219-
s_cycles_at_yield_start = ESP.getCycleCount();
219+
s_cycles_at_resume = ESP.getCycleCount();
220220
ESP.resetHeap();
221221
cont_run(g_pcont, &loop_wrapper);
222222
ESP.setDramHeap();

cores/esp8266/core_esp8266_waveform_pwm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static IRAM_ATTR void _notifyPWM(PWMState *p, bool idle) {
163163
forceTimerInterrupt();
164164
while (pwmState.pwmUpdate) {
165165
if (idle) {
166-
esp_break();
166+
esp_yield();
167167
}
168168
MEMBARRIER();
169169
}

cores/esp8266/core_esp8266_wiring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void __delay(unsigned long ms) {
4747
} else {
4848
esp_schedule();
4949
}
50-
esp_yield();
50+
esp_suspend();
5151
if(ms) {
5252
os_timer_disarm(&delay_timer);
5353
}

cores/esp8266/coredecls.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ extern "C" {
1313
#include <cont.h> // g_pcont declaration
1414

1515
bool can_yield();
16-
void esp_yield();
16+
void esp_suspend();
1717
void esp_schedule();
18-
void esp_break();
18+
void esp_yield();
1919
void tune_timeshift64 (uint64_t now_us);
2020
void disable_extra4k_at_link_time (void) __attribute__((noinline));
2121
bool sntp_set_timezone_in_seconds(int32_t timezone);

cores/esp8266/hwdt_app_entry.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,13 @@ STATIC void IRAM_MAYBE handle_hwdt(void) {
952952
/* Print separate ctx: cont stack */
953953

954954
/* Check if cont stack is yielding to SYS */
955-
if (0 == hwdt_info.cont_integrity && 0 != g_pcont->pc_yield) {
956-
ctx_cont_ptr = (const uint32_t *)((uintptr_t)g_pcont->sp_yield - 8u);
955+
if (0 == hwdt_info.cont_integrity && 0 != g_pcont->pc_suspend) {
956+
ctx_cont_ptr = (const uint32_t *)((uintptr_t)g_pcont->sp_suspend - 8u);
957957
}
958958
print_stack((uintptr_t)ctx_cont_ptr, (uintptr_t)g_pcont->stack_end, PRINT_STACK::CONT);
959959
} else {
960-
if (0 == hwdt_info.cont_integrity && 0 != g_pcont->pc_yield) {
961-
ETS_PRINTF("\nCont stack is yielding. Active stack starts at 0x%08X.\n", (uint32_t)g_pcont->sp_yield - 8u);
960+
if (0 == hwdt_info.cont_integrity && 0 != g_pcont->pc_suspend) {
961+
ETS_PRINTF("\nCont stack is yielding. Active stack starts at 0x%08X.\n", (uint32_t)g_pcont->sp_suspend - 8u);
962962
}
963963
}
964964

cores/esp8266/uart.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ uart_wait_tx_empty(uart_t* uart)
567567
return;
568568

569569
while(uart_tx_fifo_available(uart->uart_nr) > 0)
570-
esp_break();
570+
esp_yield();
571571

572572
}
573573

@@ -948,7 +948,7 @@ inline __attribute__((always_inline)) void
948948
uart_write_char_delay(const int uart_nr, char c)
949949
{
950950
while(uart_tx_fifo_full(uart_nr))
951-
esp_break();
951+
esp_yield();
952952

953953
USF(uart_nr) = c;
954954

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
568568
if (transferred != size)
569569
{
570570
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] short write, asked for %d but got %d failed.\n", size, transferred);
571-
esp_break();
571+
esp_yield();
572572
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
573573
}
574574

@@ -711,7 +711,7 @@ int HTTPClient::writeToPrint(Print * print)
711711
return returnError(HTTPC_ERROR_READ_TIMEOUT);
712712
}
713713

714-
esp_break();
714+
esp_yield();
715715
}
716716
} else {
717717
return returnError(HTTPC_ERROR_ENCODING);
@@ -1076,7 +1076,7 @@ int HTTPClient::handleHeaderResponse()
10761076
if((millis() - lastDataTime) > _tcpTimeout) {
10771077
return HTTPC_ERROR_READ_TIMEOUT;
10781078
}
1079-
esp_break();
1079+
esp_yield();
10801080
}
10811081
}
10821082

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
120120
Update.end();
121121
if (_serial_output) Serial.println("Update was aborted");
122122
}
123-
esp_break();
123+
esp_yield();
124124
});
125125
}
126126

libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ bool ESP8266WiFiGenericClass::forceSleepBegin(uint32 sleepUs) {
514514
}
515515

516516
wifi_fpm_set_sleep_type(MODEM_SLEEP_T);
517-
esp_break();
517+
esp_yield();
518518
wifi_fpm_open();
519-
esp_break();
519+
esp_yield();
520520
auto ret = wifi_fpm_do_sleep(sleepUs);
521521
if (ret != 0)
522522
{

libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static wl_status_t waitWiFiConnect(uint32_t connectTimeoutMs)
9292
// Wait for WiFi status change or timeout
9393
do {
9494
// Refresh watchdog
95-
esp_break();
95+
esp_yield();
9696

9797
// Get WiFi status
9898
status = WiFi.status();
@@ -250,7 +250,7 @@ int8_t ESP8266WiFiMulti::startScan()
250250
// Wait for WiFi scan change or timeout
251251
do {
252252
// Refresh watchdog
253-
esp_break();
253+
esp_yield();
254254

255255
// Check scan timeout which may occur when scan does not report completion
256256
if (scanTimeout) {
@@ -536,7 +536,7 @@ void ESP8266WiFiMulti::printWiFiScan()
536536
rssi,
537537
(encryptionType == ENC_TYPE_NONE) ? ' ' : '*',
538538
ssid.c_str());
539-
esp_break();
539+
esp_yield();
540540
}
541541
#endif
542542
}

0 commit comments

Comments
 (0)