EK-TM4C1294XL: Integrate the NDK Independently

Part Number: EK-TM4C1294XL

Tool/software:

Hi there!

Greetings for the day!

I wish to integrate NDK to my existing project. I made use of XGCONF to enable NDK and I am able to have socket communication. However making use of XGCONF is leading to internal control of NDK. I wish to have the NDK control in my hands and wish to initialize and de-initialize NDK based on my needs.

Can you please help me on how can I make this happen? How can I shift the control of NDK from XGCONF to my control?

Looking forward to your response!

Thanks & Regards,

Siddhi

  • Hi,

     Please refer to the NDK Developer's guide section 2 "Configuring NDK with C code" as an alternative method to using XGCONF. You would need to call CfgNew() function and CfgAddEntry() function. Refer to section 2.1.4.1 for example. 

     When XGCONF is used based off the .cfg file, the NDK code is automatically generated per the .cfg specification. If you look at the NDK example for TcpEcho, the generated file is located in your project under Debug->configPkg->package->cfg->tcpEcho_pem4f.c. You can look at this file too. Look at the function ti_ndk_config_Global_stackThread() on how the NDK is initialized. 

  • I am getting this error after integrating ndk     

  • Hi,

      I can't comment on these errors without context. I will suggest you use your current XGCONF as a starting point and reference and reference how the NDK is initialized and configured in the tcpEcho_pem4f.c file and then disable NDK from being regenerated based on the .cfg file. I have not really seen people using NDK entirely without the .cfg file as it takes care of all the backend configuration and source code generation for the NDK. 

  • HI 

    I am using the exact same approach. I went through the tcpEcho._pem4f.c file and using XGCONF for internal generation and linking of source code yet I am facing these errors. Please find below the code I am using.

    void
    NDK_START_THREAD(void)
    {
    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 Tcp module configuration settings. */
    ti_ndk_config_tcp_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 );

    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()
    {

    // netOpenHook(); (Initialize sockets here)
    }

    /*
    * 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.
    */

    const static char *TaskName[] = {"Telnet","HTTP","NAT","DHCPS","DHCPC","DNS"};
    const static char *ReportStr[] = {"","Running","Updated","Complete","Fault"};
    const 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 = 1024;
    CfgAddEntry(hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
    CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&transmitBufSize, 0);
    }
    {
    Int receiveBufSize = 1024;
    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);
    }
    }

  • I went through the tcpEcho._pem4f.c file and using XGCONF for internal generation and linking of source code yet I am facing these errors.

    What do you mean you use XGCONF for internal generation. Are you saying you use the .cfg to generate some basic code and then manually add additional code like what you are showing here?

  • I am adding ndk config through .cfg with enableCodegeneration = false. Thats how I am using ndk config and my personal C Code together.

  • Hi,

      Perhaps these posts will help. 

     https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/891734/ccs-tm4c1294ncpdt-what-s-the-correct-way-to-manually-link-ndk-libraries-to-a-project 

    https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/646100/rtos-sw-ek-tm4c1294xl-change-static-ip-at-runtime/2378384#2378384

      I will also suggest you first use the NDK project that is currently working based on the .cfg file and in your application add one CfgAddEntry to create a new service at a time to see if each new service is creating a compile issue or not.