diff --git a/keywords.txt b/keywords.txt index 9fd25419..0013e20a 100644 --- a/keywords.txt +++ b/keywords.txt @@ -65,3 +65,4 @@ EthernetNoHardware LITERAL1 EthernetW5100 LITERAL1 EthernetW5200 LITERAL1 EthernetW5500 LITERAL1 +EthernetW5100S LITERAL1 diff --git a/src/Ethernet.cpp b/src/Ethernet.cpp index 658bd642..28658623 100644 --- a/src/Ethernet.cpp +++ b/src/Ethernet.cpp @@ -114,6 +114,7 @@ EthernetLinkStatus EthernetClass::linkStatus() EthernetHardwareStatus EthernetClass::hardwareStatus() { switch (W5100.getChip()) { + case 50: return EthernetW5100S; case 51: return EthernetW5100; case 52: return EthernetW5200; case 55: return EthernetW5500; diff --git a/src/Ethernet.h b/src/Ethernet.h index 376e6c59..dbc9a63d 100644 --- a/src/Ethernet.h +++ b/src/Ethernet.h @@ -63,7 +63,8 @@ enum EthernetHardwareStatus { EthernetNoHardware, EthernetW5100, EthernetW5200, - EthernetW5500 + EthernetW5500, + EthernetW5100S }; class EthernetUDP; diff --git a/src/EthernetServer.cpp b/src/EthernetServer.cpp index ddebd154..5e91534b 100644 --- a/src/EthernetServer.cpp +++ b/src/EthernetServer.cpp @@ -46,7 +46,7 @@ EthernetClient EthernetServer::available() chip = W5100.getChip(); if (!chip) return EthernetClient(MAX_SOCK_NUM); #if MAX_SOCK_NUM > 4 - if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets + if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets #endif for (uint8_t i=0; i < maxindex; i++) { if (server_port[i] == _port) { @@ -81,7 +81,7 @@ EthernetClient EthernetServer::accept() chip = W5100.getChip(); if (!chip) return EthernetClient(MAX_SOCK_NUM); #if MAX_SOCK_NUM > 4 - if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets + if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets #endif for (uint8_t i=0; i < maxindex; i++) { if (server_port[i] == _port) { @@ -108,7 +108,7 @@ EthernetServer::operator bool() { uint8_t maxindex=MAX_SOCK_NUM; #if MAX_SOCK_NUM > 4 - if (W5100.getChip() == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets + if (W5100.getChip() == 51 || W5100.getChip() == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets #endif for (uint8_t i=0; i < maxindex; i++) { if (server_port[i] == _port) { @@ -165,7 +165,7 @@ size_t EthernetServer::write(const uint8_t *buffer, size_t size) chip = W5100.getChip(); if (!chip) return 0; #if MAX_SOCK_NUM > 4 - if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets + if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets #endif available(); for (uint8_t i=0; i < maxindex; i++) { diff --git a/src/socket.cpp b/src/socket.cpp index f059dc92..43f068ef 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -68,7 +68,7 @@ uint8_t EthernetClass::socketBegin(uint8_t protocol, uint16_t port) chip = W5100.getChip(); if (!chip) return MAX_SOCK_NUM; // immediate error if no hardware detected #if MAX_SOCK_NUM > 4 - if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets + if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets #endif //Serial.printf("W5000socket begin, protocol=%d, port=%d\n", protocol, port); SPI.beginTransaction(SPI_ETHERNET_SETTINGS); @@ -132,7 +132,7 @@ uint8_t EthernetClass::socketBeginMulticast(uint8_t protocol, IPAddress ip, uint chip = W5100.getChip(); if (!chip) return MAX_SOCK_NUM; // immediate error if no hardware detected #if MAX_SOCK_NUM > 4 - if (chip == 51) maxindex = 4; // W5100 chip never supports more than 4 sockets + if (chip == 51 || chip == 50) maxindex = 4; // W5100 chip never supports more than 4 sockets #endif //Serial.printf("W5000socket begin, protocol=%d, port=%d\n", protocol, port); SPI.beginTransaction(SPI_ETHERNET_SETTINGS); diff --git a/src/utility/w5100.cpp b/src/utility/w5100.cpp index 4ae4ee7a..132f5319 100644 --- a/src/utility/w5100.cpp +++ b/src/utility/w5100.cpp @@ -157,7 +157,29 @@ uint8_t W5100Class::init(void) writeSnTX_SIZE(i, 0); } #endif - // Try W5100 last. This simple chip uses fixed 4 byte frames + // Try W5100S. Brandnew based W5100. + } else if (isW5100S()) { + CH_BASE_MSB = 0x04; +#ifdef ETHERNET_LARGE_BUFFERS +#if MAX_SOCK_NUM <= 1 + SSIZE = 8192; + writeTMSR(0x03); + writeRMSR(0x03); +#elif MAX_SOCK_NUM <= 2 + SSIZE = 4096; + writeTMSR(0x0A); + writeRMSR(0x0A); +#else + SSIZE = 2048; + writeTMSR(0x55); + writeRMSR(0x55); +#endif + SMASK = SSIZE - 1; +#else + writeTMSR(0x55); + writeRMSR(0x55); +#endif +// Try W5100 last. This simple chip uses fixed 4 byte frames // for every 8 bit access. Terribly inefficient, but so simple // it recovers from "hearing" unsuccessful W5100 or W5200 // communication. W5100 is also the only chip without a VERSIONR @@ -210,7 +232,7 @@ uint8_t W5100Class::softReset(void) uint8_t mr = readMR(); //Serial.print("mr="); //Serial.println(mr, HEX); - if (mr == 0) return 1; + if (mr == 0 || (mr == 3 && chip == 50)) return 1; delay(1); } while (++count < 20); return 0; @@ -231,6 +253,23 @@ uint8_t W5100Class::isW5100(void) return 1; } +uint8_t W5100Class::isW5100S(void) +{ + chip = 50; + //Serial.println("w5100.cpp: detect W5100S chip"); + if (!softReset()) return 0; + writeMR(0x13); + if (readMR() != 0x13) return 0; + writeMR(0x03); + if (readMR() != 0x03) return 0; + int ver = readVERSIONR_W5100S(); + //Serial.print("version="); + //Serial.println(ver); + if (ver != 81) return 0; + //Serial.println("chip is W5100S"); + return 1; +} + uint8_t W5100Class::isW5200(void) { chip = 52; @@ -275,6 +314,12 @@ W5100Linkstatus W5100Class::getLinkStatus() if (!init()) return UNKNOWN; switch (chip) { + case 50: + SPI.beginTransaction(SPI_ETHERNET_SETTINGS); + phystatus = readPHYCFGR_W5100S(); + SPI.endTransaction(); + if (phystatus & 0x01) return LINK_ON; + return LINK_OFF; case 52: SPI.beginTransaction(SPI_ETHERNET_SETTINGS); phystatus = readPSTATUS_W5200(); @@ -296,7 +341,7 @@ uint16_t W5100Class::write(uint16_t addr, const uint8_t *buf, uint16_t len) { uint8_t cmd[8]; - if (chip == 51) { + if (chip == 51 || chip == 50) { for (uint16_t i=0; i