您好,欢迎访问三七文档
当前位置:首页 > 金融/证券 > 金融资料 > CycloneTCP协议栈移植与使用简介
ArdaTechnologyCopyright©2007-2014ArdaTechnology1ArdaTechP.F.FU2014-12-19Ver0.1#elifdefined(USE_XXXXXX)#includeos_port_xxxxxx.hCopyright©2007-2014ArdaTechnology2Copyright©2007-2014ArdaTechnology3Copyright©2007-2014ArdaTechnology4Copyright©2007-2014ArdaTechnology5Copyright©2007-2014ArdaTechnology6NicTypetype;//控制器类型。0:以太网接口,1:PPP接口,2:6LowPan接口NicInitinit;//控制器初始化函数指针NicTicktick;//控制器周期性事务处理函数指针NicEnableIrqenableIrq;//打开控制器中断函数指针NicDisableIrqdisableIrq;//关闭控制器中断函数指针NicEventHandlereventHandler;//控制器中断响应函数指针,这个是下半段的中断处理部分。NicSetMacFiltersetMacFilter;//配置多播MAC地址过滤函数指针NicSendPacketsendPacket;//发送包函数指针NicWritePhyRegwritePhyReg;//写PHY寄存器函数指针NicReadPhyRegreadPhyReg;//读PHY寄存器函数指针bool_tautoPadding;//是否支持自动填充bool_tautoCrcGen;//是否支持自动生成CRC校验码bool_tautoCrcCheck;//是否支持自动检查CRC错误NicSendControlFramesendControlFrame;//发送控制帧函数指针NicReceiveControlFramereceiveControlFrame;//接收控制帧函数指针NicPurgeTxBufferpurgeTxBuffer;//清除发送缓冲函数指针NicPurgeRxBufferpurgeRxBuffer;//清除接受缓存函数指针xxxxEthInitGpio(...)//用于在init中初始化GPIO。xxxxEthInitDmaDesc(...)//用于在init中初始化DMA任务描述符列表。XXXX_Handler(...)//用于MAC中断的上半段处理。xxxxEthReceivePacket(...)//用于在eventHandler中收包,把数据从dma的缓冲复制到外部缓冲。xxxxEthCalcCrc(...)//计算CRC值,这个函数基本上是固定的。xxxxEthDumpPhyReg(...)//用于调试的打印PHY寄存器列表值。Copyright©2007-2014ArdaTechnology7PhyInitinit;//物理层初始化函数指针PhyTicktick;//周期性事务处理函数指针PhyEnableIrqenableIrq;//打开物理层中断PhyDisableIrqdisableIrq;//关闭物理层中断PhyEventHandlereventHandler;//物理层中断处理函数Copyright©2007-2014ArdaTechnology8#includecore/tcp_ip_stack.h//必须要有的协议栈头文件#includedrivers/tm4c129x_eth.h//MAC驱动头文件,如果用了片外PHY,还要包含PHY的驱动头文件#includedhcp/dhcp_client.h//使用DHCP的话需要此头文件#includeipv6/slaac.h//使用IPV6本地短地址的话需要此头文件#includecommon/debug.h//如果你用了CycloneTCP的调试输出函数,则需要包含此头文件//Applicationconfiguration#defineAPP_MAC_ADDR00-11-22-33-44-55//定义MAC地址#defineAPP_USE_DHCPENABLED//DHCP开关,使用DHCP#defineAPP_IPV4_HOST_ADDR192.168.1.20//静态地址时的IPV4IP#defineAPP_IPV4_SUBNET_MASK255.255.255.0//静态地址时的IPV4子网掩码#defineAPP_IPV4_DEFAULT_GATEWAY192.168.1.1//静态地址时的IPV4网关IP#defineAPP_IPV4_PRIMARY_DNS8.8.8.8//静态地址时的IPV4主DNSIP#defineAPP_IPV4_SECONDARY_DNS8.8.4.4//静态地址时的IPV4从DNSIPCopyright©2007-2014ArdaTechnology9#defineAPP_USE_SLAACDISABLED//SLAAC开关,禁用SLAAC#defineAPP_IPV6_LINK_LOCAL_ADDRfe80::407#defineAPP_IPV6_PREFIX2001:db8::#defineAPP_IPV6_PREFIX_LENGTH64#defineAPP_IPV6_GLOBAL_ADDR2001:db8::407#defineAPP_IPV6_ROUTERfe80::1#defineAPP_IPV6_PRIMARY_DNS2001:4860:4860::8888#defineAPP_IPV6_SECONDARY_DNS2001:4860:4860::8844//Constantdefinitions#defineAPP_SERVER_NAME应用层访问的地址#defineAPP_SERVER_PORT80//应用层访问的端口#defineAPP_REQUEST_URI/test.php//应用层访问的远端文件路径DhcpClientSettingsdhcpClientSettings;//DHCP客户端配置DhcpClientCtxdhcpClientContext;//DHCP客户端上下文,运行时变量SlaacSettingsslaacSettings;//短地址配置SlaacContextslaacContext;//短地址上下文,运行时变量error_terror;NetInterface*interface;//网络接口结构指针MacAddrmacAddr;//MAC地址变量#if(APP_USE_DHCP==DISABLED)Ipv4Addripv4Addr;//IPV4地址变量#endif#if(APP_USE_SLAAC==DISABLED)Ipv6Addripv6Addr;//IPV6地址变量#endif//Start-upmessageTRACE_INFO(\r\n);TRACE_INFO(***********************************\r\n);TRACE_INFO(***CycloneTCPHTTPClientDemo***\r\n);Copyright©2007-2014ArdaTechnology10TRACE_INFO(***********************************\r\n);TRACE_INFO(Copyright:2010-2014OryxEmbedded\r\n);TRACE_INFO(Compiled:%s%s\r\n,__DATE__,__TIME__);TRACE_INFO(Target:EK-TM4C1294XL\r\n);TRACE_INFO(\r\n);printf(HTTPClientDemo);//TCP/IPstackinitialization初始化协议栈error=tcpIpStackInit();//Anyerrortoreport?if(error){//DebugmessageTRACE_ERROR(FailedtoinitializeTCP/IPstack!\r\n);}//ConfigurethefirstEthernetinterface配置首个网络接口interface=&netInterface[0];//Setinterfacename设定网络接口名称tcpIpStackSetInterfaceName(interface,eth0);//Sethostname设定主机名称tcpIpStackSetHostname(interface,HTTPClientDemo);//Selecttherelevantnetworkadapter设定网络适配器nic驱动tcpIpStackSetDriver(interface,&tm4c129xEthDriver);//SethostMACaddress设定主机MAC地址macStringToAddr(APP_MAC_ADDR,&macAddr);tcpIpStackSetMacAddr(interface,&macAddr);//Initializenetworkinterface初始化网络接口error=tcpIpStackConfigInterface(interface);//Anyerrortoreport?if(error){//DebugmessageTRACE_ERROR(Failedtoconfigureinterface%s!\r\n,interface-name);}#if(IPV4_SUPPORT==ENABLED)//当使能IPV4时#if(APP_USE_DHCP==ENABLED)//当使用DHCP时//Getdefaultsettings载入默认的DHCP参数dhcpClientGetDefaultSettings(&dhcpClientSettings);//SetthenetworkinterfacetobeconfiguredbyDHCP设定DHCP线程操作的网口dhcpClientSettings.interface=interface;//Disablerapidcommitoption禁用快速提交Copyright©2007-2014ArdaTechnology11dhcpClientSettings.rapidCommit=FALSE;//DHCPclientinitialization初始化DHCP客户端error=dhcpClientInit(&dhcpClientContext,&dhcpClientSettings);//FailedtoinitializeDHCPclient?if(error){//DebugmessageTRACE_ERROR(FailedtoinitializeDHCPclient!\r\n);}//StartDHCPclient启动DHCP客户端error=dhcpClientStart(&dhcpClientContext);//FailedtostartDHCPclient?if(error){//DebugmessageTRACE_ERROR(FailedtostartDHCPclient!\r\n);}#else//如果不使用DHCP时//SetIPv4hostaddress转换并设定主机IPipv4StringToAddr(APP_IPV4_HOST_ADDR,&ipv4Addr);ipv4SetHostAddr(interface,ipv4Addr);//Setsubnetmask转换并设定网络掩码ipv4StringToAddr(APP_IPV4_SUBNET_MASK,&ipv4Addr);ipv4SetSubnetMask(inte
本文标题:CycloneTCP协议栈移植与使用简介
链接地址:https://www.777doc.com/doc-4219099 .html