Browse Source

drivers, wiznet5k: Add socket_reset; fix orderly shutdown in recv.

pull/1000/head
Damien George 10 years ago
parent
commit
d8f239263d
  1. 22
      drivers/wiznet5k/ethernet/socket.c
  2. 3
      drivers/wiznet5k/ethernet/socket.h
  3. 5
      drivers/wiznet5k/ethernet/wizchip_conf.c

22
drivers/wiznet5k/ethernet/socket.c

@ -49,6 +49,9 @@
//! THE POSSIBILITY OF SUCH DAMAGE. //! THE POSSIBILITY OF SUCH DAMAGE.
// //
//***************************************************************************** //*****************************************************************************
#include <string.h>
#include "socket.h" #include "socket.h"
extern void HAL_Delay(uint32_t); extern void HAL_Delay(uint32_t);
@ -85,7 +88,19 @@ static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
if(len == 0) return SOCKERR_DATALEN; \ if(len == 0) return SOCKERR_DATALEN; \
}while(0); \ }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) int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
{ {
@ -336,8 +351,13 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
if(recvsize != 0) break; if(recvsize != 0) break;
else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn)) 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); WIZCHIP_EXPORT(close)(sn);
return SOCKERR_SOCKSTATUS; return 0;
} }
} }
else else

3
drivers/wiznet5k/ethernet/socket.h

@ -133,6 +133,9 @@
#define PACK_REMAINED 0x01 ///< In Non-TCP packet, It indicates to remain a packet to be received. #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. #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 * @ingroup WIZnet_socket_APIs
* @brief Open a socket. * @brief Open a socket.

5
drivers/wiznet5k/ethernet/wizchip_conf.c

@ -49,6 +49,8 @@
// //
#include "wizchip_conf.h" #include "wizchip_conf.h"
#include "socket.h"
/** /**
* @brief Default function to enable interrupt. * @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, * @note This function help not to access wrong address. If you do not describe this function or register any functions,
@ -328,6 +330,9 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++) for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
setSn_RXBUF_SIZE(i, rxsize[i]); setSn_RXBUF_SIZE(i, rxsize[i]);
} }
WIZCHIP_EXPORT(socket_reset)();
return 0; return 0;
} }

Loading…
Cancel
Save