From fc6aad0876d9d4e471bbe790429795c515415514 Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Sat, 23 Dec 2023 11:46:49 +0100 Subject: [PATCH] EthernetC33 debugging --- libraries/Ethernet/src/Ethernet.cpp | 7 +++---- libraries/lwIpWrapper/src/CNetIf.cpp | 17 ++++++++++------- libraries/lwIpWrapper/src/CNetIf.h | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 8f0b789c..22c90ff6 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -76,9 +76,8 @@ void CEthernet::setDNS(IPAddress dns_server) { /* -------------------------------------------------------------------------- */ int CEthernet::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { /* -------------------------------------------------------------------------- */ - int ret = (int)CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac); - begin(timeout, responseTimeout); - return ret; + CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac); + return begin(timeout, responseTimeout); } /* -------------------------------------------------------------------------- */ @@ -111,7 +110,7 @@ int CEthernet::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_ser /* -------------------------------------------------------------------------- */ int CEthernet::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet, unsigned long timeout, unsigned long responseTimeout) { /* -------------------------------------------------------------------------- */ - CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac_address); + CLwipIf::getInstance().setMacAddress(NI_ETHERNET, mac); return begin(local_ip, dns_server, gateway, subnet); } diff --git a/libraries/lwIpWrapper/src/CNetIf.cpp b/libraries/lwIpWrapper/src/CNetIf.cpp index d0d1ce92..53f01dd7 100644 --- a/libraries/lwIpWrapper/src/CNetIf.cpp +++ b/libraries/lwIpWrapper/src/CNetIf.cpp @@ -352,16 +352,19 @@ err_t CEth::output(struct netif* _ni, struct pbuf *p) { err_t errval = ERR_OK; if(eth_output_can_transimit()) { - uint16_t tx_buf_dim = 0; + uint16_t tx_buf_dim = p->tot_len; // TODO analyze the race conditions that may arise from sharing a non synchronized buffer uint8_t *tx_buf = eth_get_tx_buffer(&tx_buf_dim); - assert (p->tot_len <= tx_buf_dim); + if (p->tot_len <= tx_buf_dim) { - uint16_t bytes_actually_copied = pbuf_copy_partial(p, tx_buf, p->tot_len, 0); + uint16_t bytes_actually_copied = pbuf_copy_partial(p, tx_buf, p->tot_len, 0); - if (bytes_actually_copied > 0 && !eth_output(tx_buf, bytes_actually_copied)) { - errval = ERR_IF; + if (bytes_actually_copied > 0 && !eth_output(tx_buf, bytes_actually_copied)) { + errval = ERR_IF; + } + } else { + errval = ERR_MEM; } } else { errval = ERR_INPROGRESS; @@ -516,7 +519,7 @@ bool CLwipIf::setMacAddress(NetIfType_t type, uint8_t* mac) eth_set_mac_address(mac); } - CLwipIf::getInstance().startSyncRequest(); + CLwipIf::getInstance().restartAsyncRequest(); return true; } @@ -546,7 +549,7 @@ int CLwipIf::getMacAddress(NetIfType_t type, uint8_t* mac) rv = MAC_ADDRESS_DIM; } - CLwipIf::getInstance().startSyncRequest(); + CLwipIf::getInstance().restartAsyncRequest(); return rv; } diff --git a/libraries/lwIpWrapper/src/CNetIf.h b/libraries/lwIpWrapper/src/CNetIf.h index e8b91353..0b805d20 100644 --- a/libraries/lwIpWrapper/src/CNetIf.h +++ b/libraries/lwIpWrapper/src/CNetIf.h @@ -148,7 +148,7 @@ class CNetIf { unsigned long dhcp_timeout; DhcpSt_t dhcp_st; bool dhcp_started; - bool dhcp_acquired; + volatile bool dhcp_acquired; uint8_t _dhcp_lease_state; void dhcp_task(); void dhcp_reset();