Skip to content

Commit f159ce6

Browse files
committed
call yield() if client.write() is waiting for free memory block
1 parent fc499eb commit f159ce6

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The modernization includes:
88
* SPI transactions to share the SPI bus with devices with different communication settings
99
* SPI communication at 20 MHz if the MCU supports it, else on the maximum supported by the MCU
1010
* client.flush() to send the packet immediately
11+
* calls yield() in blocking functions
1112

1213
[The documentation of Arduino Ethernet library](https://www.arduino.cc/en/Reference/Ethernet) applies for classes and functions descriptions.
1314

src/Ethernet.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,20 @@ void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway,
330330
_dnsServerAddress = dns;
331331
}
332332

333+
void
334+
UIPEthernetClass::call_yield()
335+
{
336+
static bool in_yield;
337+
static uint32_t last_call_millis;
338+
if (!in_yield && millis() - last_call_millis > 0)
339+
{
340+
last_call_millis = millis();
341+
in_yield = true;
342+
yield();
343+
in_yield = false;
344+
}
345+
}
346+
333347
/*---------------------------------------------------------------------------*/
334348
uint16_t
335349
UIPEthernetClass::chksum(uint16_t sum, const uint8_t *data, uint16_t len)

src/Ethernet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class UIPEthernetClass
117117

118118
static boolean network_send();
119119

120+
static void call_yield();
121+
120122
friend class EthernetServer;
121123

122124
friend class EthernetClient;

src/EthernetClient.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ UIPClient::write(const uint8_t *buf, size_t size)
184184
goto ready;
185185
}
186186
#endif
187+
Ethernet.call_yield();
187188
goto repeat;
188189
}
189190
u->out_pos = 0;
@@ -217,6 +218,7 @@ UIPClient::write(const uint8_t *buf, size_t size)
217218
goto ready;
218219
}
219220
#endif
221+
Ethernet.call_yield();
220222
goto repeat;
221223
}
222224
p++;

0 commit comments

Comments
 (0)