diff --git a/Ethernet/socket.c b/Ethernet/socket.c index 412a65d..3620150 100644 --- a/Ethernet/socket.c +++ b/Ethernet/socket.c @@ -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,}; @@ -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; @@ -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]; @@ -429,6 +436,12 @@ int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len) } if((sock_io_mode & (1<= start_time+sock_rcvtimeo[sn]) + { + return SOCKERR_TIMEOUT; + } }; #if _WIZCHIP_ == 5300 } @@ -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; } diff --git a/Ethernet/socket.h b/Ethernet/socket.h index 72469a7..aa8c98c 100644 --- a/Ethernet/socket.h +++ b/Ethernet/socket.h @@ -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) ) diff --git a/Ethernet/wizchip_conf.c b/Ethernet/wizchip_conf.c index 194d296..6102f40 100644 --- a/Ethernet/wizchip_conf.c +++ b/Ethernet/wizchip_conf.c @@ -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 diff --git a/Ethernet/wizchip_conf.h b/Ethernet/wizchip_conf.h index a5d65f7..ce04612 100644 --- a/Ethernet/wizchip_conf.h +++ b/Ethernet/wizchip_conf.h @@ -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. */ @@ -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. @@ -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);