⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 由smsc公司改进的lwip2.1.1基于嵌入式系统的TCP/ip协议栈
💻 C
字号:
/***************************************************************************
 *
 * Copyright (C) 2008  SMSC
 * 
 * All rights reserved
 *
 ***************************************************************************
 * File: main.c
 */

#include "core/sps.h"

#if SMSC_THREADING_ENABLED
#include "smsc_threading.h"
#endif

/* enabled applications here */
#define ICMP_ECHO_TESTER_ENABLED	(1)
#define UDP_RX_TESTER_ENABLED		(1)
#define UDP_TX_TESTER_ENABLED		(1)
#define TCP_RX_TESTER_ENABLED		(0)
#define TCP_TX_TESTER_ENABLED		(0)
#define SOCKET_TESTER_ENABLED		(0)

#include "api/sockets.h"
#include "api/utilities.h"

#if ICMP_ECHO_TESTER_ENABLED
#include "applications/icmp_echo_tester.h"
#endif

#if UDP_RX_TESTER_ENABLED || UDP_TX_TESTER_ENABLED
#include "applications/udp_tester.h"
#endif

#if TCP_RX_TESTER_ENABLED || TCP_TX_TESTER_ENABLED
#include "applications/tcp_tester.h"
#endif

#if SOCKET_TESTER_ENABLED
#include "applications/socket_tester/socktest.h"
#endif

#if ICMP_ECHO_TESTER_ENABLED
static ICMP_ECHO_TESTER gIcmpEchoData;
#endif

#if UDP_RX_TESTER_ENABLED
static UDP_RX_TESTER udpReceiver;
#endif
#if UDP_TX_TESTER_ENABLED
static UDP_TX_TESTER udpTransmitter;
#endif
#if TCP_TX_TESTER_ENABLED
static TCP_TX_TESTER tcpTransmitter;
#endif
#if TCP_RX_TESTER_ENABLED
static TCP_RX_TESTER tcpReceiver;
#endif

#if SOCKET_TESTER_ENABLED
static struct tester gSocketTesterData1;
static struct tester gSocketTesterData2;
#endif

int main()
{
	Sps_Initialize();

#if SOCKETS_ENABLED
	Sockets_Initialize();
#endif

#if (SMSC911X_INTERFACE_COUNT>0)
#if DHCP_ENABLED
	if(Sps_StartDhcp("SMSC_0")==0) {
		SMSC_WARNING(1,("Failed to start DHCP for SMSC_0"));
	}
#else
	/* set static address here */
	if(Sps_SetIpv4Addresses("SMSC_0",
		IPV4_ADDRESS_MAKE(192,168,0,201),
		IPV4_ADDRESS_MAKE(255,255,255,0),
		IPV4_ADDRESS_MAKE(192,168,0,1))==0) 
	{
		SMSC_WARNING(1,("Failed to set Ipv4 address on SMSC_0"));
	}
#endif
	if(Sps_EnabledInterface("SMSC_0")==0) {
		SMSC_WARNING(1,("Failed to Enable SMSC_0"));
	}
#endif /*(SMSC911X_INTERFACE_COUNT>0)*/

	/* Initialize applications here */
#if ICMP_ECHO_TESTER_ENABLED
	IcmpEchoTester_Initialize(&gIcmpEchoData,
		IPV4_ADDRESS_MAKE(127,0,0,1),
		1472,	/* Size of ping packet */
		200,	/* Period in milliSeconds */
		3);	/* timeOut in Seconds */
#endif
#if UDP_RX_TESTER_ENABLED
	{
		IP_ADDRESS ipAddress;
		IP_ADDRESS_SET_IPV4(&ipAddress,127,0,0,1);
		UdpTester_InitializeReceiver(
			&udpReceiver,
			&ipAddress,	/* local address */
			6000);		/* local port */
	}
#endif
#if UDP_TX_TESTER_ENABLED
	{
		IP_ADDRESS ipAddress;
		IP_ADDRESS_SET_IPV4(&ipAddress,127,0,0,1);
		UdpTester_InitializeTransmitter(
			&udpTransmitter,
			&ipAddress,	/* remote address */
			6000, 		/* remote port */
			1472);		/* payload size */
	}
#endif
#if TCP_RX_TESTER_ENABLED
	{
		IP_ADDRESS ipAddress;
		IP_ADDRESS_SET_IPV4(&ipAddress,127,0,0,1);
		TcpTester_InitializeReceiver(
			&tcpReceiver,
			&ipAddress,/* local address */
			6000);/* local port */
	}
#endif
#if TCP_TX_TESTER_ENABLED
	{
		IP_ADDRESS ipAddress;
		IP_ADDRESS_SET_IPV4(&ipAddress,127,0,0,1);
		TcpTester_InitializeTransmitter(
			&tcpTransmitter,
			&ipAddress,	/* remote address */
			6000, 		/* remote port */
			1);         /* continuous mode, 0==disable, 1==enable */
	}
#endif
#if SOCKET_TESTER_ENABLED
	#if 0
	socket_test_initiate(
		&gSocketTesterData1,
		0,				/* 1 for udp test, 0 for tcp */
		0,				/* 1 if sender(client), 0 for receiver(server) */
		"192.168.0.201",/* Destination address, used when sender (sflag=1) */ 
		6000,			/* Destination port, used when sender */
		6000,			/* Local port to bind, used when receiver (sflag=0) */
		10,				/* No. of message to send, used when sender, 0 for continuous transmit */ 
		0,				/* Length of the message to send, used when sender. if 0, default 64 bytes */
		1,				/* 1 to skip the data verification */
		10,				/* burst time,  time to pause in ms after each burst. 0 for no pause/burst */
		10				/* burst count, no. of messages to send in each burst. default 10. ignored if burst time 0*/
		);
	#endif
	socket_test_initiate(
		&gSocketTesterData2,
		0, 				/* 1 for udp test, 0 for tcp */
		1, 				/* 1 if sender(client), 0 for receiver(server) */
		"192.168.1.12",	/* Destination address, used when sender (sflag=1) */ 
		6000, 			/* Destination port, used when sender */
		4000,			/* Local port to bind, used when receiver (sflag=0) */
		0,				/* No. of message to send, used when sender, 0 for continuous transmit */ 
		1472,			/* Length of the message to send, used when sender. if 0, default 64 bytes */
		1,				/* 1 to skip the data verification */
		10,				/* burst time,  time to pause in ms after each burst. 0 for no pause/burst */
		10				/* burst count, no. of messages to send in each burst. default 10. ignored if burst time 0*/
		);
#endif

#if SMSC_THREADING_ENABLED
	/* need to set the current thread priority to NORMAL so the scheduler
	  can balance the TaskManager_Run with other threads. */
	smsc_thread_set_priority(smsc_thread_get_current(),SMSC_THREAD_PRIORITY_NORMAL);
#endif
	/* Run TaskManager which takes care of running all tasks */
	Sps_Run();

	/* should never get here, 
		unless someone called TaskManager_StopRunning */
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -