diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c index cd810a63b..ece95f803 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/connect_ether.c @@ -24,6 +24,7 @@ please refer to the "CH32V30x Evaluation Board Manual" under the CH32V307EVT\EVT #include "eth_driver.h" #include "string.h" #include "xs_base.h" +#include "ping.h" extern uint32_t SystemCoreClock; #define KEEPALIVE_ENABLE 1 // Enable keep alive function @@ -32,6 +33,7 @@ uint8_t MACAddr[6]; // MAC address uint8_t IPAddr[4] = { 192, 168, 1, 10 }; // IP address uint8_t GWIPAddr[4] = { 192, 168, 1, 1 }; // Gateway IP address uint8_t IPMask[4] = { 255, 255, 255, 0 }; // subnet mask +uint8_t DESIP[4] = { 192, 168, 1, 100 }; // destination IP address uint8_t MyBuf[RECE_BUF_LEN]; uint8_t socket[WCHNET_MAX_SOCKET_NUM]; // Save the currently connected socket @@ -144,13 +146,25 @@ void WCHNET_DataLoopback(uint8_t id) * * @return 0 or TIME_OUT */ -int WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat) +int WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat, int commandType) { uint8_t i; - + u32 len; if (intstat & SINT_STAT_RECV) // receive data { - WCHNET_DataLoopback(socketid); // Data loopback + switch (commandType) { + case 0: + WCHNET_DataLoopback(socketid); // Data loopback + break; + case 1: + len = WCHNET_SocketRecvLen(socketid,NULL); //get socket buffer data length + WCHNET_SocketRecv(socketid,MyBuf,&len); //Read the data of the receive buffer into MyBuf + WCHNET_ICMPRecvData( len,MyBuf ); + } + // WCHNET_DataLoopback(socketid); // Data loopback + // len = WCHNET_SocketRecvLen(socketid,NULL); //get socket buffer data length + // WCHNET_SocketRecv(socketid,MyBuf,&len); //Read the data of the receive buffer into MyBuf + // WCHNET_ICMPRecvData( len,MyBuf ); } if (intstat & SINT_STAT_CONNECT) // connect successfully { @@ -175,6 +189,8 @@ int WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat) break; } } + extern uint8_t connectState; + connectState = 0; KPrintf("TCP Disconnect\r\n"); } if (intstat & SINT_STAT_TIM_OUT) // timeout disconnect @@ -198,7 +214,7 @@ int WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat) * * @return 0 or SockInt */ -int WCHNET_HandleGlobalInt(void) +int WCHNET_HandleGlobalInt(int commandType) { uint8_t intstat; uint16_t i; @@ -216,14 +232,16 @@ int WCHNET_HandleGlobalInt(void) if (intstat & GINT_STAT_PHY_CHANGE) // PHY status change { i = WCHNET_GetPHYStatus(); - if (i & PHY_Linked_Status) + if (i & PHY_Linked_Status) { + ICMPSuc = ICMP_SOKE_CON; KPrintf("PHY Link Success\r\n"); + } } if (intstat & GINT_STAT_SOCKET) { // socket related interrupt for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) { socketint = WCHNET_GetSocketInt(i); if (socketint) { - return WCHNET_HandleSockInt(i, socketint); + return WCHNET_HandleSockInt(i, socketint, commandType); } } } diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c index f0d3aa08e..8779477dd 100755 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/eth_driver.c @@ -11,6 +11,7 @@ *******************************************************************************/ #include "string.h" #include "eth_driver.h" +#include "ch32v20x.h" __attribute__((__aligned__(4))) ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB]; /* MAC receive descriptor, 4-byte aligned*/ __attribute__((__aligned__(4))) ETH_DMADESCTypeDef DMATxDscrTab[ETH_TXBUFNB]; /* MAC send descriptor, 4-byte aligned */ diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/ping.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/ping.c index 12f051675..5c1aadc53 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/ping.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/ping.c @@ -391,7 +391,7 @@ int ping(int argc, char *argv[]) { /*Query the Ethernet global interrupt, * if there is an interrupt, call the global interrupt handler*/ if (WCHNET_QueryGlobalInt()) { - WCHNET_HandleGlobalInt(); + WCHNET_HandleGlobalInt(1); } WCHNET_PINGCmd(); if (ICMPSuc == ICMP_KEEP_NO) { diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/wch_tcp_test.c b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/wch_tcp_test.c index 590f81742..d3430df73 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/wch_tcp_test.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/ethernet/test/wch_tcp_test.c @@ -4,10 +4,12 @@ #include "wchnet.h" #include "xs_base.h" + uint16_t desport = 1000; // destination port uint16_t srcport = 1000; // source port extern uint8_t DESIP[4]; uint8_t SocketId; +uint8_t connectState = 1; /********************************************************************* * @fn TCP client @@ -18,8 +20,8 @@ uint8_t SocketId; int Tcp_Client(void) { uint8_t i; - for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) - WCHNET_CreateTcpSocket(DESIP, srcport, desport, &SocketId); // Create TCP Socket + // for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) + WCHNET_CreateTcpSocket(DESIP, srcport, desport, &SocketId); // Create TCP Socket while (1) { /*Ethernet library main task function, @@ -28,16 +30,21 @@ int Tcp_Client(void) /*Query the Ethernet global interrupt, * if there is an interrupt, call the global interrupt handler*/ if (WCHNET_QueryGlobalInt()) { - if (WCHNET_HandleGlobalInt() == TIME_OUT) { + if (WCHNET_HandleGlobalInt(0) == TIME_OUT) { WCHNET_CreateTcpSocket(DESIP, srcport, desport, &SocketId); } } + /* only one connection */ + if (connectState == 0) { + break; + } } } int test_tcp_client(int argc, char* argv[]) { KPrintf("TCPClient Test\r\n"); + connectState = 1; Tcp_Client(); return 0; } diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/connect_ether.h b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/connect_ether.h index 074822c5d..4ccc41432 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/connect_ether.h +++ b/Ubiquitous/XiZi_IIoT/board/ch32v208rbt6/third_party_driver/include/connect_ether.h @@ -31,7 +31,7 @@ uint8_t InitHwEth(); void WCHNET_CreateTcpSocket(uint8_t* DESIP, uint16_t srcport, uint16_t desport, uint8_t* SocketId); void WCHNET_CreateTcpSocketListen(uint16_t srcport, uint8_t* SocketId); -int WCHNET_HandleGlobalInt(void); +int WCHNET_HandleGlobalInt(int commandType); #define TIME_OUT -1