Skip to content

Commit

Permalink
Fix optimistic_yield usage (esp8266#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Jul 22, 2015
1 parent a9d5ef1 commit 11594b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions libraries/ESP8266WiFi/src/WiFiUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ int WiFiUDP::available() {
result = static_cast<int>(_ctx->getSize());
}

if (!result) {
// yielding here will not make more data "available",
// but it will prevent the system from going into WDT reset
optimistic_yield(1000);
}

return result;
}

Expand Down
15 changes: 8 additions & 7 deletions libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){
}

int TwoWire::available(void){
int result = rxBufferLength - rxBufferIndex;
int result = rxBufferLength - rxBufferIndex;

if (!result) {
optimistic_yield();
}
if (!result) {
// yielding here will not make more data "available",
// but it will prevent the system from going into WDT reset
optimistic_yield(1000);
}

return result;
return result;
}

int TwoWire::read(void){
Expand Down Expand Up @@ -209,7 +211,7 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
// // copy twi rx buffer into local read buffer
// // this enables new reads to happen in parallel
// for(uint8_t i = 0; i < numBytes; ++i){
// rxBuffer[i] = inBytes[i];
// rxBuffer[i] = inBytes[i];
// }
// // set rx iterator vars
// rxBufferIndex = 0;
Expand Down Expand Up @@ -242,4 +244,3 @@ void TwoWire::onRequest( void (*function)(void) ){
// Preinstantiate Objects //////////////////////////////////////////////////////

TwoWire Wire = TwoWire();

0 comments on commit 11594b1

Please sign in to comment.