diff --git a/src/Dhcp.cpp b/src/Dhcp.cpp index 2bfd584b..f5c22597 100644 --- a/src/Dhcp.cpp +++ b/src/Dhcp.cpp @@ -5,6 +5,7 @@ #include "Ethernet.h" #include "Dhcp.h" #include "utility/w5100.h" +extern void ethernetIdle(void); int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { @@ -244,7 +245,8 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr if ((millis() - startTime) > responseTimeout) { return 255; } - delay(50); + ethernetIdle(); + delay(1); } // start reading in the packet RIP_MSG_FIXED fixedMsg; diff --git a/src/Dns.cpp b/src/Dns.cpp index dca7ce42..53afb60f 100644 --- a/src/Dns.cpp +++ b/src/Dns.cpp @@ -6,7 +6,7 @@ #include "Ethernet.h" #include "Dns.h" #include "utility/w5100.h" - +extern void ethernetIdle(void); #define SOCKET_NONE 255 // Various flags and header field values for a DNS message @@ -120,6 +120,8 @@ int DNSClient::getHostByName(const char* aHostname, IPAddress& aResult, uint16_t while ((wait_retries < 3) && (ret == TIMED_OUT)) { ret = ProcessResponse(timeout, aResult); wait_retries++; + ethernetIdle(); + delay(1); } } } @@ -220,7 +222,7 @@ uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress& aAddress) if ((millis() - startTime) > aTimeout) { return TIMED_OUT; } - delay(50); + ethernetIdle(); } // We've had a reply! diff --git a/src/Ethernet.cpp b/src/Ethernet.cpp index 8d9ce7fd..1299a708 100644 --- a/src/Ethernet.cpp +++ b/src/Ethernet.cpp @@ -234,3 +234,6 @@ void EthernetClass::setRetransmissionCount(uint8_t num) EthernetClass Ethernet; + +void ethernetIdle(void) __attribute__ ((weak)); +void ethernetIdle(void) {delay(10);}; \ No newline at end of file diff --git a/src/EthernetClient.cpp b/src/EthernetClient.cpp index 5a20c748..84cdcc3f 100644 --- a/src/EthernetClient.cpp +++ b/src/EthernetClient.cpp @@ -22,6 +22,7 @@ #include "Ethernet.h" #include "Dns.h" #include "utility/w5100.h" +extern void ethernetIdle(void); int EthernetClient::connect(const char * host, uint16_t port) { @@ -62,6 +63,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) if (stat == SnSR::CLOSE_WAIT) return 1; if (stat == SnSR::CLOSED) return 0; if (millis() - start > _timeout) break; + ethernetIdle(); delay(1); } Ethernet.socketClose(_sockindex); @@ -143,6 +145,7 @@ void EthernetClient::stop() _sockindex = MAX_SOCK_NUM; return; // exit the loop } + ethernetIdle(); delay(1); } while (millis() - start < _timeout);