diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index cd3b16f6a..299a97996 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -1,8 +1,8 @@ -/* +/* Esp.cpp - ESP8266-specific APIs Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -32,7 +32,7 @@ extern struct rst_info resetInfo; //#define DEBUG_SERIAL Serial - + /** * User-defined Literals * usage: @@ -92,7 +92,7 @@ void EspClass::wdtEnable(WDTO_t timeout_ms) void EspClass::wdtDisable(void) { - /// Please don’t stop software watchdog too long (less than 6 seconds), + /// Please don't stop software watchdog too long (less than 6 seconds), /// otherwise it will trigger hardware watchdog reset. system_soft_wdt_stop(); } @@ -102,13 +102,15 @@ void EspClass::wdtFeed(void) } +extern "C" void esp_yield(); + void EspClass::deepSleep(uint32_t time_us, WakeMode mode) { - system_deep_sleep_set_option(static_cast(mode)); - system_deep_sleep(time_us); + system_deep_sleep_set_option(static_cast(mode)); + system_deep_sleep(time_us); + esp_yield(); } -extern "C" void esp_yield(); extern "C" void __real_system_restart_local(); void EspClass::reset(void) { @@ -119,9 +121,6 @@ void EspClass::restart(void) { system_restart(); esp_yield(); - // todo: provide an alternative code path if this was called - // from system context, not from continuation - // (implement esp_is_cont_ctx()?) } uint16_t EspClass::getVcc(void) @@ -333,7 +332,7 @@ uint32_t EspClass::getSketchSize() { DEBUG_SERIAL.printf("num_segments=%u\r\n", image_header.num_segments); #endif for (uint32_t section_index = 0; - section_index < image_header.num_segments; + section_index < image_header.num_segments; ++section_index) { section_header_t section_header = {0}; @@ -395,8 +394,7 @@ bool EspClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool #ifdef DEBUG_SERIAL DEBUG_SERIAL.println("Update SUCCESS"); -#endif +#endif if(restartOnSuccess) ESP.restart(); return true; } - diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 67c3f3802..a953c8782 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -74,7 +74,9 @@ extern "C" void abort() { } extern "C" void esp_yield() { - cont_yield(&g_cont); + if (cont_can_yield(&g_cont)) { + cont_yield(&g_cont); + } } extern "C" void esp_schedule() {