From 1d78f9ddd595ee210db49bbf9760aa3d7ed559a5 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Sat, 30 May 2020 15:46:17 +0300 Subject: [PATCH] ethernetIdle() weak handler was added in order to execute some code while DNS requests and TCP:open/close awaiting for results --- src/Dhcp.cpp | 4 +++- src/Dns.cpp | 6 ++++-- src/Ethernet.cpp | 3 +++ src/EthernetClient.cpp | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) 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 dfa91125..4f4e4e7a 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 9257090c..f53ca0b4 100644 --- a/src/Ethernet.cpp +++ b/src/Ethernet.cpp @@ -244,3 +244,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 e2406d7d..407010e9 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);