Other Parts Discussed in Thread: SYSBIOS
Tool/software: TI-RTOS
Code Composer Studio Version: 7.4.0.00015
NDK 2.26.0.08
SYS/BIOS 6.52.0.12
am57XX PDK 1.0.9
Target : ti.targets.elf.C66
Platform : ti.platforms.evAM5732X
I am trying to start a basic network tcp socket client from a DSP core using NDK,
that will connect to a tcp socket server on a desktop via ethernet.
I have tested this client code on a linux platform and now I am trying to run it on TiRTOS.
I get an error at connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))
I want to use the default Ethernet drivers, do I need to initialize the NIMUDeviceTable ?
/*
* ======== main.c ========
*/
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/ndk/inc/stkmain.h>
#include <ti/ndk/inc/netmain.h>
#define MAX_TABLE_ENTRIES 3U
NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[MAX_TABLE_ENTRIES];
#include <stdio.h>
int create_client(void){
static int port=50000;
static char ip_address[]={"192.168.1.6"};
static SOCKET sockfd;
struct sockaddr_in serv_addr;
static char buff[100];
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)
{
System_printf("\nError : Could not create socket \n");
perror("fdError socket()");
`
return(-1);
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port);
serv_addr.sin_addr.s_addr = inet_addr(ip_address);
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
System_printf("\nError : Could not connect socket \n");
fdError("fdError : connect() ");
perror("perror : connect() ");
return(-1);
}
static int i=10;
while (i>0){
send(sockfd, "ping", 4, 0);
System_printf("sent : %s\n", "ping");
recv(sockfd, buff, 4, 0);
System_printf("received : %s\n", buff);
i--;
}
return(0);
}
/*
* ======== taskFxn ========
*/
Void taskFxn(UArg a0, UArg a1)
{
static int ret=0;
fdOpenSession(TaskSelf());
System_printf("Starting client thread \n");
ret = create_client();
System_printf("Exiting client thread with ret %d \n", ret);
fdCloseSession(TaskSelf());
System_flush(); /* force SysMin output to console */
}
/*
* ======== main ========
*/
Int main()
{
Task_Handle task;
Error_Block eb;
System_printf("enter main()\n");
Error_init(&eb);
task = Task_create(taskFxn, NULL, &eb);
if (task == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}
BIOS_start(); /* does not return */
return(0);
}
I need help with the configuration file
1). Have I missed any ndk specific modules in the app.cfg file ?
2). Have I configured the static ip address appropriately in the app.cfg file ?
/*
* ======== app.cfg ========
*/
var Defaults = xdc.useModule('xdc.runtime.Defaults');
var Diags = xdc.useModule('xdc.runtime.Diags');
var Error = xdc.useModule('xdc.runtime.Error');
var Log = xdc.useModule('xdc.runtime.Log');
var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
var Main = xdc.useModule('xdc.runtime.Main');
var Memory = xdc.useModule('xdc.runtime.Memory')
var SysMin = xdc.useModule('xdc.runtime.SysMin');
var System = xdc.useModule('xdc.runtime.System');
var Text = xdc.useModule('xdc.runtime.Text');
var BIOS = xdc.useModule('ti.sysbios.BIOS');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Swi = xdc.useModule('ti.sysbios.knl.Swi');
var Task = xdc.useModule('ti.sysbios.knl.Task');
var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
/*
* Uncomment this line to globally disable Asserts.
* All modules inherit the default from the 'Defaults' module. You
* can override these defaults on a per-module basis using Module.common$.
* Disabling Asserts will save code space and improve runtime performance.
Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
*/
/*
* Uncomment this line to keep module names from being loaded on the target.
* The module name strings are placed in the .const section. Setting this
* parameter to false will save space in the .const section. Error and
* Assert messages will contain an "unknown module" prefix instead
* of the actual module name.
Defaults.common$.namedModule = false;
*/
/*
* Minimize exit handler array in System. The System module includes
* an array of functions that are registered with System_atexit() to be
* called by System_exit().
*/
System.maxAtexitHandlers = 4;
/*
* Uncomment this line to disable the Error print function.
* We lose error information when this is disabled since the errors are
* not printed. Disabling the raiseHook will save some code space if
* your app is not using System_printf() since the Error_print() function
* calls System_printf().
Error.raiseHook = null;
*/
/*
* Uncomment this line to keep Error, Assert, and Log strings from being
* loaded on the target. These strings are placed in the .const section.
* Setting this parameter to false will save space in the .const section.
* Error, Assert and Log message will print raw ids and args instead of
* a formatted message.
Text.isLoaded = false;
*/
/*
* Uncomment this line to disable the output of characters by SysMin
* when the program exits. SysMin writes characters to a circular buffer.
* This buffer can be viewed using the SysMin Output view in ROV.
SysMin.flushAtExit = false;
*/
/*
* The BIOS module will create the default heap for the system.
* Specify the size of this default heap.
*/
//BIOS.heapSize = 0x1000;
BIOS.heapSize = 0xA0000;
/*
* Build a custom SYS/BIOS library from sources.
*/
BIOS.libType = BIOS.LibType_Custom;
/* System stack size (used by ISRs and Swis) */
//Program.stack = 0x2000;
Program.stack = 0x10000;
/* Circular buffer size for System_printf() */
SysMin.bufSize = 0x200;
/*
* Create and install logger for the whole system
*/
var loggerBufParams = new LoggerBuf.Params();
loggerBufParams.numEntries = 16;
var logger0 = LoggerBuf.create(loggerBufParams);
Defaults.common$.logger = logger0;
Main.common$.diags_INFO = Diags.ALWAYS_ON;
System.SupportProxy = SysMin;
/* NDK modules */
var Ndk = xdc.loadPackage('ti.ndk.config');
var Global = xdc.useModule('ti.ndk.config.Global');
var Ip = xdc.useModule('ti.ndk.config.Ip');
var Tcp = xdc.useModule('ti.ndk.config.Tcp');
Tcp.transmitBufSize = 16384;
Tcp.receiveBufSize = 65536;
Tcp.receiveBufLimit = 65536;
Global.ndkTickPeriod = 100;
Global.kernTaskPriLevel = 11;
Global.serviceReportHook = null;
Global.IPv6 = false;
/* Settings for static IP configuration */
Ip.ResolveIP = false;
Ip.CallByIP = false;
Ip.autoIp = false;
Ip.address = "192.168.1.4";
Ip.mask = "255.255.255.0";
Ip.gatewayIpAddr = "192.168.1.1";
/* ================ Driver configuration ================ */
/* Load the OSAL package */
var osType = "tirtos"
var Osal = xdc.useModule('ti.osal.Settings');
Osal.osType = osType;
/* Load the UART package */
var UART = xdc.loadPackage('ti.drv.uart');
/* Load the I2C package */
var I2C = xdc.loadPackage('ti.drv.i2c');
/* Load the Board package and set the board name */
var Board = xdc.loadPackage('ti.board');
Board.Settings.boardName = "idkAM572x";
var socType = "am572x";
var deviceType = "am572x";
/* Load the CSL package */
var Csl = xdc.loadPackage('ti.csl');
Csl.Settings.deviceType = socType;
/* Load the EMAC packages */
var Emac = xdc.loadPackage('ti.drv.emac');
Emac.Settings.socType = socType;
/* Load the NIMU package */
var Nimu = xdc.loadPackage('ti.transport.ndk.nimu');
Nimu.Settings.socType = socType;
/* ================ Task configuration ================ */
Task.defaultStackSize = 4096;
Task.idleTaskStackSize = 4096;
Tcp.transmitBufSize = 16384;
Tcp.receiveBufSize = 65536;
Tcp.receiveBufLimit = 65536;
Global.ndkTickPeriod = 100;
Global.kernTaskPriLevel = 11;
Global.serviceReportHook = null;
Global.IPv6 = false;
/* Settings for static IP configuration */
Ip.ResolveIP = false;
Ip.CallByIP = false;
Ip.autoIp = false;
Ip.address = "192.168.1.4";
Ip.mask = "255.255.255.0";
Ip.gatewayIpAddr = "192.168.1.1";
wwr,
Edmund C.