Other Parts Discussed in Thread: OMAPL138,
Tool/software: TI-RTOS
Hello TI members,
For past couple of days I am struggling to run the TI-NDK without using the XCONFIG configuration setting tool and I want to set the configuration with the c code initialisation method of the TI-NDK as mentioned in the file spru524j , but I am unable to achieve that till now.
what I am doing is here:
First I created an empty project from the TI resource explorer and than I did following changes to it in order to make the TI-NDK gets initialised with the c code.
First of all I took the help from the example code of "ndk_omapl138_arm9_examples" in the nsp package.
So as the project got imported I also have a *.cfg file with minimal amount of xconfig settings in it.
I added following lines of code to the configuration file which are as follow:
// Added the memory configuration of Heap. It is required as without it the system create error.
var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
/* create a HeapMem heap instance "systemHeap" */
var systemHeapParams = new HeapMem.Params;
systemHeapParams.size = 0x00002000;
//systemHeapParams.size = 0x00020000;
var systemHeap = HeapMem.create(systemHeapParams);
/* set "systemHeap" to be the default Heap for the app */
Memory.defaultHeapInstance = systemHeap;
/*There after I added following code section at very last of the configuration file */
var Global = xdc.useModule('ti.ndk.config.Global');
Global.enableCodeGeneration = false;
/* create the NDK stack Task thread */
var Task = xdc.useModule('ti.sysbios.knl.Task');
var ndkTaskParams = new Task.Params();
ndkTaskParams.priority = 5;
ndkTaskParams.stackSize = 8192;
Task.create('&StackTest', ndkTaskParams);
Now In the main.c file I added the following code apart from the minimal code present already for blinking an led in a task.
/* Included following files */
#include <stdio.h>
#include <netmain.h>
#include <_stack.h>
#include <servers.h>
/* Added following line of code in it */
//---------------------------------------------------------------------------
// 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 );
//---------------------------------------------------------------------------
// Configuration
//
char *HostName = "tidsp";
char *LocalIPAddr = "0.0.0.0"; // Set to "0.0.0.0" for DHCP
char *LocalIPMask = "255.255.254.0"; // Not used when using DHCP
char *GatewayIP = "0.0.0.0"; // 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
// This callback function is called by the evaluation stack 5 min before the
// evaluation period times out.
void evalCallBack()
{
printf("The Stack is going to shutdown in 5 min\n");
}
HANDLE hCfg;
//
// Main Thread
//
int StackTest()
{
int rc;
//
// 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;
}
// The evaluation version of TCP/IP Stack restricts usage of stack
// to maximum of 24 Hours. If application wants to be notified 5 min
// before the timeout, it can register a callback function by using
// the following configuration code section.
/*{
void (*pFxn)() = &evalCallBack;
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_SYSINFO_EVALCALLBACK, 0,
sizeof(void(*)()), (UINT8*) &pFxn, 0 );
}*/
// 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( inet_addr(LocalIPAddr) )
{
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
{
//
}
//
// 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);
}
void DHCPTestTask(void)
{
HANDLE dhcpService;
CI_SERVICE_DHCPC dhcpc;
TaskSleep(3000);
// Specify DHCP Service on IF-1
bzero( &dhcpc, sizeof(dhcpc) );
dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID;
dhcpc.cisargs.IfIdx = 1;
dhcpc.cisargs.pCbSrv = &ServiceReport;
printf("Before adding DCHP");
//_mmCheck(MMCHECK_MAP, &printf);
CfgAddEntry(hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0, sizeof(dhcpc), (UINT8*)&dhcpc, 0);
printf("After adding DCHP");
//_mmCheck(MMCHECK_MAP, &printf);
TaskSleep(3000);
if (CfgGetEntry(hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 1, &dhcpService) > 0)
{
CfgRemoveEntry(hCfg, dhcpService);
}
printf("After removing DCHP");
//_mmCheck(MMCHECK_MAP, &printf);
}
//
// NetworkOpen
//
// This function is called after the configuration has booted
//
static void NetworkOpen()
{
TaskCreate( DHCPTestTask, "DHCPTest", OS_TASKPRINORM, 0x1400, 0, 0, 0 );
}
//
// 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 );
}
}
After adding this code I was having some compiler error related to _mmCheck function which I suppressed by commenting it for now in the entire code.
and now my code is compiling successfully but the problem starts in the linking phase where it says:
<Linking> "../EK_TM4C1294XL.cmd", line 54: error #10099-D: program will not fit into available memory. run placement with alignment fails for section ".bss" size 0x5eb50 . Available memory ranges: SRAM size: 0x40000 unused: 0x3e080 max hole: 0x3e080 error #10010: errors encountered during linking; "NetworkCfgTest.out" not built
So I want to know that would I be not able to configure the NDK stack through c code method on tiva board which I think is not a case.
Please guide me how should I proceed so that it build successfully and also gets the static IP address during runtime.
regards
