Skip to content

Commit

Permalink
drivers, wiznet5k: Add socket_reset; fix orderly shutdown in recv.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed Dec 4, 2014
1 parent 32ef3a3 commit d8f2392
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion drivers/wiznet5k/ethernet/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
//! THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************

#include <string.h>

#include "socket.h"

extern void HAL_Delay(uint32_t);
Expand Down Expand Up @@ -85,7 +88,19 @@ static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
if(len == 0) return SOCKERR_DATALEN; \
}while(0); \

void WIZCHIP_EXPORT(socket_reset)(void) {
sock_any_port = SOCK_ANY_PORT_NUM;
sock_io_mode = 0;
sock_is_sending = 0;
/*
memset(sock_remained_size, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t));
memset(sock_pack_info, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint8_t));
*/

#if _WIZCHIP_ == 5200
memset(sock_next_rd, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t));
#endif
}

int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
{
Expand Down Expand Up @@ -336,8 +351,13 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
if(recvsize != 0) break;
else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn))
{
// dpgeorge: Getting here seems to be an orderly shutdown of the
// socket, and trying to get POSIX behaviour we return 0 because:
// "If no messages are available to be received and the peer has per‐
// formed an orderly shutdown, recv() shall return 0".
// TODO this return value clashes with SOCK_BUSY in non-blocking mode.
WIZCHIP_EXPORT(close)(sn);
return SOCKERR_SOCKSTATUS;
return 0;
}
}
else
Expand Down
3 changes: 3 additions & 0 deletions drivers/wiznet5k/ethernet/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
#define PACK_REMAINED 0x01 ///< In Non-TCP packet, It indicates to remain a packet to be received.
#define PACK_COMPLETED 0x00 ///< In Non-TCP packet, It indicates to complete to receive a packet.

// resets all global state associated with the socket interface
void WIZCHIP_EXPORT(socket_reset)(void);

/**
* @ingroup WIZnet_socket_APIs
* @brief Open a socket.
Expand Down
5 changes: 5 additions & 0 deletions drivers/wiznet5k/ethernet/wizchip_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
//

#include "wizchip_conf.h"
#include "socket.h"

/**
* @brief Default function to enable interrupt.
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
Expand Down Expand Up @@ -328,6 +330,9 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
setSn_RXBUF_SIZE(i, rxsize[i]);
}

WIZCHIP_EXPORT(socket_reset)();

return 0;
}

Expand Down

0 comments on commit d8f2392

Please sign in to comment.