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.

TI-RTOS NDK IP

Other Parts Discussed in Thread: SYSBIOS

 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);

}

  • What TI-RTOS, NDK, and SYSBIOS version are you using?

  • Hi  judahvang

        I am very pleased to receive your reply

        SYS/BIOS    6.4..02.27  GA  Release  Note

        NDK    2.23.01.01   GA Release  Notes 

        TI-RTOS   2.0.2.36

        What should I add the code in udpEach.c file? And the code should be added in what position?

        Very much looking forward to your reply!

    Thanks!

  • Hi   judahvang

    I modify the content udpEcho.c as follows:

    /*

     *    ======== 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

    char *LocalIPAddr = "192.168.0.12";

    char *LocalIPMask = "255.255.255.0";

    char *GatewayIP   = "192.168.0.1";

    char *HostName    = "testhost";

    char *DomainName  = "demo.net";

    static  void  NetworkStart();

    static  void  NetworkStop();

    static  void  NetworkIPAddr();

    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 )

      {

      System_printf("NC_SystemOpen Failed (%d)\n",rc);

        for(;;);

      }

      //

      // Create and build the system configuration from scratch.

      //

      // Create a new configuration

      hCfg = CfgNew();

      if( !hCfg )

      {

      System_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 )

      {

      System_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);

    }

    static  void  NetworkStart()

    {

    }

    static  void  NetworkStop()

    {

    }

    static  void  NetworkIPAddr()

    {

    }

    /*

     *  ======== 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();

        NetworkTest();

        /* 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);

    }

    I put inside the IP module configuration .cfg modified as follows.After modifying the conflict phenomenon no code before, but found the communication function can not communicate, can not connect. May I ask what is the code I have a problem or add other problems?

    My ultimate goal is to use C code to replace the configuration in the figure below IP module。

    I am very much looking forward to your reply!

    Thanks

  • You said:

    “My ultimate goal is to use C code to replace the configuration in the figure below IP module。”

     You can do the following: 

    1. Add the following config param to the *.cfg file: Global.enableCodeGeneration = false;
      1. This will prevent the network code that you see in udpEcho_pem4f.c from being generated.
      2. With this configuration param set to false, the network settings you see in XGCONF (like in your screen shots), will no longer have any effect (as they are used to generate the code in big.c).
      3. So with this setting, you will be able to use the NDK’s legacy C configuration, instead.


    2. Make NetworkTest() into a Task, and remove the call to it from main()
      1. Make sure it has the same priority and settings as the generated Task ti_ndk_config_Global_stackThread() had.

    Judah

  • Hi  judahvang        This is one part of the .cfg file inside. I will Global.enableCodeGeneration = false; add in the following location.

    /* ================ NDK configuration ================ */

    var Ndk       = xdc.loadPackage('ti.ndk.config');

    var Global    = xdc.useModule('ti.ndk.config.Global');

    Global.enableCodeGeneration = false;

    var Udp       = xdc.useModule('ti.ndk.config.Udp');

    var Tcp       = xdc.useModule('ti.ndk.config.Tcp');

    Global.IPv6 = false;

    Global.stackLibType = Global.MIN;

    Global.networkOpenHook = "&netOpenHook";

    Global.pktSizeFrameBuf = 1536;

    Global.pktNumFrameBufs = 10;

    Global.memRawPageCount = 6;

    Global.ndkThreadStackSize = 1536;

    Global.lowTaskStackSize = 1024;

    Global.normTaskStackSize = 1024;

    Global.highTaskStackSize = 1024;

    Tcp.transmitBufSize = 0;

    Tcp.receiveBufSize = 0;

    /* ================ Driver configuration ================ */

    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');

    var EMAC = xdc.useModule('ti.drivers.EMAC');

    var GPIO = xdc.useModule('ti.drivers.GPIO');

    EMAC.libType = EMAC.LibType_NonInstrumented;

    GPIO.libType = GPIO.LibType_NonInstrumented;

    //******************************************************************************//

    but there have been the following error:

    Question 1:

    I can not seem to find the correct position to add Global.enableCodeGeneration = false;

    Question 2:

    After adding “Global.enableCodeGeneration = false”, I found the previous NDK IP module, the relevant configuration code UDP module also disappeared。If I  want to have normal communication is not adding UDP module?

    Question 3:

    I found in the .cfg configuration file of the ti_ndk_config_Global_stackThread () Task priority is 5, if my program, there are other priority task 1 or 2, it will not always be preempted by ti_ndk_config_Global_stackThread () Task?

    Question 4:

    Can you give me an associated configuration files C code?

    I am looking forward to your reply. Here, very grateful for your help!

  • #1.  Position of the statement should not matter.  The error is saying that your program will not fit into the available memory.  So somehow by doing this it increases your memory usage?  That doesn't quite make sense as less code should have been generated.

    #2.   You should do this only if you want to control the code yourself in 'c'.  You should copy and paste the relevant code into a your own 'c' file the is included with the project so that it does not get generated by the configuration tool.  Wasn't this what you wanted to do?

    #3.  Your other task can be the priority you want but the Network_test() should be a task and of the same priority as the ti_ndk_config_Global_stackThread() Task.

    #4.  You should have this in the generated .c file before you set Global.enableCodeGeneration = false.

    Judah

  • Hi  judahvang

         To discuss the issue with you makes me feel very happy!I follow your instructions, write down this process:

          I have put "Global.enableCodeGeneration = false" to add to the .cfg file.

          the entire contents of the file "cfg Script"  are as follows :

     /*  ======== udpEcho.cfg =======

    /* ================ General configuration ================ */

    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 Main = xdc.useModule('xdc.runtime.Main');

    var Memory = xdc.useModule('xdc.runtime.Memory');

    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 Task = xdc.useModule('ti.sysbios.knl.Task');

    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');

    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');

    var Udp = xdc.useModule('ti.ndk.config.Udp');

    var Ip = xdc.useModule('ti.ndk.config.Ip');

    BIOS.heapSize = 20480;

    Task.idleTaskStackSize = 768;

    Program.stack = 2048;

    /* ================ System configuration ================ */

    var SysMin = xdc.useModule('xdc.runtime.SysMin');

    System.SupportProxy = SysMin;

    /* Enable Semihosting for GNU targets to print to CCS console */

    if (Program.build.target.$name.match(/gnu/)) {

        var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');

    }

    /* ================ NDK configuration ================ */

    var Ndk       = xdc.loadPackage('ti.ndk.config');

    var Global    = xdc.useModule('ti.ndk.config.Global');

    Global.enableCodeGeneration = false;

    var Tcp       = xdc.useModule('ti.ndk.config.Tcp');

    Global.IPv6 = false;

    Global.stackLibType = Global.MIN;

    Global.networkOpenHook = "&netOpenHook";

    Global.pktSizeFrameBuf = 3072;

    Global.pktNumFrameBufs = 10;

    Global.memRawPageCount = 6;

    Global.ndkThreadStackSize = 1536;

    Global.lowTaskStackSize = 1024;

    Global.normTaskStackSize = 1024;

    Global.highTaskStackSize = 1024;

    Tcp.transmitBufSize = 0;

    Tcp.receiveBufSize = 0;

    /* ================ Driver configuration ================ */

    var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');

    var EMAC = xdc.useModule('ti.drivers.EMAC');

    var GPIO = xdc.useModule('ti.drivers.GPIO');

    EMAC.libType = EMAC.LibType_NonInstrumented;

    GPIO.libType = GPIO.LibType_NonInstrumented;

    Global.memRawPageSize = 4096;

    =================================================================

    ================================================================

    The entire contents of my own C file is shown below:

     /*    ======== 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"

    #include <ti/ndk/config/prototypes.h>

    #define UDPPORT 1000

    /* 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);

    char *ti_ndk_config_Global_HostName    = "tisoc";

    /* Static IP Address settings */

    char *LocalIPAddr = "192.168.0.3";

    char *LocalIPMask = "255.255.255.0";

    char *GatewayIP   = "192.168.0.1";

    char *DomainName  = "demo.net";

    /* Main Thread */

    Void NetworkTest(UArg arg0, UArg arg1)

    {

        int rc;

        HANDLE hCfg;

        /* 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 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();

    }

    /*

     * ======== ti.ndk.config.Ip TEMPLATE ========

     */

    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);

        }

    }

    /*

     *  ======== 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();

        Task_Handle taskHandle;

        Task_Params taskParams;

        Error_Block eb;

        /* Make sure Error_Block is initialized */

        Error_init(&eb);

        Task_Params_init(&taskParams);

        taskParams.stackSize = 1024;

        taskParams.priority = 5;

        taskHandle = Task_create((Task_FuncPtr)NetworkTest, &taskParams, &eb);

        if (taskHandle == NULL) {

              System_printf("main: Failed to create NetworkTest Task\n");

            }

        /* 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);

    }

    But still get the following error:

    I tried to modify the configuration of many parts of the code, but still can not solve this problem. "UdpEcho.c" file for me have to add a lot of code. Will this error mentioned in the memory is the memory of what? I should be how to do to expand the memory, which can solve the problem?

    In the process of communication with you, I feel you are very proficient TI-RTOS, I hope you can help me solve this problem! I'm looking forward to your reply!

  • Did you solve your problem? I am still having trouble understanding what you are trying to do.

    If you still have the problem, can you give me a step by step way of reproducing your problem?
  • Hi   judahvang 

          I now want to ask you a new question. I have now created a network task, I want this task thread when I'm not connected to the network tasks, let it sleep, when to use it to wake it up. That makes this task threads into a daemon thread.

    Should  I Semaphore_post (sem2) and Semaphore_pend (sem2, BIOS_WAIT_FOREVER) add these two statements on what the right position?

    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();
    }

    Thanks

    Lewis