reset w5500 for phy link down
authorkyz <kyz@kyz.pub>
Tue, 29 Mar 2022 09:15:04 +0000 (17:15 +0800)
committerkyz <kyz@kyz.pub>
Tue, 29 Mar 2022 09:15:04 +0000 (17:15 +0800)
Core/Src/user_net.c

index 66a248361803e2535b2dbd2b94a6438994839559..0ab62feed9b1be3495fd9cad0a39cb2f286b3c5b 100644 (file)
@@ -14,6 +14,7 @@
 
 #define DATA_BUF_SIZE 1024
 
+static uint32_t tcp_modbus_st = 0;
 
 static uint8_t tcp_rx_buf[DATA_BUF_SIZE];
 static uint16_t tcp_rx_sz = 0;
@@ -89,6 +90,7 @@ uint32_t  tcp_server_poll( void )
        uint16_t port = g_mbport;
        int32_t ret;
        uint16_t size = 0;
+       uint8_t phycfg_r =0;
 
        switch(getSn_SR(sn))
        {
@@ -106,6 +108,15 @@ uint32_t  tcp_server_poll( void )
                                                tcp_rx_sz = (uint16_t) ret;
                                                prvxMBTCPPortReceive_cb( tcp_rx_buf, tcp_rx_sz );
                        }
+                       else
+                       {
+                               phycfg_r =  getPHYCFGR();
+                               if( !(phycfg_r & PHYCFGR_LNK_ON) ){
+                                       //W5500 PHY: Link down
+                                       //网线断开, 复位modbus连接
+                                       tcp_modbus_st = 0; //reset modbus
+                               }
+                       }
                        break;
                case SOCK_CLOSE_WAIT :
                        if((ret = disconnect(sn)) != SOCK_OK) return ret;
@@ -127,7 +138,6 @@ int32_t tcp_modebus_handle( void )
         int ret;
        eMBErrorCode xStatus;  
 
-       static uint32_t tcp_modbus_st = 0;
        
                if( tcp_modbus_st == 0 ){