Skip to content

SPI Transactions #2223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move Ethernet socket level stuff to utility/socket.cpp
  • Loading branch information
PaulStoffregen committed Aug 1, 2014
commit 53924e9d58456ebf77cf3e7fd5529b29886b0bd1
6 changes: 3 additions & 3 deletions libraries/Ethernet/src/EthernetClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int EthernetClient::connect(IPAddress ip, uint16_t port) {
return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.readSnSR(i);
uint8_t s = socketStatus(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
_sock = i;
break;
Expand Down Expand Up @@ -88,7 +88,7 @@ size_t EthernetClient::write(const uint8_t *buf, size_t size) {

int EthernetClient::available() {
if (_sock != MAX_SOCK_NUM)
return W5100.getRXReceivedSize(_sock);
return recvAvailable(_sock);
return 0;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ uint8_t EthernetClient::connected() {

uint8_t EthernetClient::status() {
if (_sock == MAX_SOCK_NUM) return SnSR::CLOSED;
return W5100.readSnSR(_sock);
return socketStatus(_sock);
}

// the next function allows us to use the client returned by
Expand Down
4 changes: 2 additions & 2 deletions libraries/Ethernet/src/EthernetUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ uint8_t EthernetUDP::begin(uint16_t port) {
return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.readSnSR(i);
uint8_t s = socketStatus(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
Expand Down Expand Up @@ -120,7 +120,7 @@ int EthernetUDP::parsePacket()
// discard any remaining bytes in the last packet
flush();

if (W5100.getRXReceivedSize(_sock) > 0)
if (recvAvailable(_sock) > 0)
{
//HACK - hand-parse the UDP packet using TCP recv method
uint8_t tmpBuf[8];
Expand Down
12 changes: 12 additions & 0 deletions libraries/Ethernet/src/utility/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag)
}


uint8_t socketStatus(SOCKET s)
{
return W5100.readSnSR(s);
}


/**
* @brief This function close the socket and parameter is "s" which represent the socket number
*/
Expand Down Expand Up @@ -176,6 +182,12 @@ int16_t recv(SOCKET s, uint8_t *buf, int16_t len)
}


int16_t recvAvailable(SOCKET s)
{
return W5100.getRXReceivedSize(s);
}


/**
* @brief Returns the first byte in the receive queue (no checking)
*
Expand Down
2 changes: 2 additions & 0 deletions libraries/Ethernet/src/utility/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#include "utility/w5100.h"

extern uint8_t socket(SOCKET s, uint8_t protocol, uint16_t port, uint8_t flag); // Opens a socket(TCP or UDP or IP_RAW mode)
extern uint8_t socketStatus(SOCKET s);
extern void close(SOCKET s); // Close socket
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_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 int16_t recv(SOCKET s, uint8_t * buf, int16_t len); // Receive data (TCP)
extern int16_t recvAvailable(SOCKET s);
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)
Expand Down