Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed

#7832

Prev Previous commit
Next Next commit
restore legacy yield(), add minimal_yield(), highlight missing keywords
  • Loading branch information
d-a-v committed Apr 7, 2021
commit a26b2d6256463995a43cb75ccad6cfe6e2f3f310
4 changes: 2 additions & 2 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void setup(void);
void loop(void);

void yield(void);

void optimistic_yield(uint32_t interval_us);
void minimal_yield();
void optimistic_yield(uint32_t interval_us); // parameter ignored, is minimal_yield()

#define _PORT_GPIO16 1
#define digitalPinToPort(pin) (((pin)==16)?(_PORT_GPIO16):(0))
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int HardwareSerial::available(void)
{
int result = static_cast<int>(uart_rx_available(_uart));
if (!result) {
yield();
minimal_yield();
}
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions cores/esp8266/StreamSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ size_t Stream::SendGenericPeekBuffer(Print* to, const ssize_t len, const int rea
break;
}

yield();
minimal_yield();
}

if (getLastSendReport() == Report::Success && maxLen > 0)
Expand Down Expand Up @@ -215,7 +215,7 @@ size_t Stream::SendGenericRegularUntil(Print* to, const ssize_t len, const int r
break;
}

yield();
minimal_yield();
}

if (getLastSendReport() == Report::Success && maxLen > 0)
Expand Down Expand Up @@ -308,7 +308,7 @@ size_t Stream::SendGenericRegular(Print* to, const ssize_t len, const esp8266::p
break;
}

yield();
minimal_yield();
}

if (getLastSendReport() == Report::Success && maxLen > 0)
Expand Down
6 changes: 3 additions & 3 deletions cores/esp8266/core_esp8266_i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static bool _i2s_write_sample(uint32_t sample, bool nb) {
if (tx->slc_queue_len > 0) {
break;
} else {
yield();
minimal_yield();
}
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ static uint16_t _i2s_write_buffer(const int16_t *frames, uint16_t frame_count, b
if (tx->slc_queue_len > 0) {
break;
} else {
yield();
minimal_yield();
}
}
}
Expand Down Expand Up @@ -422,7 +422,7 @@ bool i2s_read_sample(int16_t *left, int16_t *right, bool blocking) {
if (rx->slc_queue_len > 0){
break;
} else {
yield();
minimal_yield();
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ extern "C" void __yield() {
#endif
}

extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));

extern "C" void __optimistic_yield(uint32_t interval_us) {
const uint32_t intvl_cycles = interval_us *
#if defined(F_CPU)
Expand All @@ -158,13 +160,12 @@ extern "C" void __optimistic_yield(uint32_t interval_us) {
}
}

extern "C" void optimistic_yield(uint32_t interval_us) {
(void)interval_us;
extern "C" void minimal_yield() {
__optimistic_yield(DelayBetweenRealYield_usec);
}

extern "C" void yield() {
// at least 1ms between two consecutive yields
extern "C" void optimistic_yield(uint32_t interval_us) {
(void)interval_us;
__optimistic_yield(DelayBetweenRealYield_usec);
}

Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/core_esp8266_wiring_pulse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern uint32_t xthal_get_ccount();
if (xthal_get_ccount() - start_cycle_count > timeout_cycles) { \
return 0; \
} \
yield(); \
minimal_yield(); \
}

// max timeout is 27 seconds at 160MHz clock and 54 seconds at 80MHz clock
Expand Down
6 changes: 3 additions & 3 deletions cores/esp8266/flash_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
}

int32_t flash_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
yield();
minimal_yield();

// We use flashRead overload that handles proper alignment
if (ESP.flashRead(addr, dst, size)) {
Expand All @@ -41,7 +41,7 @@ int32_t flash_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
}

int32_t flash_hal_write(uint32_t addr, uint32_t size, const uint8_t *src) {
yield();
minimal_yield();

// We use flashWrite overload that handles proper alignment
if (ESP.flashWrite(addr, src, size)) {
Expand All @@ -60,7 +60,7 @@ int32_t flash_hal_erase(uint32_t addr, uint32_t size) {
const uint32_t sector = addr / SPI_FLASH_SEC_SIZE;
const uint32_t sectorCount = size / SPI_FLASH_SEC_SIZE;
for (uint32_t i = 0; i < sectorCount; ++i) {
yield();
minimal_yield();
if (!ESP.flashEraseSector(sector + i)) {
DEBUGV("_spif_erase addr=%x size=%d i=%d\r\n", addr, size, i);
return FLASH_HAL_ERASE_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ uart_write(uart_t* uart, const char* buf, size_t size)
const int uart_nr = uart->uart_nr;
while (size--) {
uart_do_write_char(uart_nr, pgm_read_byte(buf++));
yield();
minimal_yield();
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int WiFiClient::available()
int result = _client->getSize();

if (!result) {
yield();
minimal_yield();
}
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ size_t WiFiClientSecureCtx::_write(const uint8_t *buf, size_t size, bool pmem) {
do {
// Ensure we yield if we need multiple fragments to avoid WDT
if (sent_bytes) {
yield();
minimal_yield();
}

// Get BearSSL to a state where we can send
Expand Down Expand Up @@ -479,7 +479,7 @@ int WiFiClientSecureCtx::_run_until(unsigned target, bool blocking) {
esp8266::polledTimeout::oneShotMs loopTimeout(_timeout);

for (int no_work = 0; blocking || no_work < 2;) {
yield();
minimal_yield();

if (loopTimeout) {
DEBUG_BSSL("_run_until: Timeout\n");
Expand Down Expand Up @@ -605,7 +605,7 @@ bool WiFiClientSecureCtx::_wait_for_handshake() {
if (br_ssl_engine_current_state(_eng) & BR_SSL_SENDAPP) {
_handshake_done = true;
}
yield();
minimal_yield();
}
return _handshake_done;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ WiFiClient WiFiServer::available(byte* status) {
return result;
}

yield();
minimal_yield();
return WiFiClient();
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiServerSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ WiFiClientSecure WiFiServerSecure::available(uint8_t* status) {
}

// Something weird, return a no-op object
yield();
minimal_yield();
return WiFiClientSecure();
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int WiFiUDP::available() {
if (!result) {
// yielding here will not make more data "available",
// but it will prevent the system from going into WDT reset
yield();
minimal_yield();
}

return result;
Expand Down Expand Up @@ -195,7 +195,7 @@ int WiFiUDP::parsePacket()
return 0;

if (!_ctx->next()) {
yield();
minimal_yield();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ int TwoWire::available(void)
{
// yielding here will not make more data "available",
// but it will prevent the system from going into WDT reset
yield();
minimal_yield();
}

return result;
Expand Down
2 changes: 2 additions & 0 deletions libraries/esp8266/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ChaCha20Poly1305 KEYWORD1
# Methods and Functions (KEYWORD2)
#######################################

optimistic_yield KEYWORD2
minimal_yield KEYWORD2
wdtEnable KEYWORD2
wdtDisable KEYWORD2
wdtFeed KEYWORD2
Expand Down