update 1.8
This commit is contained in:
@@ -19,7 +19,6 @@ 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"
|
||||
#include "ModuleConfig.h"
|
||||
|
||||
@@ -82,7 +81,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;
|
||||
@@ -107,7 +106,7 @@ void TIM2_Init( void )
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_UdpServerRecv(struct _SCOK_INF *socinf,u32 ipaddr,u16 port,u8 *buf,u32 len)
|
||||
void WCHNET_UdpServerRecv(struct _SOCK_INF *socinf,u32 ipaddr,u16 port,u8 *buf,u32 len)
|
||||
{
|
||||
u8 i;
|
||||
|
||||
@@ -130,7 +129,7 @@ void WCHNET_UdpServerRecv(struct _SCOK_INF *socinf,u32 ipaddr,u16 port,u8 *buf,u
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void WCHNET_UdpSRecv(struct _SCOK_INF *socinf,u32 ipaddr,u16 port,u8 *buf,u32 len)
|
||||
void WCHNET_UdpSRecv(struct _SOCK_INF *socinf,u32 ipaddr,u16 port,u8 *buf,u32 len)
|
||||
{
|
||||
u8 ip_addr[4],i;
|
||||
|
||||
@@ -163,41 +162,41 @@ void WCHNET_Create_Communication_Socket(void)
|
||||
TmpSocketInf.DesPort = ((u16)CFG->dest_port[0]+(u16)CFG->dest_port[1]*256);
|
||||
TmpSocketInf.SourPort = ((u16)CFG->src_port[0]+(u16)CFG->src_port[1]*256);
|
||||
switch(CFG->type){
|
||||
case NET_MODULE_TYPE_TCP_S:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
||||
sockFlag= NET_MODULE_TYPE_TCP_S;
|
||||
break;
|
||||
case NET_MODULE_TYPE_TCP_C:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
||||
sockFlag= NET_MODULE_TYPE_TCP_C;
|
||||
break;
|
||||
case NET_MODULE_TYPE_UDP_S:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
TmpSocketInf.AppCallBack = WCHNET_UdpSRecv;
|
||||
sockFlag= NET_MODULE_TYPE_UDP_S;
|
||||
break;
|
||||
case NET_MODULE_TYPE_UDP_C:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
sockFlag= NET_MODULE_TYPE_UDP_C;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case NET_MODULE_TYPE_TCP_S:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
||||
sockFlag= NET_MODULE_TYPE_TCP_S;
|
||||
break;
|
||||
case NET_MODULE_TYPE_TCP_C:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_TCP;
|
||||
sockFlag= NET_MODULE_TYPE_TCP_C;
|
||||
break;
|
||||
case NET_MODULE_TYPE_UDP_S:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
TmpSocketInf.AppCallBack = WCHNET_UdpSRecv;
|
||||
sockFlag= NET_MODULE_TYPE_UDP_S;
|
||||
break;
|
||||
case NET_MODULE_TYPE_UDP_C:
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
sockFlag= NET_MODULE_TYPE_UDP_C;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
TmpSocketInf.RecvStartPoint = (u32)SocketRecvBuf[1];
|
||||
TmpSocketInf.RecvBufLen = RECE_BUF_LEN ;
|
||||
i = WCHNET_SocketCreat(&SocketId,&TmpSocketInf);
|
||||
mStopIfError(i);
|
||||
switch(CFG->type){
|
||||
case NET_MODULE_TYPE_TCP_S:
|
||||
WCHNET_SocketListen(SocketId);
|
||||
printf("listening\n");
|
||||
break;
|
||||
case NET_MODULE_TYPE_TCP_C:
|
||||
WCHNET_SocketConnect(SocketId);
|
||||
printf("connecting\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case NET_MODULE_TYPE_TCP_S:
|
||||
WCHNET_SocketListen(SocketId);
|
||||
printf("listening\n");
|
||||
break;
|
||||
case NET_MODULE_TYPE_TCP_C:
|
||||
WCHNET_SocketConnect(SocketId);
|
||||
printf("connecting\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,18 +251,19 @@ void WCHNET_DataLoopback(u8 id)
|
||||
}
|
||||
#else
|
||||
u32 len, totallen;
|
||||
u8 *p = MyBuf;
|
||||
u8 *p = MyBuf, TransCnt = 255;
|
||||
|
||||
len = WCHNET_SocketRecvLen(id, NULL); //query length
|
||||
printf("Receive Len = %02x\n", len);
|
||||
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(totallen)continue; //If the data is not sent, continue to send
|
||||
if( !--TransCnt ) break; //Timeout exit
|
||||
if(totallen) continue; //If the data is not sent, continue to send
|
||||
break; //After sending, exit
|
||||
}
|
||||
#endif
|
||||
@@ -304,7 +304,6 @@ void WCHNET_HandleSockInt(u8 socketid,u8 initstat)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn WCHNET_HandleGlobalInt
|
||||
*
|
||||
@@ -374,11 +373,14 @@ int main(void)
|
||||
Delay_Init();
|
||||
USART_Printf_Init(115200); //USART initialize
|
||||
GPIOInit();
|
||||
printf("ETH_CFG\r\n");
|
||||
printf("SystemClk:%d\r\n",SystemCoreClock);
|
||||
printf("net version:%x\n",WCHNET_GetVer());
|
||||
if( WCHNET_LIB_VER != WCHNET_GetVer() ){
|
||||
printf("version error.\n");
|
||||
printf("ETH CFG 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()){
|
||||
printf("version error.\n");
|
||||
}
|
||||
/*After the button(PB6) is pressed, initialize WCHNET
|
||||
* and execute the default configuration*/
|
||||
@@ -406,7 +408,7 @@ int main(void)
|
||||
WCHNET_GetMacAddr(MACAddr); //get the chip MAC address
|
||||
printf("mac addr:");
|
||||
for(i = 0; i < 6; i++)
|
||||
printf("%x ",MACAddr[i]);
|
||||
printf("%x ", MACAddr[i]);
|
||||
printf("\n");
|
||||
TIM2_Init();
|
||||
memcpy(IPAddr,CFG->src_ip,sizeof(CFG->src_ip));
|
||||
|
||||
Reference in New Issue
Block a user