update 1.8
This commit is contained in:
@@ -17,21 +17,20 @@ please refer to the "CH32V20x Evaluation Board Manual" under the CH32V20xEVT\EVT
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "debug.h"
|
||||
#include "eth_driver.h"
|
||||
|
||||
u8 MACAddr[6]; //MAC address
|
||||
u8 IPAddr[4] = { 192, 168, 1, 10 }; //IP address
|
||||
u8 GWIPAddr[4] = { 192, 168, 1, 1 }; //Gateway IP address
|
||||
u8 IPMask[4] = { 255, 255, 255, 0 }; //subnet mask
|
||||
u8 DESIP[4] = { 192, 168, 1, 100 }; //destination IP address
|
||||
u16 desport = 1000; //destination port
|
||||
u16 srcport = 1000; //source port
|
||||
#define UDP_RECE_BUF_LEN 1472
|
||||
u8 MACAddr[6]; //MAC address
|
||||
u8 IPAddr[4] = { 192, 168, 1, 10 }; //IP address
|
||||
u8 GWIPAddr[4] = { 192, 168, 1, 1 }; //Gateway IP address
|
||||
u8 IPMask[4] = { 255, 255, 255, 0 }; //subnet mask
|
||||
u8 DESIP[4] = { 192, 168, 1, 100 }; //destination IP address
|
||||
u16 desport = 1000; //destination port
|
||||
u16 srcport = 1000; //source port
|
||||
|
||||
u8 SocketId;
|
||||
u8 SocketRecvBuf[WCHNET_MAX_SOCKET_NUM][RECE_BUF_LEN]; //socket receive buffer
|
||||
u8 MyBuf[RECE_BUF_LEN];
|
||||
|
||||
u8 SocketRecvBuf[WCHNET_MAX_SOCKET_NUM][UDP_RECE_BUF_LEN]; //socket receive buffer
|
||||
u8 MyBuf[UDP_RECE_BUF_LEN];
|
||||
/*********************************************************************
|
||||
* @fn mStopIfError
|
||||
*
|
||||
@@ -61,7 +60,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;
|
||||
@@ -91,9 +90,9 @@ void WCHNET_CreateUdpSocket(void)
|
||||
TmpSocketInf.SourPort = srcport++;
|
||||
TmpSocketInf.ProtoType = PROTO_TYPE_UDP;
|
||||
TmpSocketInf.RecvStartPoint = (u32) SocketRecvBuf[SocketId];
|
||||
TmpSocketInf.RecvBufLen = RECE_BUF_LEN;
|
||||
TmpSocketInf.RecvBufLen = UDP_RECE_BUF_LEN;
|
||||
i = WCHNET_SocketCreat(&SocketId, &TmpSocketInf);
|
||||
printf("WCHNET_SocketCreat %d srcport %d\r\n", SocketId, srcport);
|
||||
printf("WCHNET_SocketCreat %d\r\n", SocketId);
|
||||
mStopIfError(i);
|
||||
}
|
||||
|
||||
@@ -119,16 +118,16 @@ void WCHNET_DataLoopback(u8 id)
|
||||
else {
|
||||
len = SocketInf[id].RecvRemLen;
|
||||
}
|
||||
i = WCHNET_SocketSend(id, (u8 *) SocketInf[id].RecvReadPoint, &len); //send data
|
||||
i = WCHNET_SocketSend(id, (u8 *) SocketInf[id].RecvReadPoint, &len); //send data
|
||||
if (i == WCHNET_ERR_SUCCESS) {
|
||||
WCHNET_SocketRecv(id, NULL, &len); //Clear sent data
|
||||
WCHNET_SocketRecv(id, NULL, &len); //Clear sent data
|
||||
}
|
||||
#else
|
||||
u32 len, totallen;
|
||||
u8 *p = MyBuf;
|
||||
|
||||
len = WCHNET_SocketRecvLen(id, NULL); //query length
|
||||
printf("Receive Len = %02x\n", len);
|
||||
printf("Receive Len = %d\n", len);
|
||||
totallen = len;
|
||||
WCHNET_SocketRecv(id, MyBuf, &len); //Read the data of the receive buffer into MyBuf
|
||||
while(1){
|
||||
@@ -222,15 +221,18 @@ int main(void)
|
||||
|
||||
Delay_Init();
|
||||
USART_Printf_Init(115200); //USART initialize
|
||||
printf("UdpClient Test\r\n");
|
||||
printf("SystemClk:%d\r\n", SystemCoreClock);
|
||||
printf("UDPClient 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
|
||||
printf("mac addr:");
|
||||
for (i = 0; i < 6; i++)
|
||||
for(i = 0; i < 6; i++)
|
||||
printf("%x ", MACAddr[i]);
|
||||
printf("\n");
|
||||
TIM2_Init();
|
||||
@@ -239,7 +241,7 @@ int main(void)
|
||||
if (i == WCHNET_ERR_SUCCESS)
|
||||
printf("WCHNET_LibInit Success\r\n");
|
||||
for (i = 0; i < WCHNET_MAX_SOCKET_NUM; i++)
|
||||
WCHNET_CreateUdpSocket(); //Create UDP Socket
|
||||
WCHNET_CreateUdpSocket(); //Create UDP Socket
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user