diff --git a/libraries/WiFi/arch/avr/WiFiClient.cpp b/libraries/WiFi/arch/avr/WiFiClient.cpp index cd996305c..d669191ab 100644 --- a/libraries/WiFi/arch/avr/WiFiClient.cpp +++ b/libraries/WiFi/arch/avr/WiFiClient.cpp @@ -104,7 +104,10 @@ int WiFiClient::read() { int WiFiClient::read(uint8_t* buf, size_t size) { - if (!ServerDrv::getDataBuf(_sock, buf, &size)) + // sizeof(size_t) is architecture dependent + // but we need a 16 bit data type here + uint16_t _size = size; + if (!ServerDrv::getDataBuf(_sock, buf, &_size)) return -1; return 0; } diff --git a/libraries/WiFi/arch/avr/WiFiUdp.cpp b/libraries/WiFi/arch/avr/WiFiUdp.cpp index d4d6795c7..19e087f4c 100644 --- a/libraries/WiFi/arch/avr/WiFiUdp.cpp +++ b/libraries/WiFi/arch/avr/WiFiUdp.cpp @@ -115,7 +115,7 @@ int WiFiUDP::read(unsigned char* buffer, size_t len) { if (available()) { - size_t size = 0; + uint16_t size = 0; if (!ServerDrv::getDataBuf(_sock, buffer, &size)) return -1; // TODO check if the buffer is too smal respect to buffer size diff --git a/libraries/WiFi/arch/avr/utility/socket.h b/libraries/WiFi/arch/avr/utility/socket.h index de3cc786a..a9c73f210 100644 --- a/libraries/WiFi/arch/avr/utility/socket.h +++ b/libraries/WiFi/arch/avr/utility/socket.h @@ -15,73 +15,20 @@ #define SOCK_NOT_AVAIL 255 #include "utility/wl_definitions.h" -/** - * The 8-bit signed data type. - */ -typedef char int8; -/** - * The volatile 8-bit signed data type. - */ -typedef volatile char vint8; -/** - * The 8-bit unsigned data type. - */ -typedef unsigned char uint8; -/** - * The volatile 8-bit unsigned data type. - */ -typedef volatile unsigned char vuint8; -/** - * The 16-bit signed data type. - */ -typedef int int16; -/** - * The volatile 16-bit signed data type. - */ -typedef volatile int vint16; -/** - * The 16-bit unsigned data type. - */ -typedef unsigned int uint16; -/** - * The volatile 16-bit unsigned data type. - */ -typedef volatile unsigned int vuint16; -/** - * The 32-bit signed data type. - */ -typedef long int32; -/** - * The volatile 32-bit signed data type. - */ -typedef volatile long vint32; -/** - * The 32-bit unsigned data type. - */ -typedef unsigned long uint32; -/** - * The volatile 32-bit unsigned data type. - */ -typedef volatile unsigned long vuint32; +typedef uint16_t SOCKET; -/* bsd */ -typedef uint8 u_char; /**< 8-bit value */ -typedef uint16_t SOCKET; -typedef uint16 u_short; /**< 16-bit value */ -typedef uint16 u_int; /**< 16-bit value */ -typedef uint32 u_long; /**< 32-bit value */ - -extern SOCKET socket(uint8 protocol); // Opens a socket(TCP or UDP or IP_RAW mode) +extern SOCKET socket(uint8_t protocol); // Opens a socket(TCP or UDP or IP_RAW mode) extern void close(SOCKET s); // Close socket -extern uint8 connect(SOCKET s, uint8 * addr, uint16 port); // Establish TCP connection (Active connection) +extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TCP connection (Active connection) extern void disconnect(SOCKET s); // disconnect the connection -extern uint8 listen(SOCKET s); // Establish TCP connection (Passive connection) -extern uint16 send(SOCKET s, const uint8 * buf, uint16 len); // Send data (TCP) -extern uint16 recv(SOCKET s, uint8 * buf, uint16 len); // Receive data (TCP) -extern uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port); // Send data (UDP/IP RAW) -extern uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port); // Receive data (UDP/IP RAW) +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 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) + +extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len); -extern uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len); #endif /* _SOCKET_H_ */ diff --git a/libraries/WiFi/arch/avr/utility/spi_drv.cpp b/libraries/WiFi/arch/avr/utility/spi_drv.cpp index 7f56fe867..b5a1d0696 100644 --- a/libraries/WiFi/arch/avr/utility/spi_drv.cpp +++ b/libraries/WiFi/arch/avr/utility/spi_drv.cpp @@ -8,15 +8,14 @@ extern "C" { #include "utility/debug.h" } -#define DATAOUT 11 // MOSI -#define DATAIN 12 // MISO -#define SPICLOCK 13 // sck -#define SLAVESELECT 10 // ss -#define SLAVEREADY 7 // handshake pin -#define WIFILED 9 // led on wifi shield +#define DATAOUT 11 // MOSI +#define DATAIN 12 // MISO +#define SPICLOCK 13 // sck +#define SLAVESELECT 10 // ss +#define SLAVEREADY 7 // handshake pin +#define WIFILED 9 // led on wifi shield -#define DELAY_100NS do { asm volatile("nop"); }while(0); -#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); }while(++ii #include "utility/wl_definitions.h" #define CMD_FLAG 0 diff --git a/libraries/WiFi/arch/sam/WiFiClient.cpp b/libraries/WiFi/arch/sam/WiFiClient.cpp index 0ad4007ae..d669191ab 100644 --- a/libraries/WiFi/arch/sam/WiFiClient.cpp +++ b/libraries/WiFi/arch/sam/WiFiClient.cpp @@ -104,6 +104,8 @@ int WiFiClient::read() { int WiFiClient::read(uint8_t* buf, size_t size) { + // sizeof(size_t) is architecture dependent + // but we need a 16 bit data type here uint16_t _size = size; if (!ServerDrv::getDataBuf(_sock, buf, &_size)) return -1; diff --git a/libraries/WiFi/arch/sam/utility/socket.h b/libraries/WiFi/arch/sam/utility/socket.h index c96262b20..a9c73f210 100644 --- a/libraries/WiFi/arch/sam/utility/socket.h +++ b/libraries/WiFi/arch/sam/utility/socket.h @@ -15,73 +15,20 @@ #define SOCK_NOT_AVAIL 255 #include "utility/wl_definitions.h" -/** - * The 8-bit signed data type. - */ -typedef char int8; -/** - * The volatile 8-bit signed data type. - */ -typedef volatile char vint8; -/** - * The 8-bit unsigned data type. - */ -typedef unsigned char uint8; -/** - * The volatile 8-bit unsigned data type. - */ -typedef volatile unsigned char vuint8; -/** - * The 16-bit signed data type. - */ -typedef int int16; -/** - * The volatile 16-bit signed data type. - */ -typedef volatile int vint16; -/** - * The 16-bit unsigned data type. - */ -typedef unsigned int uint16; -/** - * The volatile 16-bit unsigned data type. - */ -typedef volatile unsigned int vuint16; -/** - * The 32-bit signed data type. - */ -typedef long int32; -/** - * The volatile 32-bit signed data type. - */ -typedef volatile long vint32; -/** - * The 32-bit unsigned data type. - */ -typedef unsigned long uint32; -/** - * The volatile 32-bit unsigned data type. - */ -typedef volatile unsigned long vuint32; +typedef uint16_t SOCKET; -/* bsd */ -typedef uint8 u_char; /**< 8-bit value */ -typedef uint16_t SOCKET; -//typedef uint16 u_short; /**< 16-bit value */ -typedef uint16 u_int; /**< 16-bit value */ -typedef uint32 u_long; /**< 32-bit value */ - -extern SOCKET socket(uint8 protocol); // Opens a socket(TCP or UDP or IP_RAW mode) +extern SOCKET socket(uint8_t protocol); // Opens a socket(TCP or UDP or IP_RAW mode) extern void close(SOCKET s); // Close socket -extern uint8 connect(SOCKET s, uint8 * addr, uint16 port); // Establish TCP connection (Active connection) +extern uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port); // Establish TCP connection (Active connection) extern void disconnect(SOCKET s); // disconnect the connection -extern uint8 listen(SOCKET s); // Establish TCP connection (Passive connection) -extern uint16 send(SOCKET s, const uint8 * buf, uint16 len); // Send data (TCP) -extern uint16 recv(SOCKET s, uint8 * buf, uint16 len); // Receive data (TCP) -extern uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port); // Send data (UDP/IP RAW) -extern uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port); // Receive data (UDP/IP RAW) +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 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) + +extern uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len); -extern uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len); #endif /* _SOCKET_H_ */ diff --git a/libraries/WiFi/arch/sam/utility/spi_drv.cpp b/libraries/WiFi/arch/sam/utility/spi_drv.cpp index 53c93fb87..c037a32e4 100644 --- a/libraries/WiFi/arch/sam/utility/spi_drv.cpp +++ b/libraries/WiFi/arch/sam/utility/spi_drv.cpp @@ -8,12 +8,12 @@ extern "C" { #include "utility/debug.h" } -#define DATAOUT 11 // MOSI -#define DATAIN 12 // MISO -#define SPICLOCK 13 // sck +#define DATAOUT 11 // MOSI +#define DATAIN 12 // MISO +#define SPICLOCK 13 // sck #define SLAVESELECT 10 // ss -#define SLAVEREADY 7 // handshake pin -#define WIFILED 9 // led on wifi shield +#define SLAVEREADY 7 // handshake pin +#define WIFILED 9 // led on wifi shield #define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < X*6); } #define DELAY_TRANSFER() DELAY_SPI(10) @@ -37,7 +37,7 @@ void SpiDrv::begin() } void SpiDrv::end() { - SPI.end(); + SPI.end(); } void SpiDrv::spiSlaveSelect() @@ -51,19 +51,10 @@ void SpiDrv::spiSlaveDeselect() digitalWrite(SLAVESELECT,HIGH); } -//void delaySpi() -//{ -// int i = 0; -// const int DELAY = 1000; -// for (;i #include "utility/socket.h" -SOCKET socket(uint8 protocol) {return 0;} // Opens a socket(TCP or UDP or IP_RAW mode) +SOCKET socket(uint8_t protocol) {return 0;} // Opens a socket(TCP or UDP or IP_RAW mode) void close(SOCKET s) {} // Close socket -uint8 connect(SOCKET s, uint8 * addr, uint16 port) {return 0;} // Establish TCP connection (Active connection) +uint8_t connect(SOCKET s, uint8_t * addr, uint16_t port) {return 0;} // Establish TCP connection (Active connection) void disconnect(SOCKET s) {} // disconnect the connection -uint8 listen(SOCKET s) { return 0;} // Establish TCP connection (Passive connection) -uint16 send(SOCKET s, const uint8 * buf, uint16 len) { return 0;} // Send data (TCP) -uint16 recv(SOCKET s, uint8 * buf, uint16 len) {return 0;} // Receive data (TCP) -uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port) {return 0;} // Send data (UDP/IP RAW) -uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port) {return 0;} // Receive data (UDP/IP RAW) +uint8_t listen(SOCKET s) { return 0;} // Establish TCP connection (Passive connection) +uint16_t send(SOCKET s, const uint8_t * buf, uint16_t len) { return 0;} // Send data (TCP) +uint16_t recv(SOCKET s, uint8_t * buf, uint16_t len) {return 0;} // Receive data (TCP) +uint16_t sendto(SOCKET s, const uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port) {return 0;} // Send data (UDP/IP RAW) +uint16_t recvfrom(SOCKET s, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port) {return 0;} // Receive data (UDP/IP RAW) -uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len) {return 0;} +uint16_t igmpsend(SOCKET s, const uint8_t * buf, uint16_t len) {return 0;}