DSP:6678开发板NDK网口通信完整实现(附源码)
如果出現(xiàn)圖片打不開,或是顯示異常,請點擊下方鏈接閱讀原文!!!
DSP:6678開發(fā)板NDK網(wǎng)口通信完整實現(xiàn)(附源碼) - 子木的文章 - 知乎 https://zhuanlan.zhihu.com/p/85110735
?
//*************************************************************************************************
//寫在前面:
1.已經(jīng)有很多前輩做過很優(yōu)秀的記錄,本篇盡量講得詳細一點,能夠讓新手直接上手。
2.在整個調(diào)試過程中,會遇到各種各樣的問題,如果遇到問題請看第四部分,大部分問題應(yīng)該能解決掉,不能解決的就評論區(qū)留言。
3.我的CCS安裝路徑是“C:\Ti\***”,后文如果出現(xiàn),請對應(yīng)你自己的安裝路徑
?
1.開發(fā)環(huán)境:CCS 5.4 、卓嵐TCP&UDP調(diào)試工具
2.開發(fā)平臺: Ti TMDSEVM6678LE(TMDSEVM6678LE是開發(fā)板,程序在其他6678板卡上也運行過)
3.需要工程源文件,ccs,調(diào)試助手的評論區(qū)留言!
?
//*************************************************************************************************//
目錄
一、原理
二、調(diào)試流程
三、程序執(zhí)行流程與部分程序解讀
四、注意事項與遇到過的問題及解決方法
五、程序源碼
?
?
一、原理
1.通過UDP實現(xiàn)DSP與PC的通信,硬件上只需要用網(wǎng)線連接電腦與6678板卡即可,在程序上只是對TI已有的范例進行一些修改就能實現(xiàn)簡單的通信。
2.板卡上電后,CCS通過JTAG連接調(diào)試板卡,則會首先從GEL的StartUp( )函數(shù)開始執(zhí)行初始化,JTAG連接后執(zhí)行OnTargetConnect( )函數(shù),OnTargetConnect( )會調(diào)用Global_Default_Setup_Silent()函數(shù)中的ddr3_setup_auto_lvl_1333(0);和 configSGMIISerdes();函數(shù)完成DDR和SGMII的初始化。
3.如果要使用NDK,建立的ccs工程必須是跑sys/bios的工程。所以需要安裝bios,我安裝的是bios_setupwin32_6_33_06_50(正常情況下,安裝ccs時已經(jīng)安裝了,檢查下安裝目錄)
4. 在任何SOCKET應(yīng)用程序建立之前,TCP/IP堆棧必須被正確的配置然后初始化。通常可以動態(tài)創(chuàng)建或者在DSP/BIOS中靜態(tài)創(chuàng)建一個堆棧初始化任務(wù),不管應(yīng)用程序當中建立了多少SOCKET,在整個系統(tǒng)中只能有一個堆棧初始化任務(wù),并且該任務(wù)會成為整個網(wǎng)絡(luò)任務(wù)的唯一調(diào)度者,因此該任務(wù)在應(yīng)用程序結(jié)束前不會返回。
堆棧初始化過程:(1)使用NC_SystemOpen()。該函數(shù)為所有網(wǎng)絡(luò)應(yīng)用程序建立堆棧和內(nèi)存環(huán)境;(2)使用CfgNew()。該函數(shù)會創(chuàng)建一個配置句柄,利用該句柄使用CfgAddEntry()函數(shù)可以添加DHCP、DNS、HTTP等服務(wù)和配置SOCKET緩沖區(qū)大小與ARP超時參數(shù);(3)使用NC_NetStart()。該函數(shù)根據(jù)前面的配置參數(shù)啟動網(wǎng)絡(luò),并創(chuàng)建三個回調(diào)函數(shù),分別是網(wǎng)絡(luò)啟動時只運行一次的函數(shù)、網(wǎng)絡(luò)被關(guān)閉時只運行一次的函數(shù)、當IP地址改變時運行的函數(shù)。通常會在啟動函數(shù)里面創(chuàng)建自己的應(yīng)用程序線程,在關(guān)閉函數(shù)里面刪除創(chuàng)建的應(yīng)用程序線程。
?
?
二、調(diào)試過程
1.首先需要安裝MCSDK和NDK,一般來說安裝的CCS版本不是太低,都已經(jīng)自動安裝這些組件了。(我記得ndk_2_21_01_38這個版本是有問題的,盡量不用這個,安裝了也沒關(guān)系,可以在設(shè)置里面修改成其他版本。)
我ccs安裝目錄下文件狀態(tài)
2.導入工程
在C:\Ti\mcsdk_2_01_02_06\examples\ndk\helloWorld路徑下是ndk例程的官方例程,
導入工程可以分為在它源文件上進行調(diào)試,也可以復制到其他地方調(diào)試,擔心破壞掉源文件,所以這里采用把文件復制到其他路徑下調(diào)試。
(1)開始導入工程
(2)工程文件選擇到helloWorld或者evmc6678l都可以,因為后面還得改。第3步是把文件復制到自己的工作路徑下,我的是workspace
(3)可以看到此時文件標識有感嘆號,這是由于路徑不對,如果編譯,會報錯:
? ?Description Resource Path Location Type gmake: *** No rule to make target `C:/Ti/workspace/udpHello.c', needed by `udpHello.obj'. helloworld_evmc6678l Unknown C/C++ Problem
(4)在工程上右鍵,點擊properties
(5)在箭頭處雙擊,進去過file找到helloWorld.c等4個c文件的位置,也就是:C:\Ti\mcsdk_2_01_02_06\examples\ndk\helloWorld里面。就完成了修改路徑
(6)修改完之后是下圖的狀態(tài)
(7)此時右鍵工程選擇Rebuild Project,編譯就通過了。
?
3.配置仿真文件
由于需要硬件仿真,需要選擇仿真器類型,創(chuàng)建ccxml和gel文件,如果以前寫過相關(guān)的ccxml和gel,只要仿真器和板卡沒變,可以直接復制過來使用,就可跳過這一步,文章最后會提供我的ccxml和gel。
(1)右鍵工程,選擇新建Target Configuration File
(2)命名為evmc6678l.ccxml
(3)選擇仿真器型號和芯片
(4)配置gel文件
【Gel文件的執(zhí)行時間一般在DSP connect target之后,在download代碼之前。因為gel文件通常會進行一些初始化的寄存器的設(shè)置,比如memory map,PLL和DDR初始化等。所以在download之前必須初始化這些。
gel文件的腳本都可以找到的。CCS5的版本可以在這個目錄下找到大部分EVM的gel腳本
ccsv5\ccs_base\emulation\boards
gel腳本類似于C語言函數(shù),就是運行一些函數(shù)。比如DDR初始化函數(shù)。如果DDR沒有初始化,是無法將代碼download到DDR中去的。執(zhí)行g(shù)el腳本有兩種,一種是用戶自己執(zhí)行,另一種是CCS5自動將gel腳本關(guān)聯(lián)到相關(guān)的操作中,比如connect target就自動關(guān)聯(lián)了初始化PLL,初始化DDR的gel函數(shù)。
可以找個gel腳本看看,這樣更有助于理解。】
雙擊剛剛新建的evmc6678l.ccxml文件,再點擊圖中位置,
(5)gel文件在CCS安裝路徑下的\ccsv5\ccs_base\emulation\boards里可以找到對應(yīng)芯片的gel文件,最后點擊save。6678是多核芯片,這里只用到了core0,所以給0核配置就可以了。也可以直接在路徑中復制過來。
4.文件處理好的狀態(tài)
5.IP設(shè)置
(1)由于是采取的靜態(tài)IP,需要把板卡上的撥碼開關(guān)設(shè)置成下圖這樣,(這個撥碼開關(guān)決定選擇dhcp還是靜態(tài)IP)
(2)需要將程序中IP部分進行相應(yīng)修改
(3)為了穩(wěn)定,上位機使用的是一個網(wǎng)上的助手軟件。也可以用QT或是VS編寫,后面的文章會說到。下圖是助手界面,可以看到相關(guān)信息,目的IP(DSP的ip)是169.254.198.113。所以需要在DSP程序中進行修改。
(4)將原來helloWorld.c里面的ip改為助手顯示的IP就行
原IP
修改后的IP段程序:
? ?/****助手IP***/ char *HostName = "tidsp"; char *LocalIPAddr = "169.254.198.113"; char *LocalIPMask = "255.255.0.0"; // Not used when using DHCP char *GatewayIP = "169.254.1.1"; // 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
(5)因為使用的是靜態(tài)IP,不需要DHCP,在helloWorld.c里面再修改下面的一段程序
修改后的程序(注釋后加一個if(1)就行了):
? ?// 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 if(1) { printf("IP address is specified.\n"); CI_IPNET NA; CI_ROUTE RT; IPN IPTmp;
6.硬件調(diào)試
(1)rebuild project之后連接好線。板卡需要電源線,仿真器,網(wǎng)線。
(2)點擊view里面的Target configurations
(3)在彈出的界面右鍵ccxml文件,launch selected configuration
(4)選擇0核,再點擊連接
連接之后的打印信息:
? ?C66xx_0: GEL Output: Setup_Memory_Map... C66xx_0: GEL Output: Setup_Memory_Map... Done. C66xx_0: GEL Output: Connecting Target... C66xx_0: GEL Output: DSP core #0 C66xx_0: GEL Output: C6678L GEL file Ver is 2.005 C66xx_0: GEL Output: Global Default Setup... C66xx_0: GEL Output: Setup Cache... C66xx_0: GEL Output: L1P = 32K C66xx_0: GEL Output: L1D = 32K C66xx_0: GEL Output: L2 = ALL SRAM C66xx_0: GEL Output: Setup Cache... Done. C66xx_0: GEL Output: Main PLL (PLL1) Setup ... C66xx_0: GEL Output: PLL in Bypass ... C66xx_0: GEL Output: PLL1 Setup for DSP @ 1000.0 MHz. C66xx_0: GEL Output: SYSCLK2 = 333.3333 MHz, SYSCLK5 = 200.0 MHz. C66xx_0: GEL Output: SYSCLK8 = 15.625 MHz. C66xx_0: GEL Output: PLL1 Setup... Done. C66xx_0: GEL Output: Power on all PSC modules and DSP domains... C66xx_0: GEL Output: Security Accelerator disabled! C66xx_0: GEL Output: Power on all PSC modules and DSP domains... Done. C66xx_0: GEL Output: PA PLL (PLL3) Setup ... C66xx_0: GEL Output: PA PLL Setup... Done. C66xx_0: GEL Output: DDR3 PLL (PLL2) Setup ... C66xx_0: GEL Output: DDR3 PLL Setup... Done. C66xx_0: GEL Output: DDR begin (1333 auto) C66xx_0: GEL Output: XMC Setup ... Done C66xx_0: GEL Output: DDR3 initialization is complete. C66xx_0: GEL Output: DDR done C66xx_0: GEL Output: DDR3 memory test... Started C66xx_0: GEL Output: DDR3 memory test... Passed C66xx_0: GEL Output: PLL and DDR Initialization completed(0) ... C66xx_0: GEL Output: configSGMIISerdes Setup... Begin C66xx_0: GEL Output: SGMII SERDES has been configured. C66xx_0: GEL Output: Enabling EDC ... C66xx_0: GEL Output: L1P error detection logic is enabled. C66xx_0: GEL Output: L2 error detection/correction logic is enabled. C66xx_0: GEL Output: MSMC error detection/correction logic is enabled. C66xx_0: GEL Output: Enabling EDC ...Done C66xx_0: GEL Output: Configuring CPSW ... C66xx_0: GEL Output: Configuring CPSW ...Done C66xx_0: GEL Output: Global Default Setup... Done.
(5)load .out文件
加載成功后的打印信息:
? ?C66xx_0: GEL Output: Invalidate All Cache... C66xx_0: GEL Output: Invalidate All Cache... Done. C66xx_0: GEL Output: GEL Reset... C66xx_0: GEL Output: GEL Reset... Done. C66xx_0: GEL Output: Disable all EDMA3 interrupts and events.
(6)運行DSP
運行的打印信息:
? ?[C66xx_0] QMSS successfully initialized CPPI successfully initialized PA successfully initialized TCP/IP Stack 'Hello World!' Application TCP/IP Stack 'Hello World!' Application PASS successfully initialized Ethernet subsystem successfully initialized Ethernet eventId : 48 and vectId (Interrupt) : 7 Registration of the EMAC Successful, waiting for link up .. Network Added: If-1:169.254.198.113
(7)打開助手軟件
dsp的程序?qū)崿F(xiàn)的功能是上位機向dsp發(fā)送消息,dsp收到后再回傳給上位機。下圖是打開助手后的狀態(tài)
(8)測試結(jié)果
下圖是由上位機發(fā)送一串數(shù)字,并顯示接收到的消息的狀態(tài)
?
三、程序執(zhí)行流程與部分程序解讀
1.首先執(zhí)行EVM_init()函數(shù),也就是在main()函數(shù)之前執(zhí)行,具體設(shè)置在一個*.cfg文件中
? ?void EVM_init()
2.在main函數(shù)中執(zhí)行BIOS_start(),并創(chuàng)建進程StackTest()
? ?int main() { /* Start the BIOS 6 Scheduler */ BIOS_start (); }
3.在進程StackTest中執(zhí)行了QMSS、CPPI、PA等的初始化,完成了基本網(wǎng)絡(luò)配置
? ?int StackTest()
4.初始化platform
5.完成相應(yīng)配置后啟動NetworkOpen服務(wù)后,關(guān)聯(lián)了dtask_udp_hello任務(wù),等待UDP連接,并執(zhí)行相關(guān)操作
? ?static void NetworkOpen() { // Create our local server hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello, OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 ); }
6.程序開始執(zhí)行udpHello.c
?
四、注意事項與遇到過的問題及解決方法
?
1.路徑不要包含非ASCII字符
2.dsp每次燒寫程序都需要斷電重連
3.程序如果出問題了,可以在程序中用printf("**** ");打印信息。但是printf開銷很大,占用資源,完整的程序中應(yīng)該少用。
4.如果遇到關(guān)于platform而出現(xiàn)的編譯問題,參考這個鏈接:https://blog.csdn.net/u013368345/article/details/87905638
5. 正常來說,PC是無法識別DSP的,因為沒有交互,但是能夠正常通信。所以在電腦上ping的話,會顯示ping不通。
6.導入工程出錯,選擇狀態(tài)欄的project方式或者在project explore界面右鍵導入
?
?
五、程序源碼
1.helloWorld.c
? ?/* * helloWorld_bios6.c * * TCP/IP Stack 'Hello World!' Example ported to use BIOS6 OS. * * Copyright (C) 2007, 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ //-------------------------------------------------------------------------- // IP Stack 'Hello World!' Example // // This is a skeleton application, intended to provide application // programmers with a basic Stack setup, to which they can start // adding their code. // // To test it as is, use with helloWorld.exe from \winapps directory // #include <stdio.h> #include <ti/ndk/inc/netmain.h> /* BIOS6 include */ #include <ti/sysbios/BIOS.h> /* Platform utilities include */ #include "ti/platform/platform.h" #include "ti/platform/resource_mgr.h" /* Platform Information - we will read it form the Platform Library */ platform_info gPlatformInfo; //--------------------------------------------------------------------------- // Title String // char *VerStr = "\nTCP/IP Stack 'Hello World!' Application\n\n"; // Our NETCTRL callback functions static void NetworkOpen(); static void NetworkClose(); static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd ); // Fun reporting function static void ServiceReport( uint Item, uint Status, uint Report, HANDLE hCfgEntry ); // External references extern int dtask_udp_hello(); //--------------------------------------------------------------------------- // Configuration // char *HostName = "tidsp"; char *LocalIPAddr = "169.254.198.113"; char *LocalIPMask = "255.255.0.0"; // Not used when using DHCP char *GatewayIP = "169.254.1.1"; // 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 // Simulator EMAC Switch does not handle ALE_LEARN mode, so please configure the // MAC address of the PC where you want to launch the webpages and initiate PING to NDK */ Uint8 clientMACAddress [6] = {0x5C, 0x26, 0x0A, 0x69, 0x44, 0x0B}; /* MAC address for my PC */ /************************************************************************* * @b EVM_init() * * @n * * Initializes the platform hardware. This routine is configured to start in * the evm.cfg configuration file. It is the first routine that BIOS * calls and is executed before Main is called. If you are debugging within * CCS the default option in your target configuration file may be to execute * all code up until Main as the image loads. To debug this you should disable * that option. * * @param[in] None * * @retval * None ************************************************************************/ void EVM_init() { platform_init_flags sFlags; platform_init_config sConfig; /* Status of the call to initialize the platform */ int32_t pform_status; /* * You can choose what to initialize on the platform by setting the following * flags. Things like the DDR, PLL, etc should have been set by the boot loader. */ memset( (void *) &sFlags, 0, sizeof(platform_init_flags)); memset( (void *) &sConfig, 0, sizeof(platform_init_config)); sFlags.pll = 0; /* PLLs for clocking */ sFlags.ddr = 0; /* External memory */ sFlags.tcsl = 1; /* Time stamp counter */ #ifdef _SCBP6618X_ sFlags.phy = 0; /* Ethernet */ #else sFlags.phy = 1; /* Ethernet */ #endif sFlags.ecc = 0; /* Memory ECC */ sConfig.pllm = 0; /* Use libraries default clock divisor */ pform_status = platform_init(&sFlags, &sConfig); /* If we initialized the platform okay */ if (pform_status != Platform_EOK) { /* Initialization of the platform failed... die */ while (1) { (void) platform_led(1, PLATFORM_LED_ON, PLATFORM_USER_LED_CLASS); (void) platform_delay(50000); (void) platform_led(1, PLATFORM_LED_OFF, PLATFORM_USER_LED_CLASS); (void) platform_delay(50000); } } } //--------------------------------------------------------------------- // Main Entry Point //--------------------------------------------------------------------- int main() { /* Start the BIOS 6 Scheduler */ BIOS_start (); } // // Main Thread // int StackTest() { int rc; int i; HANDLE hCfg; QMSS_CFG_T qmss_cfg; CPPI_CFG_T cppi_cfg; /* Get information about the platform so we can use it in various places */ memset( (void *) &gPlatformInfo, 0, sizeof(platform_info)); (void) platform_get_info(&gPlatformInfo); (void) platform_uart_init(); (void) platform_uart_set_baudrate(115200); (void) platform_write_configure(PLATFORM_WRITE_ALL); /* Clear the state of the User LEDs to OFF */ for (i=0; i < gPlatformInfo.led[PLATFORM_USER_LED_CLASS].count; i++) { (void) platform_led(i, PLATFORM_LED_OFF, PLATFORM_USER_LED_CLASS); } /* Initialize the components required to run this application: * (1) QMSS * (2) CPPI * (3) Packet Accelerator */ /* Initialize QMSS */ if (platform_get_coreid() == 0) { qmss_cfg.master_core = 1; } else { qmss_cfg.master_core = 0; } qmss_cfg.max_num_desc = MAX_NUM_DESC; qmss_cfg.desc_size = MAX_DESC_SIZE; qmss_cfg.mem_region = Qmss_MemRegion_MEMORY_REGION0; if (res_mgr_init_qmss (&qmss_cfg) != 0) { platform_write ("Failed to initialize the QMSS subsystem \n"); goto main_exit; } else { platform_write ("QMSS successfully initialized \n"); } /* Initialize CPPI */ if (platform_get_coreid() == 0) { cppi_cfg.master_core = 1; } else { cppi_cfg.master_core = 0; } cppi_cfg.dma_num = Cppi_CpDma_PASS_CPDMA; cppi_cfg.num_tx_queues = NUM_PA_TX_QUEUES; cppi_cfg.num_rx_channels = NUM_PA_RX_CHANNELS; if (res_mgr_init_cppi (&cppi_cfg) != 0) { platform_write ("Failed to initialize CPPI subsystem \n"); goto main_exit; } else { platform_write ("CPPI successfully initialized \n"); } if (res_mgr_init_pass()!= 0) { platform_write ("Failed to initialize the Packet Accelerator \n"); goto main_exit; } else { platform_write ("PA successfully initialized \n"); } // // THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION before // using the stack!! // rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT ); if( rc ) { platform_write("NC_SystemOpen Failed (%d)\n",rc); for(;;); } // Print out our banner platform_write(VerStr); // // Create and build the system configuration from scratch. // // Create a new configuration hCfg = CfgNew(); if( !hCfg ) { platform_write("Unable to create configuration\n"); goto main_exit; } // // THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!! // rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT ); if( rc ) { printf("NC_SystemOpen Failed (%d)\n",rc); for(;;); } // Print out our banner printf(VerStr); // // Create and build the system configuration from scratch. // // Create a new configuration hCfg = CfgNew(); if( !hCfg ) { printf("Unable to create configuration\n"); goto main_exit; } // We better validate the length of the supplied names if( strlen( DomainName ) >= CFG_DOMAIN_MAX || strlen( HostName ) >= CFG_HOSTNAME_MAX ) { printf("Names too long\n"); goto main_exit; } // Add our global hostname to hCfg (to be claimed in all connected domains) CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0, strlen(HostName), (UINT8 *)HostName, 0 ); // 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 if(1) { 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 ); } // // Configure IPStack/OS Options // // We don't want to see debug messages less than WARNINGS rc = DBG_WARN; CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL, CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 ); // // This code sets up the TCP and UDP buffer sizes // (Note 8192 is actually the default. This code is here to // illustrate how the buffer and limit sizes are configured.) // // UDP Receive limit rc = 8192; CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT, CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 ); // // Boot the system using this configuration // // We keep booting until the function returns 0. This allows // us to have a "reboot" command. // do { rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr ); } while( rc > 0 ); // Delete Configuration CfgFree( hCfg ); // Close the OS main_exit: NC_SystemClose(); return(0); } // // System Task Code [ Server Daemon Servers ] // static HANDLE hHello=0; // // NetworkOpen // // This function is called after the configuration has booted // static void NetworkOpen() { // Create our local server hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello, OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 ); } // // NetworkClose // // This function is called when the network is shutting down, // or when it no longer has any IP addresses assigned to it. // static void NetworkClose() { DaemonFree( hHello ); } // // NetworkIPAddr // // This function is called whenever an IP address binding is // added or removed from the system. // static void NetworkIPAddr( IPN IPAddr, uint IfIdx, uint fAdd ) { IPN IPTmp; if( fAdd ) printf("Network Added: "); else printf("Network Removed: "); // Print a message IPTmp = ntohl( IPAddr ); printf("If-%d:%d.%d.%d.%d\n", IfIdx, (UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF, (UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF ); } // // Service Status Reports // // Here's a quick example of using service status updates // static char *TaskName[] = { "Telnet","HTTP","NAT","DHCPS","DHCPC","DNS" }; static char *ReportStr[] = { "","Running","Updated","Complete","Fault" }; static char *StatusStr[] = { "Disabled","Waiting","IPTerm","Failed","Enabled" }; static void ServiceReport( uint Item, uint Status, uint Report, HANDLE h ) { printf( "Service Status: %-9s: %-9s: %-9s: %03d\n", TaskName[Item-1], StatusStr[Status], ReportStr[Report/256], Report&0xFF ); // // Example of adding to the DHCP configuration space // // When using the DHCP client, the client has full control over access // to the first 256 entries in the CFGTAG_SYSINFO space. // // Note that the DHCP client will erase all CFGTAG_SYSINFO tags except // CFGITEM_DHCP_HOSTNAME. If the application needs to keep manual // entries in the DHCP tag range, then the code to maintain them should // be placed here. // // Here, we want to manually add a DNS server to the configuration, but // we can only do it once DHCP has finished its programming. // if( Item == CFGITEM_SERVICE_DHCPCLIENT && Status == CIS_SRV_STATUS_ENABLED && (Report == (NETTOOLS_STAT_RUNNING|DHCPCODE_IPADD) || Report == (NETTOOLS_STAT_RUNNING|DHCPCODE_IPRENEW)) ) { IPN IPTmp; // Manually add the DNS server when specified IPTmp = inet_addr(DNSServer); if( IPTmp ) CfgAddEntry( 0, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER, 0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 ); } }
2.udphello.c
? ?/* * udpHello.c * * This program implements a UDP echo server, which echos back any * input it receives. * * Copyright (C) 2007 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include <ti/ndk/inc/netmain.h> // // dtask_udp_hello() - UDP Echo Server Daemon Function // (SOCK_DGRAM, port 7) // // Returns "1" if socket 's' is still open, and "0" if its been closed // int dtask_udp_hello( SOCKET s, UINT32 unused ) { struct sockaddr_in sin1; struct timeval to; int i,tmp; char *pBuf; HANDLE hBuffer; (void)unused; // Configure our socket timeout to be 3 seconds to.tv_sec = 3; to.tv_usec = 0; setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) ); setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) ); for(;;) { tmp = sizeof( sin1 ); i = (int)recvncfrom( s, (void **)&pBuf, 0, (PSA)&sin1, &tmp, &hBuffer ); // Spit any data back out if( i >= 0 ) { sendto( s, pBuf, i, 0, (PSA)&sin1, sizeof(sin1) ); recvncfree( hBuffer ); } else break; } // Since the socket is still open, return "1" // (we need to leave UDP sockets open) return(1); }
總結(jié)
以上是生活随笔為你收集整理的DSP:6678开发板NDK网口通信完整实现(附源码)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 64位游戏找call_网络小游戏怎么修改
- 下一篇: c语言%3c与 的优先级,C语言程序设计