This is a non working version of my ethernet with sd card, i do not know why
Dependencies: SDFileSystem mbed
Fork of eth_v13 by
TCPSocket.cpp
- Committer:
- hggerdd
- Date:
- 2014-03-18
- Revision:
- 2:8f5bacfef390
- Child:
- 3:79dc3337d9da
File content as of revision 2:8f5bacfef390:
#include "TCPSocket.h" #include "ipaddr.h" #include "w5100.h" #include "mbed.h" extern Serial pc; TCPSocket::TCPSocket(int newSocket) { _socket = newSocket; } void TCPSocket::bind(int port) { _port = port; W5100.writeSnMR(_socket, SnMR::TCP); // set TCP mode W5100.writeSnPORT(_socket, _port); } void TCPSocket::listen() { W5100.execCmdSn(_socket, Sock_OPEN); // set OPEN command W5100.execCmdSn(_socket, Sock_LISTEN); // listen } int TCPSocket::send(const char* buf, int len) { if (len > 0) { W5100.send_data_processing(_socket, (uint8_t*)buf, len); W5100.execCmdSn(_socket, Sock_SEND); } return len; } int TCPSocket::recv(char* buf, int len) { int size = W5100.getRXReceivedSize(_socket); if (size > len) { size = len; } if (size > 0) { W5100.recv_data_processing(_socket, (uint8_t*)buf, size); W5100.execCmdSn(_socket, Sock_RECV); } return size; } void TCPSocket::poll() { uint8_t Sn_SR = W5100.readSnSR(_socket); //pc.printf("SnSR = %x\n", Sn_SR); switch(Sn_SR) { case SnSR::ESTABLISHED: m_pCb(); break; } } void TCPSocket::close() { if (_socket != (-1)) { W5100.execCmdSn(_socket, Sock_DISCON); W5100.execCmdSn(_socket, Sock_CLOSE); } } void TCPSocket::setOnEvent(void (*pMethod)(void)) { m_pCb = pMethod; }