咨询大家一个问题:用
STM32或AT32 控制W5500 作为SERVER PC端作出client, 现从PC端发送命令给W5500。 当整个系统只有单个W5500时 传输较为稳定。 当系统中有多个W5500时,PC发给各个W5500的指令 不能够被准时可靠的接收。 用抓包工具可以看到 retransmission ,DUP ACK等字眼。 即使本次命令在重传后被各个W5500接收, 在后续的系统工作中,总会有一个或多个W5500 与PC 掉线。附上W5500 收发部分代码。
- int Start_serve_net(void)
- {
- int ret;
- uint16_t size = 0, txsize = 0;
- switch(getSn_SR(sn))
- {
- case SOCK_INIT :
- printf("%d:Listen, TCP server loopback, port [%d]rn", sn, port);
- if( (ret = listen(sn)) != SOCK_OK) return ret;
- osThreadYield();
- break;
-
- case SOCK_LISTEN:
- osThreadYield();
- break;
-
- case SOCK_ESTABLISHED :
- flag_cle = 0;
- if(getSn_IR(sn) & Sn_IR_CON) setSn_IR(sn,Sn_IR_CON);
-
- if(!flag_req)
- {
- printf("%d:SOCK_ESTABLISHEDrn", sn);
- memset(pethbuf.buf,0,sizeof(pethbuf.buf));
- anchorRequestConfig(app.eui64,0);
- send(sn,(uint8_t*)&pethbuf.buf, sizeof(request_configCle_t)+6);
- flag_req = 1;
- }
- if(flag_port3000 == 1)
- {
- at32_led_toggle(LED2);
- flag_port3000 = 0;
- }
- if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't occur.
- {
- printf("snrxsize = %dn", size);
- osMutexWait(app.ctrlServer[0].MutexId, 3);
- if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
- ret = recv(sn, Eth_Rx_Buffer, size);
-
- if(Eth_Rx_Buffer[0] == RTLS_START_REQ && size == RTLS_START_REQ_LEN)
- Set_start_stop_RTLSreq();
- else if(Eth_Rx_Buffer[0] == RTLS_CMD_SET_CFG_CCP && size == RTLS_CMD_SET_CFG_CCP_LEN)
- Set_ccp_cmd();
- osMutexRelease(app.ctrlServer[0].MutexId);
- cnt_int = 0;
- }
-
- osThreadYield();
- break;
-
- case SOCK_CLOSE_WAIT :
- if((ret = disconnect(sn)) != SOCK_OK) return ret;
- printf("%d:Socket Closedrn", sn);
-
- osThreadYield();
- break;
- case SOCK_CLOSED:
-
- /* below is complete sequence to cancel any working mode */
- vdsr_force_txrx_off(); //switch off DWxxxx
- app_apptimer_stop(); //cancel application slow timer
- ccp_timer_stop(); //cancel fast CCP timer
- vdsr_initreset_app(NULL, NULL, NULL, NULL); //cancel all user call-backs
- app.RtlsInfo.sendClkSync = 0;
- if((ret = socket(sn, Sn_MR_TCP, 3000, 0x00)) != sn) return ret;
- flag_req = 0; txen = false;
- printf("%d: SOCK_CLOSED open new Socketrn",sn);
- osThreadYield();
- break;
-
- default:
- osThreadYield();
-
- break;
- }
- return ret;
- }