Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions Ethernet/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ static uint16_t sock_is_sending = 0;

static uint16_t sock_remained_size[_WIZCHIP_SOCK_NUM_] = {0,0,};

//used to store the recv timeout values for each socket in ms, default is 0 which means infinite
static uint32_t sock_rcvtimeo[_WIZCHIP_SOCK_NUM_] = {0,};

//M20150601 : For extern decleation
//static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
Expand Down Expand Up @@ -258,6 +261,9 @@ int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
{
CHECK_SOCKNUM();
CHECK_SOCKMODE(Sn_MR_TCP);

uint8_t _SR_=getSn_SR(sn);

CHECK_SOCKINIT();
//M20140501 : For avoiding fatal error on memory align mismatched
//if( *((uint32_t*)addr) == 0xFFFFFFFF || *((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
Expand Down Expand Up @@ -386,6 +392,7 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len)
{
uint8_t tmp = 0;
uint16_t recvsize = 0;
uint32_t start_time=WIZCHIP._get_tick();
//A20150601 : For integarating with W5300
#if _WIZCHIP_ == 5300
uint8_t head[2];
Expand Down Expand Up @@ -429,6 +436,12 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len)
}
if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY;
if(recvsize != 0) break;

//implement timeout
if(sock_rcvtimeo[sn]!=0 && WIZCHIP._get_tick() >= start_time+sock_rcvtimeo[sn])
{
return SOCKERR_TIMEOUT;
}
};
#if _WIZCHIP_ == 5300
}
Expand Down Expand Up @@ -866,6 +879,10 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
break;
#endif
#endif
case SO_RCVTIMEO:
sock_rcvtimeo[sn] = *((uint32_t*) arg);
break;

default:
return SOCKERR_ARG;
}
Expand Down
1 change: 1 addition & 0 deletions Ethernet/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ typedef enum
SO_MSS, ///< Set MSS. @ref Sn_MSSR ( @ref setSn_MSSR(), @ref getSn_MSSR() )
SO_DESTIP, ///< Set the destination IP address. @ref Sn_DIPR ( @ref setSn_DIPR(), @ref getSn_DIPR() )
SO_DESTPORT, ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
SO_RCVTIMEO, ///< Set the timeout for recv() function, by default it is infinite or wait forever
#if _WIZCHIP_ != 5100
SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100
#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
Expand Down
5 changes: 5 additions & 0 deletions Ethernet/wizchip_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), vo
}
}

void reg_wizchip_tick_cbfunc(uint32_t (*_get_tick) (void))
{
WIZCHIP._get_tick = _get_tick;
}

int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg)
{
#if _WIZCHIP_ == W5100S || _WIZCHIP_ == W5200 || _WIZCHIP_ == W5500
Expand Down
20 changes: 18 additions & 2 deletions Ethernet/wizchip_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ typedef struct __WIZCHIP
{
void (*_select) (void); ///< @ref \_WIZCHIP_ selected
void (*_deselect)(void); ///< @ref \_WIZCHIP_ deselected
}CS;
}CS;

/**
* A function to get current one millisecond tick
*/
uint32_t (*_get_tick) (void);

/**
* The set of interface IO callback func.
*/
Expand Down Expand Up @@ -504,6 +510,16 @@ void reg_wizchip_spi_cbfunc(uint8_t (*spi_rb)(void), void (*spi_wb)(uint8_t wb))
*/
void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), void (*spi_wb)(uint8_t* pBuf, uint16_t len));

/**
* @brief Registers call back function to get one millisecond tick counter value.
* @details Resets WIZCHIP & internal PHY, Configures PHY mode, Monitor PHY(Link,Speed,Half/Full/Auto),
* controls interrupt & mask and so on.
* @param _get_tick : callback function to get one millisecond tick counter value
* @param arg : arg type is dependent on cwtype.
*
*/
void reg_wizchip_tick_cbfunc(uint32_t (*_get_tick) (void));

/**
* @ingroup extra_functions
* @brief Controls to the WIZCHIP.
Expand All @@ -512,7 +528,7 @@ void reg_wizchip_spiburst_cbfunc(void (*spi_rb)(uint8_t* pBuf, uint16_t len), vo
* @param cwtype : Decides to the control type
* @param arg : arg type is dependent on cwtype.
* @return 0 : Success \n
* -1 : Fail because of invalid \ref ctlwizchip_type or unsupported \ref ctlwizchip_type in WIZCHIP
* -1 : Fail because of invalid \ref ctlwizchip_type or unsupported \ref ctlwizchip_type in WIZCHIP
*/
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg);

Expand Down