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.

.cfg File is not used to how to configure a static IP address

Other Parts Discussed in Thread: SYSBIOS

      I'm CCS6.0.1 inside using TI-RTOS, 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);
}


Please also TI employees or experts who know the way to help me, I would be very grateful!

  • A TI-RTOS application has a configuration file (with extension of “.cfg”), which is used to build the application.  The “.cfg” file is not used by a program later during runtime, but only during build time, so there wouldn’t be a reason to place this in a local file system. 

    Also, NDK has a separate runtime configuration interface (with functions with a prefix of “Cfg”) – but this is something completely different.

    I think the code you posted is from Section 3.2.4.1.1 “Constructing a Configuration for a Static IP and Gateway” in the NDK User’s Guide (http://www.ti.com/lit/ug/spru523i/spru523i.pdf).  In that example the IP address is defined in the C code in a string “LocalIPAddr”, and that string is used to fill in the structure that is passed to the function CfgAddEntry():

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

    So, the IP address is not in the .cfg file, but is in a string that is used at runtime as part of starting the network. 

    So if you want to use a different IP address that your program determines at runtime, I think you need to dynamically create a character string, with that specific address to use, and then use that string to initialize NA.IPAddr.

    Hope this helps.

    Scott

  • Hi Scott Gary:

     I am very pleased to receive your reply. 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!

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

    /*

     * Copyright (c) 2014, Texas Instruments Incorporated

     * All rights reserved.

     *

     * Redistribution and use in source and binary forms, with or without

     * modification, are permitted provided that the following conditions

     * are met:

     *

     * *  Redistributions of source code must retain the above copyright

     *    notice, this list of conditions and the following disclaimer.

     *

     * *  Redistributions in binary form must reproduce the above copyright

     *    notice, this list of conditions and the following disclaimer in the

     *    documentation and/or other materials provided with the distribution.

     *

     * *  Neither the name of Texas Instruments Incorporated nor the names of

     *    its contributors may be used to endorse or promote products derived

     *    from this software without specific prior written permission.

     *

     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,

     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR

     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR

     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,

     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,

     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;

     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR

     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,

     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

     */

    /*

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

    }

  • Hi Scott Gary
    I am very pleased to receive your reply.
    But I use the TI-RTOS 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!
    ===========================================================================================================
    /*
    * Copyright (c) 2014, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    /*
    * ======== 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 build errors are you getting?

    And can you explain exactly how you modified the udpEcho example?   In some of the code you posted I see this block, apparently in ..\Debug\...\udpEcho_pem4f.c  

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

    Did you edit that file directly?  That particular file will be automatically generated when the project is built, and anything you add to it will be lost when there is a change that triggers rebuild of some of the project files.

    Or did you add it to another C file?  I don’t see it in what you show for udpEcho.c

    It would be easier to see what you’ve done if you attach the files you’ve modified, versus cutting and pasting the text all together…

    Thanks,
    Scott

  • Hi   Scott

    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

  • I believe that this question was answered in an alternate thread, so I am marking it as Answered.