1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-10-28 17:15:26 +03:00

PHY status API for ethernet drivers (#8784)

* PHY status API for W5500 & ENC28J60 drivers
* move linkStatus() from ArduinoEthernet:: to LwipIntfDev::
* LwipIntfDev: include PHY status into ::connected()
This commit is contained in:
david gauchard
2023-01-05 09:23:57 +01:00
committed by GitHub
parent c9f90a3ed3
commit 7cfb551f90
7 changed files with 112 additions and 17 deletions

View File

@@ -46,6 +46,13 @@
#define DEFAULT_MTU 1500
#endif
enum EthernetLinkStatus
{
Unknown,
LinkON,
LinkOFF
};
template<class RawDev>
class LwipIntfDev: public LwipIntf, public RawDev
{
@@ -93,9 +100,11 @@ public:
void setDefault(bool deflt = true);
// true if interface has a valid IPv4 address
// (and ethernet link status is not detectable or is up)
bool connected()
{
return !!ip4_addr_get_u32(ip_2_ip4(&_netif.ip_addr));
return !!ip4_addr_get_u32(ip_2_ip4(&_netif.ip_addr))
&& (!RawDev::isLinkDetectable() || RawDev::isLinked());
}
bool routable()
@@ -106,6 +115,9 @@ public:
// ESP8266WiFi API compatibility
wl_status_t status();
// Arduino Ethernet compatibility
EthernetLinkStatus linkStatus();
protected:
err_t netif_init();
void check_route();
@@ -282,6 +294,12 @@ wl_status_t LwipIntfDev<RawDev>::status()
return _started ? (connected() ? WL_CONNECTED : WL_DISCONNECTED) : WL_NO_SHIELD;
}
template<class RawDev>
EthernetLinkStatus LwipIntfDev<RawDev>::linkStatus()
{
return RawDev::isLinkDetectable() ? _started && RawDev::isLinked() ? LinkON : LinkOFF : Unknown;
}
template<class RawDev>
err_t LwipIntfDev<RawDev>::linkoutput_s(netif* netif, struct pbuf* pbuf)
{