Skip to content

Commit 29ccc06

Browse files
committed
Fix optimistic_yield usage (#588)
1 parent 4354ef9 commit 29ccc06

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiUdp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ int WiFiUDP::available() {
122122
result = static_cast<int>(_ctx->getSize());
123123
}
124124

125+
if (!result) {
126+
// yielding here will not make more data "available",
127+
// but it will prevent the system from going into WDT reset
128+
optimistic_yield(1000);
129+
}
130+
125131
return result;
126132
}
127133

hardware/esp8266com/esp8266/libraries/Wire/Wire.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){
161161
}
162162

163163
int TwoWire::available(void){
164-
int result = rxBufferLength - rxBufferIndex;
164+
int result = rxBufferLength - rxBufferIndex;
165165

166-
if (!result) {
167-
optimistic_yield();
168-
}
166+
if (!result) {
167+
// yielding here will not make more data "available",
168+
// but it will prevent the system from going into WDT reset
169+
optimistic_yield(1000);
170+
}
169171

170-
return result;
172+
return result;
171173
}
172174

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

244246
TwoWire Wire = TwoWire();
245-

0 commit comments

Comments
 (0)