Skip to content

Commit 608f734

Browse files
committed
Return to scheduler context from ESP::deepSleep (esp8266#609)
1 parent ac459eb commit 608f734

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

hardware/esp8266com/esp8266/cores/esp8266/Esp.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/*
1+
/*
22
Esp.cpp - ESP8266-specific APIs
33
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
44
This file is part of the esp8266 core for Arduino environment.
5-
5+
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
88
License as published by the Free Software Foundation; either
@@ -32,7 +32,7 @@ extern struct rst_info resetInfo;
3232

3333
//#define DEBUG_SERIAL Serial
3434

35-
35+
3636
/**
3737
* User-defined Literals
3838
* usage:
@@ -92,7 +92,7 @@ void EspClass::wdtEnable(WDTO_t timeout_ms)
9292

9393
void EspClass::wdtDisable(void)
9494
{
95-
/// Please dont stop software watchdog too long (less than 6 seconds),
95+
/// Please don't stop software watchdog too long (less than 6 seconds),
9696
/// otherwise it will trigger hardware watchdog reset.
9797
system_soft_wdt_stop();
9898
}
@@ -102,13 +102,15 @@ void EspClass::wdtFeed(void)
102102

103103
}
104104

105+
extern "C" void esp_yield();
106+
105107
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
106108
{
107-
system_deep_sleep_set_option(static_cast<int>(mode));
108-
system_deep_sleep(time_us);
109+
system_deep_sleep_set_option(static_cast<int>(mode));
110+
system_deep_sleep(time_us);
111+
esp_yield();
109112
}
110113

111-
extern "C" void esp_yield();
112114
extern "C" void __real_system_restart_local();
113115
void EspClass::reset(void)
114116
{
@@ -119,9 +121,6 @@ void EspClass::restart(void)
119121
{
120122
system_restart();
121123
esp_yield();
122-
// todo: provide an alternative code path if this was called
123-
// from system context, not from continuation
124-
// (implement esp_is_cont_ctx()?)
125124
}
126125

127126
uint16_t EspClass::getVcc(void)
@@ -333,7 +332,7 @@ uint32_t EspClass::getSketchSize() {
333332
DEBUG_SERIAL.printf("num_segments=%u\r\n", image_header.num_segments);
334333
#endif
335334
for (uint32_t section_index = 0;
336-
section_index < image_header.num_segments;
335+
section_index < image_header.num_segments;
337336
++section_index)
338337
{
339338
section_header_t section_header = {0};
@@ -395,8 +394,7 @@ bool EspClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool
395394

396395
#ifdef DEBUG_SERIAL
397396
DEBUG_SERIAL.println("Update SUCCESS");
398-
#endif
397+
#endif
399398
if(restartOnSuccess) ESP.restart();
400399
return true;
401400
}
402-

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ extern "C" void abort() {
7474
}
7575

7676
extern "C" void esp_yield() {
77-
cont_yield(&g_cont);
77+
if (cont_can_yield(&g_cont)) {
78+
cont_yield(&g_cont);
79+
}
7880
}
7981

8082
extern "C" void esp_schedule() {

0 commit comments

Comments
 (0)