DSP

DSP6678 NDK网络配置(UDP)要点

2019-07-13 10:33发布

最近找工作告一段落,又有了一些零碎时间,想起来博客里之前还挖了6678千兆网配置的坑,但是网络配置程序我只是简单的使用了NDK demo 提供的UDP功能,所以就没办法详细写网络配置了,就写几个要点吧,大家如果在实际配置时遇到什么问题,可以在下面留言咱们互相交流解决。
1、如果要使用NDK,那你所建立的ccs工程必须是跑sys/bios的工程。
2、如果想看6678的网络demo,那么其demo路径为:C: imcsdk_2_01_02_06examples dkhelloWorld
3、DSP的本地IP主要在helloworld.c中的以下代码段设置 char *HostName = "tidsp"; char *LocalIPAddr = "192.168.2.100"; char *LocalIPMask = "255.255.255.0"; // Not used when using DHCP char *GatewayIP = "192.168.2.101"; // Not used when using DHCP char *DomainName = "demo.net"; // Not used when using DHCP char *DNSServer = "0.0.0.0"; // Used when set to anything but zero 4、设置DHCP还是静态IP,主要体现在helloworld.c中的以下代码段: // If the IP address is specified, manually configure IP and Gateway #if defined(_SCBP6618X_) || defined(_EVMTCI6614_) || defined(DEVICE_K2H) || defined(DEVICE_K2K) /* SCBP6618x, EVMTCI6614, EVMK2H, EVMK2K always uses DHCP */ if (0) #else if (!platform_get_switch_state(1)) #endif { CI_IPNET NA; CI_ROUTE RT; IPN IPTmp; // Setup manual IP address bzero( &NA, sizeof(NA) ); NA.IPAddr = inet_addr(LocalIPAddr); NA.IPMask = inet_addr(LocalIPMask); strcpy( NA.Domain, DomainName ); NA.NetType = 0; // Add the address to interface 1 CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 ); // Add the default gateway. Since it is the default, the // destination address and mask are both zero (we go ahead // and show the assignment for clarity). bzero( &RT, sizeof(RT) ); RT.IPDestAddr = 0; RT.IPDestMask = 0; RT.IPGateAddr = inet_addr(GatewayIP); // Add the route CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0 ); // Manually add the DNS server when specified IPTmp = inet_addr(DNSServer); if( IPTmp ) CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER, 0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 ); } // Else we specify DHCP else { CI_SERVICE_DHCPC dhcpc; // Specify DHCP Service on IF-1 bzero( &dhcpc, sizeof(dhcpc) ); dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID; dhcpc.cisargs.IfIdx = 1; dhcpc.cisargs.pCbSrv = &ServiceReport; CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0, sizeof(dhcpc), (UINT8 *)&dhcpc, 0 ); } 其中switch_state是拨码开关,有的开发板上直接是固定的,官方板上该开关可以拨动。 5、可以在以下代码段创建socket进程,用来传输数据: static void NetworkOpen() { // Create our local server // 下面这个函数的第三个参数是接收进程的端口设定 // hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello, // OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 ); //// hSend = TaskCreate ( dtask_udp_hello, "UDP_Send", OS_TASKPRIHIGH, //// OS_TASKSTKNORM, 0, 0, 0 ); hSend = TaskCreate ( task_sendto_PC, "UDP_Send", OS_TASKPRINORM, OS_TASKSTKNORM, 0, 0, 0 ); // 当然也可以创建接收进程啦 } 注意:必须在发送/接收进程执行任务完成之后执行fdCloseSession(TaskSelf());否则影响堆栈分配
6、至于task_sendto_PC怎么写,那就是socket编程的事情啦!