1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-08 11:22:40 +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

@@ -106,6 +106,7 @@ void serial_printf(const char* fmt, ...)
#define MACONX_BANK 0x02
#define MACON1 0x00
#define MACSTAT1 0x01
#define MACON3 0x02
#define MACON4 0x03
#define MABBIPG 0x04
@@ -113,6 +114,16 @@ void serial_printf(const char* fmt, ...)
#define MAIPGH 0x07
#define MAMXFLL 0x0a
#define MAMXFLH 0x0b
#define MACON2 0x10
#define MACSTAT2 0x11
#define MICMD 0x12
#define MIREGADR 0x14
#define MIRDL 0x18
#define MIRDH 0x19
/* MICMD Register Bit Definitions */
#define MICMD_MIISCAN 0x02
#define MICMD_MIIRD 0x01
#define MACON1_TXPAUS 0x08
#define MACON1_RXPAUS 0x04
@@ -135,6 +146,9 @@ void serial_printf(const char* fmt, ...)
#define MISTAT 0x0a
#define EREVID 0x12
/* MISTAT Register Bit Definitions */
#define MISTAT_BUSY 0x01
#define EPKTCNT_BANK 0x01
#define ERXFCON 0x18
#define EPKTCNT 0x19
@@ -720,3 +734,26 @@ uint16_t ENC28J60::readFrameData(uint8_t* buffer, uint16_t framesize)
return _len;
}
uint16_t ENC28J60::phyread(uint8_t reg)
{
// ( https://github.com/JAndrassy/EthernetENC/tree/master/src/utility/enc28j60.h )
setregbank(MACONX_BANK);
writereg(MIREGADR, reg);
writereg(MICMD, MICMD_MIIRD);
// wait until the PHY read completes
while (readreg(MISTAT) & MISTAT_BUSY)
{
delayMicroseconds(15);
}
writereg(MICMD, 0);
return (readreg(MIRDL) | readreg(MIRDH) << 8);
}
bool ENC28J60::isLinked()
{
// ( https://github.com/JAndrassy/EthernetENC/tree/master/src/utility/enc28j60.h )
return !!(phyread(MACSTAT2) & 0x400);
}

View File

@@ -79,6 +79,21 @@ public:
*/
virtual uint16_t readFrame(uint8_t* buffer, uint16_t bufsize);
/**
Check physical link
@return true when physical link is up
*/
bool isLinked();
/**
Report whether ::isLinked() API is implemented
@return true when ::isLinked() API is implemented
*/
constexpr bool isLinkDetectable() const
{
return true;
}
protected:
static constexpr bool interruptIsPossible()
{
@@ -133,6 +148,8 @@ private:
// Previously defined in contiki/core/sys/clock.h
void clock_delay_usec(uint16_t dt);
uint16_t phyread(uint8_t reg);
uint8_t _bank;
int8_t _cs;
SPIClass& _spi;