diff options
Diffstat (limited to 'libraries/Ethernet/utility')
-rw-r--r-- | libraries/Ethernet/utility/socket.cpp | 7 | ||||
-rwxr-xr-x | libraries/Ethernet/utility/socket.h | 2 | ||||
-rw-r--r-- | libraries/Ethernet/utility/w5100.cpp | 4 | ||||
-rwxr-xr-x | libraries/Ethernet/utility/w5100.h | 9 |
4 files changed, 14 insertions, 8 deletions
diff --git a/libraries/Ethernet/utility/socket.cpp b/libraries/Ethernet/utility/socket.cpp index 4875845..fd3e442 100644 --- a/libraries/Ethernet/utility/socket.cpp +++ b/libraries/Ethernet/utility/socket.cpp @@ -9,7 +9,6 @@ static uint16_t local_port; */ uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag) { - uint8_t ret; if ((protocol == SnMR::TCP) || (protocol == SnMR::UDP) || (protocol == SnMR::IPRAW) || (protocol == SnMR::MACRAW) || (protocol == SnMR::PPPOE)) { close(s); @@ -144,15 +143,15 @@ uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len) * * @return received data size for success else -1. */ -uint16_t recv(SOCKET s, uint8_t *buf, uint16_t len) +int16_t recv(SOCKET s, uint8_t *buf, int16_t len) { // Check how much data is available - uint16_t ret = W5100.getRXReceivedSize(s); + int16_t ret = W5100.getRXReceivedSize(s); if ( ret == 0 ) { // No data available. uint8_t status = W5100.readSnSR(s); - if ( s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::CLOSE_WAIT ) + if ( status == SnSR::LISTEN || status == SnSR::CLOSED || status == SnSR::CLOSE_WAIT ) { // The remote end has closed its side of the connection, so this is the eof state ret = 0; diff --git a/libraries/Ethernet/utility/socket.h b/libraries/Ethernet/utility/socket.h index 37ea93f..45e0fb3 100755 --- a/libraries/Ethernet/utility/socket.h +++ b/libraries/Ethernet/utility/socket.h @@ -9,7 +9,7 @@ extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TC extern void disconnect(SOCKET s); // disconnect the connection extern uint8_t listen(SOCKET s); // Establish TCP connection (Passive connection) extern uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len); // Send data (TCP) -extern uint16_t recv(SOCKET s, uint8_t * buf, uint16_t len); // Receive data (TCP) +extern int16_t recv(SOCKET s, uint8_t * buf, int16_t len); // Receive data (TCP) extern uint16_t peek(SOCKET s, uint8_t *buf); extern uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); // Send data (UDP/IP RAW) extern uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port); // Receive data (UDP/IP RAW) diff --git a/libraries/Ethernet/utility/w5100.cpp b/libraries/Ethernet/utility/w5100.cpp index aafabae..9c748fd 100644 --- a/libraries/Ethernet/utility/w5100.cpp +++ b/libraries/Ethernet/utility/w5100.cpp @@ -140,7 +140,7 @@ uint8_t W5100Class::write(uint16_t _addr, uint8_t _data) uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len) { - for (int i=0; i<_len; i++) + for (uint16_t i=0; i<_len; i++) { setSS(); SPI.transfer(0xF0); @@ -166,7 +166,7 @@ uint8_t W5100Class::read(uint16_t _addr) uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len) { - for (int i=0; i<_len; i++) + for (uint16_t i=0; i<_len; i++) { setSS(); SPI.transfer(0x0F); diff --git a/libraries/Ethernet/utility/w5100.h b/libraries/Ethernet/utility/w5100.h index 9872c7c..153aedb 100755 --- a/libraries/Ethernet/utility/w5100.h +++ b/libraries/Ethernet/utility/w5100.h @@ -270,7 +270,10 @@ private: } \ static uint16_t read##name(SOCKET _s) { \ uint16_t res = readSn(_s, address); \ - res = (res << 8) + readSn(_s, address + 1); \ + uint16_t res2 = readSn(_s,address + 1); \ + res = res << 8; \ + res2 = res2 & 0xFF; \ + res = res | res2; \ return res; \ } #define __SOCKET_REGISTER_N(name, address, size) \ @@ -324,6 +327,10 @@ private: inline static void initSS() { DDRB |= _BV(4); }; inline static void setSS() { PORTB &= ~_BV(4); }; inline static void resetSS() { PORTB |= _BV(4); }; +#elif defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__) + inline static void initSS() { DDRB |= _BV(0); }; + inline static void setSS() { PORTB &= ~_BV(0); }; + inline static void resetSS() { PORTB |= _BV(0); }; #else inline static void initSS() { DDRB |= _BV(2); }; inline static void setSS() { PORTB &= ~_BV(2); }; |