diff --git a/Ethernet/Dhcp.cpp b/Dhcp.cpp similarity index 100% rename from Ethernet/Dhcp.cpp rename to Dhcp.cpp diff --git a/Ethernet/Dhcp.h b/Dhcp.h similarity index 100% rename from Ethernet/Dhcp.h rename to Dhcp.h diff --git a/Ethernet/Dns.cpp b/Dns.cpp similarity index 100% rename from Ethernet/Dns.cpp rename to Dns.cpp diff --git a/Ethernet/Dns.h b/Dns.h similarity index 100% rename from Ethernet/Dns.h rename to Dns.h diff --git a/Ethernet/Ethernet.cpp b/Ethernet.cpp similarity index 99% rename from Ethernet/Ethernet.cpp rename to Ethernet.cpp index f5582dc..b69e9c8 100644 --- a/Ethernet/Ethernet.cpp +++ b/Ethernet.cpp @@ -15,7 +15,9 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, }; int EthernetClass::begin(void) { byte mac_address[6] ={0,}; - _dhcp = new DhcpClass(); + + if(_dhcp == NULL) + _dhcp = new DhcpClass(); // Initialise the basic info W5100.init(); diff --git a/Ethernet/Ethernet.h b/Ethernet.h similarity index 98% rename from Ethernet/Ethernet.h rename to Ethernet.h index a115ee6..9dba31f 100644 --- a/Ethernet/Ethernet.h +++ b/Ethernet.h @@ -19,6 +19,8 @@ class EthernetClass { IPAddress _dnsServerAddress; DhcpClass* _dhcp; public: + EthernetClass() : _dhcp(NULL) {} + static uint8_t _state[MAX_SOCK_NUM]; static uint16_t _server_port[MAX_SOCK_NUM]; diff --git a/Ethernet/EthernetClient.cpp b/EthernetClient.cpp similarity index 100% rename from Ethernet/EthernetClient.cpp rename to EthernetClient.cpp diff --git a/Ethernet/EthernetClient.h b/EthernetClient.h similarity index 100% rename from Ethernet/EthernetClient.h rename to EthernetClient.h diff --git a/Ethernet/EthernetServer.cpp b/EthernetServer.cpp similarity index 100% rename from Ethernet/EthernetServer.cpp rename to EthernetServer.cpp diff --git a/Ethernet/EthernetServer.h b/EthernetServer.h similarity index 100% rename from Ethernet/EthernetServer.h rename to EthernetServer.h diff --git a/Ethernet/EthernetUdp.cpp b/EthernetUdp.cpp similarity index 97% rename from Ethernet/EthernetUdp.cpp rename to EthernetUdp.cpp index 3760052..6e35fa7 100644 --- a/Ethernet/EthernetUdp.cpp +++ b/EthernetUdp.cpp @@ -120,8 +120,6 @@ int EthernetUDP::parsePacket() // discard any remaining bytes in the last packet flush(); - if (W5100.getRXReceivedSize(_sock) > 0) - { //HACK - hand-parse the UDP packet using TCP recv method uint8_t tmpBuf[8]; int ret =0; @@ -139,9 +137,6 @@ int EthernetUDP::parsePacket() ret = _remaining; } return ret; - } - // There aren't any packets available - return 0; } int EthernetUDP::read() @@ -210,9 +205,9 @@ void EthernetUDP::flush() // should only occur if recv fails after telling us the data is there, lets // hope the w5100 always behaves :) - while (_remaining) + if (_remaining) { - read(); + W5100.skip(_sock, _remaining); } } diff --git a/Ethernet/EthernetUdp.h b/EthernetUdp.h similarity index 100% rename from Ethernet/EthernetUdp.h rename to EthernetUdp.h diff --git a/Ethernet/Twitter.cpp b/Twitter.cpp similarity index 100% rename from Ethernet/Twitter.cpp rename to Twitter.cpp diff --git a/Ethernet/Twitter.h b/Twitter.h similarity index 100% rename from Ethernet/Twitter.h rename to Twitter.h diff --git a/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino similarity index 100% rename from Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino rename to examples/BarometricPressureWebServer/BarometricPressureWebServer.ino diff --git a/Ethernet/examples/ChatServer/ChatServer.ino b/examples/ChatServer/ChatServer.ino similarity index 100% rename from Ethernet/examples/ChatServer/ChatServer.ino rename to examples/ChatServer/ChatServer.ino diff --git a/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino similarity index 100% rename from Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino rename to examples/DhcpAddressPrinter/DhcpAddressPrinter.ino diff --git a/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/examples/DhcpChatServer/DhcpChatServer.ino similarity index 100% rename from Ethernet/examples/DhcpChatServer/DhcpChatServer.ino rename to examples/DhcpChatServer/DhcpChatServer.ino diff --git a/Ethernet/examples/TelnetClient/TelnetClient.ino b/examples/TelnetClient/TelnetClient.ino similarity index 100% rename from Ethernet/examples/TelnetClient/TelnetClient.ino rename to examples/TelnetClient/TelnetClient.ino diff --git a/Ethernet/examples/Twitter_Serial_GW/Twitter_Serial_GW.ino b/examples/Twitter_Serial_GW/Twitter_Serial_GW.ino similarity index 100% rename from Ethernet/examples/Twitter_Serial_GW/Twitter_Serial_GW.ino rename to examples/Twitter_Serial_GW/Twitter_Serial_GW.ino diff --git a/Ethernet/examples/Twitter_SimplePost/Twitter_SimplePost.ino b/examples/Twitter_SimplePost/Twitter_SimplePost.ino similarity index 100% rename from Ethernet/examples/Twitter_SimplePost/Twitter_SimplePost.ino rename to examples/Twitter_SimplePost/Twitter_SimplePost.ino diff --git a/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/examples/UDPSendReceiveString/UDPSendReceiveString.ino similarity index 100% rename from Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino rename to examples/UDPSendReceiveString/UDPSendReceiveString.ino diff --git a/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/examples/UdpNtpClient/UdpNtpClient.ino similarity index 100% rename from Ethernet/examples/UdpNtpClient/UdpNtpClient.ino rename to examples/UdpNtpClient/UdpNtpClient.ino diff --git a/Ethernet/examples/WebClient/WebClient.ino b/examples/WebClient/WebClient.ino similarity index 100% rename from Ethernet/examples/WebClient/WebClient.ino rename to examples/WebClient/WebClient.ino diff --git a/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/examples/WebClientRepeating/WebClientRepeating.ino similarity index 100% rename from Ethernet/examples/WebClientRepeating/WebClientRepeating.ino rename to examples/WebClientRepeating/WebClientRepeating.ino diff --git a/Ethernet/examples/WebServer/WebServer.ino b/examples/WebServer/WebServer.ino similarity index 100% rename from Ethernet/examples/WebServer/WebServer.ino rename to examples/WebServer/WebServer.ino diff --git a/Ethernet/examples/XivelyClient/XivelyClient.ino b/examples/XivelyClient/XivelyClient.ino similarity index 100% rename from Ethernet/examples/XivelyClient/XivelyClient.ino rename to examples/XivelyClient/XivelyClient.ino diff --git a/Ethernet/examples/XivelyClientString/XivelyClientString.ino b/examples/XivelyClientString/XivelyClientString.ino similarity index 100% rename from Ethernet/examples/XivelyClientString/XivelyClientString.ino rename to examples/XivelyClientString/XivelyClientString.ino diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..a115ca9 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,42 @@ +####################################### +# Syntax Coloring Map For Ethernet +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Ethernet KEYWORD1 +EthernetClient KEYWORD1 +EthernetServer KEYWORD1 +IPAddress KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +status KEYWORD2 +connect KEYWORD2 +write KEYWORD2 +available KEYWORD2 +read KEYWORD2 +peek KEYWORD2 +flush KEYWORD2 +stop KEYWORD2 +connected KEYWORD2 +begin KEYWORD2 +beginPacket KEYWORD2 +endPacket KEYWORD2 +parsePacket KEYWORD2 +remoteIP KEYWORD2 +remotePort KEYWORD2 +setRXMemorySizes KEYWORD2 +setTXMemorySizes KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +W5100_ETHERNET_SHIELD LITERAL1 +W5200_ETHERNET_SHIELD LITERAL1 +W5500_ETHERNET_SHIELD LITERAL1 diff --git a/Ethernet/util.h b/util.h similarity index 100% rename from Ethernet/util.h rename to util.h diff --git a/Ethernet/utility/socket.cpp b/utility/socket.cpp similarity index 97% rename from Ethernet/utility/socket.cpp rename to utility/socket.cpp index fd3e442..971c4bd 100644 --- a/Ethernet/utility/socket.cpp +++ b/utility/socket.cpp @@ -99,8 +99,8 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len) uint16_t ret=0; uint16_t freesize=0; - if (len > W5100.SSIZE) - ret = W5100.SSIZE; // check size not to exceed MAX size. + if (len > W5100.SSIZE[s]) + ret = W5100.SSIZE[s]; // check size not to exceed MAX size. else ret = len; @@ -199,7 +199,7 @@ uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint1 { uint16_t ret=0; - if (len > W5100.SSIZE) ret = W5100.SSIZE; // check size not to exceed MAX size. + if (len > W5100.SSIZE[s]) ret = W5100.SSIZE[s]; // check size not to exceed MAX size. else ret = len; if @@ -316,8 +316,8 @@ uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len) uint8_t status=0; uint16_t ret=0; - if (len > W5100.SSIZE) - ret = W5100.SSIZE; // check size not to exceed MAX size. + if (len > W5100.SSIZE[s]) + ret = W5100.SSIZE[s]; // check size not to exceed MAX size. else ret = len; diff --git a/Ethernet/utility/socket.h b/utility/socket.h similarity index 100% rename from Ethernet/utility/socket.h rename to utility/socket.h diff --git a/Ethernet/utility/w5100.cpp b/utility/w5100.cpp similarity index 73% rename from Ethernet/utility/w5100.cpp rename to utility/w5100.cpp index 679504e..21d0984 100644 --- a/Ethernet/utility/w5100.cpp +++ b/utility/w5100.cpp @@ -34,12 +34,49 @@ void W5100Class::init(void) initSS(); writeMR(1<> 10; + uint8_t log2 = 0; + while (size >>= 1) ++log2; + msr |= log2 << (i * 2); + } + writeTMSR(msr); + + SMASK[0] = SSIZE[0] - 1; + SBASE[0] = TXBUF_BASE; + for (int i=1; i> 10; + uint8_t log2 = 0; + while (size >>= 1) ++log2; + msr |= log2 << (i * 2); + } + writeRMSR(msr); + + RMASK[0] = RSIZE[0] - 1; + RBASE[0] = RXBUF_BASE; + for (int i=1; i SSIZE) + if (offset + len > SSIZE[s]) { // Wrap around circular buffer - uint16_t size = SSIZE - offset; + uint16_t size = SSIZE[s] - offset; write(dstAddr, data, size); write(SBASE[s], data + size, len - size); } @@ -109,18 +146,26 @@ void W5100Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uin } } +void W5100Class::skip(SOCKET s, uint16_t len) +{ + uint16_t ptr; + ptr = readSnRX_RD(s); + ptr += len; + writeSnRX_RD(s, ptr); +} + void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len) { uint16_t size; uint16_t src_mask; uint16_t src_ptr; - src_mask = (uint16_t)src & RMASK; + src_mask = (uint16_t)src & RMASK[s]; src_ptr = RBASE[s] + src_mask; - if( (src_mask + len) > RSIZE ) + if( (src_mask + len) > RSIZE[s] ) { - size = RSIZE - src_mask; + size = RSIZE[s] - src_mask; read(src_ptr, (uint8_t *)dst, size); dst += size; read(RBASE[s], (uint8_t *) dst, len - size); diff --git a/Ethernet/utility/w5100.h b/utility/w5100.h similarity index 96% rename from Ethernet/utility/w5100.h rename to utility/w5100.h index 3bfb1aa..44e99e0 100644 --- a/Ethernet/utility/w5100.h +++ b/utility/w5100.h @@ -16,8 +16,8 @@ typedef uint8_t SOCKET; //#define W5100_ETHERNET_SHIELD // Arduino Ethenret Shield and Compatibles ... -//#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield -#define W5500_ETHERNET_SHIELD // WIZ550io, ioShield series of WIZnet +#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield +//#define W5500_ETHERNET_SHIELD // WIZ550io, ioShield series of WIZnet #if defined(W5500_ETHERNET_SHIELD) #define WIZ550io_WITH_MACADDRESS // Use assigned MAC address of WIZ550io @@ -183,6 +183,13 @@ class W5100Class { */ void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek = 0); + /** + * @brief Moves the Rx read pointer forward + * + * This function allows you to skip a number of bytes in the Rx pointer register. + */ + void skip(SOCKET s, uint16_t len); + inline void setGatewayIp(uint8_t *_addr); inline void getGatewayIp(uint8_t *_addr); @@ -203,6 +210,8 @@ class W5100Class { uint16_t getTXFreeSize(SOCKET s); uint16_t getRXReceivedSize(SOCKET s); + void setTXMemorySizes(uint16_t * sizes); + void setRXMemorySizes(uint16_t * sizes); // W5100 Registers // --------------- @@ -327,12 +336,12 @@ class W5100Class { static const uint8_t RST = 7; // Reset BIT static const int SOCKETS = 4; - static const uint16_t SMASK = 0x07FF; // Tx buffer MASK - static const uint16_t RMASK = 0x07FF; // Rx buffer MASK + uint16_t SMASK[SOCKETS]; // Tx buffer MASK + uint16_t RMASK[SOCKETS]; // Rx buffer MASK public: - static const uint16_t SSIZE = 2048; // Max Tx buffer size + uint16_t SSIZE[SOCKETS]; // Max Tx buffer size private: - static const uint16_t RSIZE = 2048; // Max Rx buffer size + uint16_t RSIZE[SOCKETS]; // Max Rx buffer size uint16_t SBASE[SOCKETS]; // Tx buffer base address uint16_t RBASE[SOCKETS]; // Rx buffer base address diff --git a/Ethernet/utility/w5200.cpp b/utility/w5200.cpp similarity index 77% rename from Ethernet/utility/w5200.cpp rename to utility/w5200.cpp index 5e2aa8a..8fbfe71 100644 --- a/Ethernet/utility/w5200.cpp +++ b/utility/w5200.cpp @@ -33,13 +33,36 @@ void W5200Class::init(void) writeMR(1<> 10); + } + SMASK[0] = SSIZE[0] - 1; + SBASE[0] = TXBUF_BASE; + for (int i=1; i> 10); + } + RMASK[0] = RSIZE[0] - 1; + RBASE[0] = RXBUF_BASE; + for (int i=1; i SSIZE) + if (offset + len > SSIZE[s]) { // Wrap around circular buffer - uint16_t size = SSIZE - offset; + uint16_t size = SSIZE[s] - offset; write(dstAddr, data, size); write(SBASE[s], data + size, len - size); } @@ -109,18 +132,26 @@ void W5200Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uin } } +void W5200Class::skip(SOCKET s, uint16_t len) +{ + uint16_t ptr; + ptr = readSnRX_RD(s); + ptr += len; + writeSnRX_RD(s, ptr); +} + void W5200Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len) { uint16_t size; uint16_t src_mask; uint16_t src_ptr; - src_mask = (uint16_t)src & RMASK; + src_mask = (uint16_t)src & RMASK[s]; src_ptr = RBASE[s] + src_mask; - if( (src_mask + len) > RSIZE ) + if( (src_mask + len) > RSIZE[s] ) { - size = RSIZE - src_mask; + size = RSIZE[s] - src_mask; read(src_ptr, (uint8_t *)dst, size); dst += size; read(RBASE[s], (uint8_t *) dst, len - size); diff --git a/Ethernet/utility/w5200.h b/utility/w5200.h similarity index 96% rename from Ethernet/utility/w5200.h rename to utility/w5200.h index 22b1db6..d73de47 100644 --- a/Ethernet/utility/w5200.h +++ b/utility/w5200.h @@ -163,6 +163,13 @@ class W5200Class { */ void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek = 0); + /** + * @brief Moves the Rx read pointer forward + * + * This function allows you to skip a number of bytes in the Rx pointer register. + */ + void skip(SOCKET s, uint16_t len); + inline void setGatewayIp(uint8_t *_addr); inline void getGatewayIp(uint8_t *_addr); @@ -183,6 +190,8 @@ class W5200Class { uint16_t getTXFreeSize(SOCKET s); uint16_t getRXReceivedSize(SOCKET s); + void setTXMemorySizes(uint16_t * sizes); + void setRXMemorySizes(uint16_t * sizes); // W5100 Registers // --------------- @@ -303,12 +312,12 @@ class W5200Class { private: static const uint8_t RST = 7; // Reset BIT static const int SOCKETS = 8; - static const uint16_t SMASK = 0x07FF; // Tx buffer MASK - static const uint16_t RMASK = 0x07FF; // Rx buffer MASK + uint16_t SMASK[SOCKETS]; // Tx buffer MASK + uint16_t RMASK[SOCKETS]; // Rx buffer MASK public: - static const uint16_t SSIZE = 2048; // Max Tx buffer size + uint16_t SSIZE[SOCKETS]; // Max Tx buffer size private: - static const uint16_t RSIZE = 2048; // Max Rx buffer size + uint16_t RSIZE[SOCKETS]; // Max Rx buffer size uint16_t SBASE[SOCKETS]; // Tx buffer base address uint16_t RBASE[SOCKETS]; // Rx buffer base address diff --git a/Ethernet/utility/w5500.cpp b/utility/w5500.cpp similarity index 83% rename from Ethernet/utility/w5500.cpp rename to utility/w5500.cpp index 07694b9..233e01a 100644 --- a/Ethernet/utility/w5500.cpp +++ b/utility/w5500.cpp @@ -25,10 +25,26 @@ void W5500Class::init(void) delay(300); SPI.begin(); + uint16_t sizes[MAX_SOCK_NUM] = {2048,2048,2048,2048,2048,2048,2048,2048}; + setTXMemorySizes(sizes); + setRXMemorySizes(sizes); +} + +void W5500Class::setTXMemorySizes(uint16_t * sizes) +{ for (int i=0; i> 10); //0x1F - Sn_TXBUF_SIZE + } +} + +void W5500Class::setRXMemorySizes(uint16_t * sizes) +{ + for (int i=0; i> 10); //0x1E - Sn_RXBUF_SIZE } } @@ -88,6 +104,14 @@ void W5500Class::recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uin } } +void W5500Class::skip(SOCKET s, uint16_t len) +{ + uint16_t ptr; + ptr = readSnRX_RD(s); + ptr += len; + writeSnRX_RD(s, ptr); +} + void W5500Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *dst, uint16_t len) { uint8_t cntl_byte = (0x18+(s<<5)); diff --git a/Ethernet/utility/w5500.h b/utility/w5500.h similarity index 97% rename from Ethernet/utility/w5500.h rename to utility/w5500.h index f0a9882..b87468e 100644 --- a/Ethernet/utility/w5500.h +++ b/utility/w5500.h @@ -166,6 +166,13 @@ class W5500Class { */ void recv_data_processing(SOCKET s, uint8_t *data, uint16_t len, uint8_t peek = 0); + /** + * @brief Moves the Rx read pointer forward + * + * This function allows you to skip a number of bytes in the Rx pointer register. + */ + void skip(SOCKET s, uint16_t len); + inline void setGatewayIp(uint8_t *_addr); inline void getGatewayIp(uint8_t *_addr); @@ -189,6 +196,8 @@ class W5500Class { uint16_t getTXFreeSize(SOCKET s); uint16_t getRXReceivedSize(SOCKET s); + void setTXMemorySizes(uint16_t * sizes); + void setRXMemorySizes(uint16_t * sizes); // W5500 Registers // --------------- @@ -324,9 +333,9 @@ class W5500Class { static const int SOCKETS = 8; public: - static const uint16_t SSIZE = 2048; // Max Tx buffer size + uint16_t SSIZE[SOCKETS]; // Max Tx buffer size private: - static const uint16_t RSIZE = 2048; // Max Rx buffer size + uint16_t RSIZE[SOCKETS]; // Max Rx buffer size private: #if defined(REL_GR_KURUMI) || defined(REL_GR_KURUMI_PROTOTYPE)