update 1.8

This commit is contained in:
qiyongshuang
2023-09-06 10:08:11 +08:00
parent b79c6ac80d
commit 64be955461
760 changed files with 42517 additions and 30957 deletions
+28 -26
View File
@@ -16,9 +16,7 @@ to the server and receives data and then sends it back.
For details on the selection of engineering chips,
please refer to the "CH32V20x Evaluation Board Manual" under the CH32V20xEVT\EVT\PUB folder.
*/
#include "string.h"
#include "debug.h"
#include "eth_driver.h"
#define KEEPALIVE_ENABLE 1 //Enable keep alive function
@@ -35,7 +33,6 @@ u8 SocketId;
u8 socket[WCHNET_MAX_SOCKET_NUM]; //Save the currently connected socket
u8 SocketRecvBuf[WCHNET_MAX_SOCKET_NUM][RECE_BUF_LEN]; //socket receive buffer
u8 MyBuf[RECE_BUF_LEN];
/*********************************************************************
* @fn mStopIfError
*
@@ -65,7 +62,7 @@ void TIM2_Init(void)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseStructure.TIM_Period = SystemCoreClock / 1000000 - 1;
TIM_TimeBaseStructure.TIM_Period = SystemCoreClock / 1000000;
TIM_TimeBaseStructure.TIM_Prescaler = WCHNETTIMERPERIOD * 1000 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
@@ -130,16 +127,18 @@ void WCHNET_DataLoopback(u8 id)
}
#else
u32 len, totallen;
u8 *p = MyBuf;
u8 *p = MyBuf, TransCnt = 255;
len = WCHNET_SocketRecvLen(id, NULL); //query length
WCHNET_SocketRecv(id, MyBuf, &len); //Read the data of the receive buffer into MyBuf
printf("Receive Len = %d\r\n", len);
totallen = len;
WCHNET_SocketRecv(id, MyBuf, &len); //Read the data of the receive buffer into MyBuf
while(1){
len = totallen;
WCHNET_SocketSend(id, p, &len); //Send the data
totallen -= len; //Subtract the sent length from the total length
p += len; //offset buffer pointer
if( !--TransCnt ) break; //Timeout exit
if(totallen) continue; //If the data is not sent, continue to send
break; //After sending, exit
}
@@ -160,18 +159,18 @@ void WCHNET_HandleSockInt(u8 socketid, u8 intstat)
{
u8 i;
if (intstat & SINT_STAT_RECV) //receive data
if (intstat & SINT_STAT_RECV) //receive data
{
WCHNET_DataLoopback(socketid); //Data loopback
WCHNET_DataLoopback(socketid); //Data loopback
}
if (intstat & SINT_STAT_CONNECT) //connect successfully
if (intstat & SINT_STAT_CONNECT) //connect successfully
{
#if KEEPALIVE_ENABLE
WCHNET_SocketSetKeepLive(socketid, ENABLE);
#endif
WCHNET_ModifyRecvBuf(socketid, (u32) SocketRecvBuf[socketid], RECE_BUF_LEN);
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) {
if (socket[i] == 0xff) { //save connected socket id
if (socket[i] == 0xff) { //save connected socket id
socket[i] = socketid;
break;
}
@@ -189,9 +188,9 @@ void WCHNET_HandleSockInt(u8 socketid, u8 intstat)
}
printf("TCP Disconnect\r\n");
}
if (intstat & SINT_STAT_TIM_OUT) //timeout disconnect
if (intstat & SINT_STAT_TIM_OUT) //timeout disconnect
{
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) { //delete disconnected socket id
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) { //delete disconnected socket id
if (socket[i] == socketid) {
socket[i] = 0xff;
break;
@@ -215,22 +214,22 @@ void WCHNET_HandleGlobalInt(void)
u16 i;
u8 socketint;
intstat = WCHNET_GetGlobalInt(); //get global interrupt flag
if (intstat & GINT_STAT_UNREACH) //Unreachable interrupt
intstat = WCHNET_GetGlobalInt(); //get global interrupt flag
if (intstat & GINT_STAT_UNREACH) //Unreachable interrupt
{
printf("GINT_STAT_UNREACH\r\n");
}
if (intstat & GINT_STAT_IP_CONFLI) //IP conflict
if (intstat & GINT_STAT_IP_CONFLI) //IP conflict
{
printf("GINT_STAT_IP_CONFLI\r\n");
}
if (intstat & GINT_STAT_PHY_CHANGE) //PHY status change
if (intstat & GINT_STAT_PHY_CHANGE) //PHY status change
{
i = WCHNET_GetPHYStatus();
if (i & PHY_Linked_Status)
printf("PHY Link Success\r\n");
}
if (intstat & GINT_STAT_SOCKET) { //socket related interrupt
if (intstat & GINT_STAT_SOCKET) { //socket related interrupt
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++) {
socketint = WCHNET_GetSocketInt(i);
if (socketint)
@@ -251,24 +250,27 @@ int main(void)
u8 i;
Delay_Init();
USART_Printf_Init(115200); //USART initialize
printf("TcpClient Test\r\n");
printf("SystemClk:%d\r\n", SystemCoreClock);
USART_Printf_Init(115200); //USART initialize
printf("TCPClient Test\r\n");
if((SystemCoreClock == 60000000) || (SystemCoreClock == 120000000))
printf("SystemClk:%d\r\n", SystemCoreClock);
else
printf("Error: Please choose 60MHz and 120MHz clock when using Ethernet!\r\n");
printf("net version:%x\n", WCHNET_GetVer());
if ( WCHNET_LIB_VER != WCHNET_GetVer()) {
if (WCHNET_LIB_VER != WCHNET_GetVer()) {
printf("version error.\n");
}
WCHNET_GetMacAddr(MACAddr); //get the chip MAC address
WCHNET_GetMacAddr(MACAddr); //get the chip MAC address
printf("mac addr:");
for ( i = 0; i < 6; i++)
for(i = 0; i < 6; i++)
printf("%x ", MACAddr[i]);
printf("\n");
TIM2_Init();
i = ETH_LibInit(IPAddr, GWIPAddr, IPMask, MACAddr); //Ethernet library initialize
i = ETH_LibInit(IPAddr, GWIPAddr, IPMask, MACAddr); //Ethernet library initialize
mStopIfError(i);
if (i == WCHNET_ERR_SUCCESS)
printf("WCHNET_LibInit Success\r\n");
#if KEEPALIVE_ENABLE //Configure keep alive parameters
#if KEEPALIVE_ENABLE //Configure keep alive parameters
{
struct _KEEP_CFG cfg;
@@ -280,7 +282,7 @@ int main(void)
#endif
memset(socket, 0xff, WCHNET_MAX_SOCKET_NUM);
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++)
WCHNET_CreateTcpSocket(); //Create TCP Socket
WCHNET_CreateTcpSocket(); //Create TCP Socket
while(1)
{