1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

Fix optimistic_yield usage (#588)

This commit is contained in:
Ivan Grokhotkov 2015-07-22 22:50:26 +03:00
parent a9d5ef198a
commit 11594b1340
2 changed files with 14 additions and 7 deletions

View File

@ -122,6 +122,12 @@ int WiFiUDP::available() {
result = static_cast<int>(_ctx->getSize()); 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; return result;
} }

View File

@ -161,13 +161,15 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){
} }
int TwoWire::available(void){ int TwoWire::available(void){
int result = rxBufferLength - rxBufferIndex; int result = rxBufferLength - rxBufferIndex;
if (!result) { if (!result) {
optimistic_yield(); // 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){ int TwoWire::read(void){
@ -209,7 +211,7 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
// // copy twi rx buffer into local read buffer // // copy twi rx buffer into local read buffer
// // this enables new reads to happen in parallel // // this enables new reads to happen in parallel
// for(uint8_t i = 0; i < numBytes; ++i){ // for(uint8_t i = 0; i < numBytes; ++i){
// rxBuffer[i] = inBytes[i]; // rxBuffer[i] = inBytes[i];
// } // }
// // set rx iterator vars // // set rx iterator vars
// rxBufferIndex = 0; // rxBufferIndex = 0;
@ -242,4 +244,3 @@ void TwoWire::onRequest( void (*function)(void) ){
// Preinstantiate Objects ////////////////////////////////////////////////////// // Preinstantiate Objects //////////////////////////////////////////////////////
TwoWire Wire = TwoWire(); TwoWire Wire = TwoWire();