Hi all
I'm CCS6.0.1 inside using TIRTOS, which NDK regarding the IP address of the UDP traffic if they do not use such a configuration file .cfg tools to configure the IP but to use C code to configure static IP I how to correct to use it. Because if you use .cfg configure its IP address, I have no way to modify it through the network. If the inside of the file system by RTOS to modify this file .cfg how should I go operation, I found inside the file system module RTOS support only seems to mount the device to operate it?
I found the following code on configuring documents related to it, but to add it more appropriate point in what position?
int NetworkTest()
{
int rc;
CI_IPNET NA;
CI_ROUTE RT;
HANDLE hCfg;
//
// 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(;;);
}
//
// 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'd 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;
}
// Manually configure our local 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 our hostname
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
strlen(HostName), (UINT8 *)HostName, 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 );
//
// Boot the system using this configuration
//
// We keep booting until the function returns less than 1. This allows
// us to have a "reboot" command.
//
do
{
rc = NC_NetStart( hCfg, NetworkStart, NetworkStop, NetworkIPAddr );
} while( rc > 0 );
// Delete Configuration
CfgFree( hCfg );
// Close the OS
main_exit:
NC_SystemClose();
return(0);
}
But I use the TIRTOS for TivaC of routine udpEcho_TivaTM4C1294NCPDT experiment a result, a lot of errors that seems to be repeated occurrence of certain modules are defined. So I found a file udpEcho_pem4f.c in udpEcho_TivaTM4C1294NCPDT \ Debug \ configPkg \ package \ cfg\udpEcho_pem4f.c. In this document I found the following code:
======================================================================
/* Our NETCTRL callback functions */
static void ti_ndk_config_Global_NetworkOpen();
static void ti_ndk_config_Global_NetworkClose();
static void ti_ndk_config_Global_NetworkIPAddr(IPN IPAddr, uint IfIdx, uint fAdd);
extern void llTimerTick();
char *ti_ndk_config_Global_HostName = "tisoc";
/* Static IP Address settings */
char *LocalIPAddr = "192.168.0.2";
char *LocalIPMask = "255.255.255.0";
char *GatewayIP = "192.168.0.1";
char *DomainName = "demo.net";
/* Main Thread */
Void ti_ndk_config_Global_stackThread(UArg arg0, UArg arg1)
{
int rc;
HANDLE hCfg;
ti_sysbios_knl_Clock_Params clockParams;
/* Create the NDK heart beat */
ti_sysbios_knl_Clock_Params_init(&clockParams);
clockParams.startFlag = TRUE;
clockParams.period = 100;
ti_sysbios_knl_Clock_create(&llTimerTick, clockParams.period, &clockParams, NULL);
/* THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!! */
rc = NC_SystemOpen(NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT);
if (rc) {
xdc_runtime_System_abort("NC_SystemOpen Failed (%d)\n");
}
/* Create and build the system configuration from scratch. */
hCfg = CfgNew();
if (!hCfg) {
xdc_runtime_System_printf("Unable to create configuration\n");
goto main_exit;
}
/* add the Ip module configuration settings. */
ti_ndk_config_ip_init(hCfg);
/* add the Tcp module configuration settings. */
ti_ndk_config_tcp_init(hCfg);
/* add the Udp module configuration settings. */
ti_ndk_config_udp_init(hCfg);
/* add the configuration settings for NDK low priority tasks stack size. */
rc = 1024;
CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKLOW,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
/* add the configuration settings for NDK norm priority tasks stack size. */
rc = 1024;
CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKNORM,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
/* add the configuration settings for NDK high priority tasks stack size. */
rc = 1024;
CfgAddEntry(hCfg, CFGTAG_OS, CFGITEM_OS_TASKSTKHIGH,
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, ti_ndk_config_Global_NetworkOpen,
ti_ndk_config_Global_NetworkClose,
ti_ndk_config_Global_NetworkIPAddr);
} while( rc > 0 );
/* Delete Configuration */
CfgFree(hCfg);
/* Close the OS */
main_exit:
NC_SystemClose();
xdc_runtime_System_flush();
}
/*
* ti_ndk_config_Global_NetworkOpen
*
* This function is called after the configuration has booted
*/
static void ti_ndk_config_Global_NetworkOpen()
{
{
extern Void netOpenHook();
/* call user defined network open hook */
netOpenHook();
}
}
/*
* ti_ndk_config_Global_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 ti_ndk_config_Global_NetworkClose()
{
}
/*
* ti_ndk_config_Global_NetworkIPAddr
*
* This function is called whenever an IP address binding is
* added or removed from the system.
*/
static void ti_ndk_config_Global_NetworkIPAddr(IPN IPAddr, uint IfIdx, uint fAdd)
{
IPN IPTmp;
if (fAdd) {
xdc_runtime_System_printf("Network Added: ");
}
else {
xdc_runtime_System_printf("Network Removed: ");
}
// Print a message
IPTmp = ntohl(IPAddr);
xdc_runtime_System_printf("If-%d:%d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF);
xdc_runtime_System_flush();
}
/*
* Service Status Reports
*
* Function for reporting 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"};
Void ti_ndk_config_Global_serviceReport(uint Item, uint Status,
uint Report, HANDLE h)
{
xdc_runtime_System_printf("Service Status: %-9s: %-9s: %-9s: %03d\n",
TaskName[Item-1], StatusStr[Status],
ReportStr[Report/256], Report&0xFF);
xdc_runtime_System_flush();
}
/*
* ======== ti.ndk.config.Tcp TEMPLATE ========
*/
Void ti_ndk_config_tcp_init(HANDLE hCfg)
{
{
Int transmitBufSize = 0;
CfgAddEntry(hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&transmitBufSize, 0);
}
{
Int receiveBufSize = 0;
CfgAddEntry(hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&receiveBufSize, 0);
}
{
Int receiveBufLimit = 2048;
CfgAddEntry(hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&receiveBufLimit, 0);
}
}
/*
* ======== ti.ndk.config.Ip TEMPLATE ========
*/
#include <ti/ndk/inc/netmain.h>
#include <ti/ndk/config/prototypes.h>
Void ti_ndk_config_ip_init(HANDLE hCfg)
{
/* Add our global hostname to hCfg (to be claimed in all connected domains) */
CfgAddEntry(hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
strlen(ti_ndk_config_Global_HostName),
(UINT8 *)ti_ndk_config_Global_HostName, 0);
/* Configure IP address manually on interface 1 */
{
CI_IPNET NA;
CI_ROUTE RT;
/* 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;
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);
CfgAddEntry(hCfg, CFGTAG_ROUTE, 0, 0,
sizeof(CI_ROUTE), (UINT8 *)&RT, 0);
}
}
/*
* ======== ti.ndk.config.Udp TEMPLATE ========
*/
Void ti_ndk_config_udp_init(HANDLE hCfg)
{
{
Int receiveBufSize = 2048;
CfgAddEntry(hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&receiveBufSize, 0);
}
}
======================================================================
I think I'm going to add these and those of the C code to configure the IP address conflict. Can I change how like to rewrite this udpEcho_TivaTM4C1294NCPDT routines to make them functional communication and modify IP using C code can be the purpose of such use of the process in the future?
The following code is udpEcho_TivaTM4C1294NCPDT the udpEcho.c content:
Please can you help me correct configuration code to add in the following documents in udpEcho.c.
Here, I would be very grateful, and very looking forward to your reply!
======================================================================
/*
* ======== udpEcho.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/Memory.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
/* NDK Header files */
#include <ti/ndk/inc/netmain.h>
#include <ti/ndk/inc/_stack.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
/* Example/Board Header files */
#include "Board.h"
#define UDPPORT 1000
/*
* ======== udpHandler ========
* Echo back all UDP data received.
*
* Since we are using UDP, the same socket is used for all incoming requests.
*/
Void udpHandler(UArg arg0, UArg arg1)
{
SOCKET lSocket;
struct sockaddr_in sLocalAddr;
struct sockaddr_in client_addr;
struct timeval to;
fd_set readfds;
int addrlen = sizeof(client_addr);
int status;
HANDLE hBuffer;
IPN LocalAddress = 0;
int nbytes;
bool flag = true;
char *buffer;
fdOpenSession(TaskSelf());
lSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (lSocket < 0) {
System_printf("udpHandler: socket failed\n");
Task_exit();
return;
}
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
sLocalAddr.sin_family = AF_INET;
sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = LocalAddress;
sLocalAddr.sin_port = htons(arg0);
status = bind(lSocket, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr));
if (status < 0) {
System_printf("udpHandler: bind failed: returned: %d, error: %d\n",
status, fdError());
fdClose(lSocket);
Task_exit();
return;
}
/* Give user time to connect with udpSendReceive client app */
to.tv_sec = 30;
to.tv_usec = 0;
if (setsockopt( lSocket, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) ) < 0) {
System_printf("udpHandler: setsockopt SO_SNDTIMEO failed\n");
fdClose(lSocket);
Task_exit();
return;
}
if (setsockopt( lSocket, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) ) < 0) {
System_printf("udpHandler: setsockopt SO_RCVTIMEO failed\n");
fdClose(lSocket);
Task_exit();
return;
}
/* Loop while we receive data */
while (flag) {
/*
* Wait for the reply. Timeout after TIMEOUT seconds (assume UDP
* packet dropped)
*/
FD_ZERO(&readfds);
FD_SET(lSocket, &readfds);
if (fdSelect(0, &readfds, NULL, NULL, NULL) != 1) {
status = fdError();
System_printf("timed out waiting for client\n", status);
continue;
}
nbytes = recvncfrom(lSocket, (void **)&buffer, MSG_WAITALL,
(struct sockaddr *)&client_addr, &addrlen, &hBuffer);
if (nbytes >= 0) {
/* Echo the data back */
sendto(lSocket, (char *)buffer, nbytes, 0,
(struct sockaddr *)&client_addr, sizeof(client_addr));
recvncfree( hBuffer );
}
else {
status = fdError();
if (status == EWOULDBLOCK) {
System_printf("udpHandler: Waiting for client to send UDP data\n");
continue;
}
else {
System_printf(
"udpHandler: recvfrom failed: returned: %d, error: %d\n",
nbytes, status);
fdClose(lSocket);
flag = false;
}
}
}
System_printf("udpHandler stop, lSocket = 0x%x\n", lSocket);
if (lSocket) {
fdClose(lSocket);
}
fdCloseSession(TaskSelf());
/*
* Since deleteTerminatedTasks is set in the cfg file,
* the Task will be deleted when the idle task runs.
*/
Task_exit();
}
/*
* ======== netOpenHook ========
*/
void netOpenHook()
{
Task_Handle taskHandle;
Task_Params taskParams;
Error_Block eb;
/* Make sure Error_Block is initialized */
Error_init(&eb);
/*
* Create the Task that handles UDP "connections."
* arg0 will be the port that this task listens to.
*/
Task_Params_init(&taskParams);
taskParams.stackSize = 1024;
taskParams.priority = 1;
taskParams.arg0 = UDPPORT;
taskHandle = Task_create((Task_FuncPtr)udpHandler, &taskParams, &eb);
if (taskHandle == NULL) {
System_printf("main: Failed to create udpHandler Task\n");
}
}
/*
* ======== main ========
*/
int main(void)
{
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
Board_initEMAC();
/* Turn on user LED */
GPIO_write(Board_LED0, Board_LED_ON);
System_printf("Starting the UDP Echo example\nSystem provider is set to "
"SysMin. Halt the target to view any SysMin contents in"
" ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}