mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Add wait loop at the end of mode, refactor can_yield (#6721)
* Add wait loop at the end of mode, refactor can_yield * fix mock build
This commit is contained in:
parent
6f7eb2828a
commit
453eb2d064
@ -90,6 +90,9 @@ void preloop_update_frequency() {
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" bool can_yield() {
|
||||
return cont_can_yield(g_pcont);
|
||||
}
|
||||
|
||||
static inline void esp_yield_within_cont() __attribute__((always_inline));
|
||||
static void esp_yield_within_cont() {
|
||||
@ -98,7 +101,7 @@ static void esp_yield_within_cont() {
|
||||
}
|
||||
|
||||
extern "C" void esp_yield() {
|
||||
if (cont_can_yield(g_pcont)) {
|
||||
if (can_yield()) {
|
||||
esp_yield_within_cont();
|
||||
}
|
||||
}
|
||||
@ -109,7 +112,7 @@ extern "C" void esp_schedule() {
|
||||
}
|
||||
|
||||
extern "C" void __yield() {
|
||||
if (cont_can_yield(g_pcont)) {
|
||||
if (can_yield()) {
|
||||
esp_schedule();
|
||||
esp_yield_within_cont();
|
||||
}
|
||||
@ -121,7 +124,7 @@ extern "C" void __yield() {
|
||||
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
|
||||
|
||||
extern "C" void optimistic_yield(uint32_t interval_us) {
|
||||
if (cont_can_yield(g_pcont) &&
|
||||
if (can_yield() &&
|
||||
(system_get_time() - s_micros_at_task_start) > interval_us)
|
||||
{
|
||||
yield();
|
||||
|
@ -14,6 +14,7 @@ extern "C" {
|
||||
|
||||
extern bool timeshift64_is_set;
|
||||
|
||||
bool can_yield();
|
||||
void esp_yield();
|
||||
void esp_schedule();
|
||||
void tune_timeshift64 (uint64_t now_us);
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <list>
|
||||
#include <string.h>
|
||||
#include <coredecls.h>
|
||||
#include <PolledTimeout.h>
|
||||
#include "ESP8266WiFi.h"
|
||||
#include "ESP8266WiFiGeneric.h"
|
||||
|
||||
@ -434,6 +435,25 @@ bool ESP8266WiFiGenericClass::mode(WiFiMode_t m, WiFiState* state) {
|
||||
}
|
||||
ETS_UART_INTR_ENABLE();
|
||||
|
||||
if(!ret)
|
||||
return false; //calling wifi_set_opmode failed
|
||||
|
||||
//Wait for mode change, which is asynchronous.
|
||||
//Only wait if in CONT context. If this were called from SYS, it's up to the user to serialize
|
||||
//tasks to wait correctly.
|
||||
constexpr unsigned int timeoutValue = 1000; //1 second
|
||||
if(can_yield()) {
|
||||
using oneShot = esp8266::polledTimeout::oneShotFastUs;
|
||||
oneShot timeout(timeoutValue);
|
||||
while(wifi_get_opmode() != (uint8) m && !timeout)
|
||||
delay(5);
|
||||
|
||||
//if at this point mode still hasn't been reached, give up
|
||||
if(wifi_get_opmode() != (uint8) m) {
|
||||
return false; //timeout
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,11 @@ extern "C" void yield()
|
||||
{
|
||||
}
|
||||
|
||||
extern "C" bool can_yield()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" void optimistic_yield (uint32_t interval_us)
|
||||
{
|
||||
usleep(interval_us);
|
||||
@ -69,3 +74,4 @@ cont_t* g_pcont = NULL;
|
||||
extern "C" void cont_yield(cont_t*)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user