This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/AM5726: Configuring Basic TCP socket client on DSP using NDK

Part Number: AM5726
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.

  • Hi,

    I am not sure if you followed up with any of our NDK examples under pdk_am57xx_1_0_x\packages\ti\transport\ndk\nimu\example. There are the app.cfg file for the NDK modules, also the how the NIMUDeviceTable is initialized.

    From the SYSBIOS main(), it typically runs a stacktest(), This is a big setup function, at the end you will see:
    rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );

    Where NetworkOpen() may starts some local server like:
    // Create our local servers
    hEcho = DaemonNew( SOCK_STREAMNC, 0, 7, dtask_tcp_echo,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hEchoUdp = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_echo,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 );
    hData = DaemonNew( SOCK_STREAM, 0, 1000, dtask_tcp_datasrv,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hNull = DaemonNew( SOCK_STREAMNC, 0, 1001, dtask_tcp_nullsrv,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
    hOob = DaemonNew( SOCK_STREAMNC, 0, 999, dtask_tcp_oobsrv,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );

    For you, you want to starts a TCP client. This is where you need to add with you code client code.

    Regards, Eric
  • Hello,

    We were able to run the TCP/IP Example properly on DSP1 only. However once we run linux in parralell and load the application using remoteproc the stack is locked at DHCP request. It seems like the semaphores are waiting forever. Do you have any expierience running NDK on DSP1 and Linux in parallel?

    Many thanks in advance!

  • Wajdi,

    This thread is closed. Running RTOS NDK + Linux is a new topic, please open a new thread for that.

    Regards, Eric