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.

NDK configuration stack thread

Hello,

i'm using TM4C129 with XDCtool xdctools_3_31_02_38_core and TI-RTOS tirtos_tivac_2_14_00_10.

and i wanted to created my own NDK configuration stack thread, so that at the board startup, the board will check the user IP configuration to be used to configure the IP setting static/dynamic.

so i created  a task SoAd_vNetworkConfigurationTask which will be used instead of ti_ndk_config_Global_stackThread which will be generated automatically if Global.enableCodeGeneration is true. my code is setting this variable to false.

but once i compiled the code, i'm getting the following error:

"program will not fit into available memory. run placement with alignment fails for section "BSS_GROUP" size 0x7c8f8 . Available memory ranges: SoAd_HOOK.c /ICG/ATI Library/Service Layer/Communication/Socket Adaptor C/C++ Problem:

and once i commented the line

s32ReturnStatus = NC_SystemOpen(NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT);

The code will compile properly!!

so please find the attached cfg file and  a part of my code which include the task and few helper API that will be used by the task.6011.ICG.cfg

void SoAd_vNetworkConfigurationTask(INT32U u32Argument1, INT32U u32Argument2)
{
    INT32S s32ReturnStatus, s32NewValue;
    HANDLE hCfgIpAddr;
    SoAd_vStackThreadBeginHook();
    /* THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!! */
    s32ReturnStatus = NC_SystemOpen(NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT);
    if(s32ReturnStatus)
    {
        SoAd_vmLogError1(&objstrSoAdModuleInfoType, "NC_SystemOpen Failed (%d)", s32ReturnStatus);
    }
    else
    {
        /* Create a new configuration */
        hCfgIpAddr = CfgNew();
        if(hCfgIpAddr)
        {
            /* call user defined stack initialization hook */
            Web_vAddFiles();
            /* add the Ip module configuration settings. */
            SoAd_vInitIPConfig(hCfgIpAddr);
            /* add the Http module configuration settings. */
            SoAd_vInitHTTPConfig(hCfgIpAddr);
            /* add the Tcp module configuration settings. */
            SoAd_vInitTCPConfig(hCfgIpAddr);
            /* add the Udp module configuration settings. */
            SoAd_vInitUDPConfig(hCfgIpAddr);
            /* add the configuration settings for NDK low priority tasks stack size. */
            s32NewValue = 1024;
            CfgAddEntry(hCfgIpAddr, \
                        CFGTAG_OS, \
                        CFGITEM_OS_TASKSTKLOW,\
                        CFG_ADDMODE_UNIQUE, \
                        sizeof(uint), \
                        (UINT8 *)&s32NewValue, \
                        0);
            /* add the configuration settings for NDK norm priority tasks stack size. */
            s32NewValue = 1024;
            CfgAddEntry(hCfgIpAddr, \
                        CFGTAG_OS, \
                        CFGITEM_OS_TASKSTKNORM,\
                        CFG_ADDMODE_UNIQUE, \
                        sizeof(uint), \
                        (UINT8 *)&s32NewValue, \
                        0);
            /* add the configuration settings for NDK high priority tasks stack size. */
            s32NewValue = 2048;
            CfgAddEntry(hCfgIpAddr, \
                        CFGTAG_OS, \
                        CFGITEM_OS_TASKSTKHIGH,
                        CFG_ADDMODE_UNIQUE, \
                        sizeof(uint), \
                        (UINT8 *)&s32NewValue, \
                        0);
            /*
             *  Boot the system using this configuration
             *  We keep booting until the function returns 0. This allows
             *  us to have a "reboot" command.
            */
            do
            {
                s32ReturnStatus = NC_NetStart(hCfgIpAddr,\
                                              SoAd_vNetworkOpenHook,\
                                              SoAd_vNetworkCloseHook,\
                                              SoAd_vNetworkIPAddressChangeHook);
            }while(s32ReturnStatus > 0);
            /* call user defined stack delete hook */
             Web_vRemoveFiles();
            /* Delete Configuration */
            CfgFree(hCfgIpAddr);
            /* Close the OS */
            NC_SystemClose();
        }
        else
        {
            /* Close the OS */
            NC_SystemClose();
            SoAd_vmLogError0(&objstrSoAdModuleInfoType, "Can't create new Network configuration");
        }
    }
}
static void SoAd_vInitUDPConfig(HANDLE hCfgIpAddr)
{
    INT32S s32ReceiveBufSize;
    s32ReceiveBufSize = 2048;
    CfgAddEntry(hCfgIpAddr, \
                CFGTAG_IP, \
                CFGITEM_IP_SOCKUDPRXLIMIT,\
                CFG_ADDMODE_UNIQUE, \
                sizeof(uint), \
                (UINT8 *)&s32ReceiveBufSize, \
                0);
}
static void SoAd_vInitTCPConfig(HANDLE hCfgIpAddr)
{
    INT32S s32TransmitBufSize,s32ReceiveBufSize, s32ReceiveBufLimit;
    s32TransmitBufSize = 1024;
    CfgAddEntry(hCfgIpAddr, \
                CFGTAG_IP, \
                CFGITEM_IP_SOCKTCPTXBUF,\
                CFG_ADDMODE_UNIQUE, \
                sizeof(uint), \
                (UINT8 *)&s32TransmitBufSize, \
                0);
    s32ReceiveBufSize = 1024;
    CfgAddEntry(hCfgIpAddr, \
                CFGTAG_IP, \
                CFGITEM_IP_SOCKTCPRXBUF,\
                CFG_ADDMODE_UNIQUE, \
                sizeof(uint), \
                (UINT8 *)&s32ReceiveBufSize, \
                0);
    s32ReceiveBufLimit = 2048;
    CfgAddEntry(hCfgIpAddr, \
                CFGTAG_IP, \
                CFGITEM_IP_SOCKTCPRXLIMIT,\
                CFG_ADDMODE_UNIQUE, \
                sizeof(uint), \
                (UINT8 *)&s32ReceiveBufLimit, \
                0);
}
static void SoAd_vInitHTTPConfig(HANDLE hCfgIpAddr)
{
    CI_SERVICE_HTTP  objstrHTTPServiceType;
    /* Specify HTTP service */
    bzero(&objstrHTTPServiceType, sizeof(objstrHTTPServiceType));
    objstrHTTPServiceType.cisargs.IPAddr = INADDR_ANY;
    objstrHTTPServiceType.cisargs.pCbSrv = &SoAd_vNetworkStatusChangeHook;
    objstrHTTPServiceType.cisargs.IfIdx  = 1;
    objstrHTTPServiceType.param.MaxCon   = 3;
    objstrHTTPServiceType.param.Port     = 80;
    CfgAddEntry(hCfgIpAddr, \
                CFGTAG_SERVICE, \
                CFGITEM_SERVICE_HTTP, \
                0,\
                sizeof(objstrHTTPServiceType), \
                (UINT8 *)&objstrHTTPServiceType, \
                0 );
}
static void SoAd_vInitIPConfig(HANDLE hCfgIpAddr)
{
    CI_IPNET         objstrIPNetType;
    CI_ROUTE         objstrRouteType;
    CI_SERVICE_DHCPC objstrDHCPServiceType;
    INT32S           s32StatusReturn;
    IPN              objIPv4Type;
    /* Add our global hostname to hCfg (to be claimed in all connected domains) */
    CfgAddEntry(hCfgIpAddr, \
                CFGTAG_SYSINFO, \
                CFGITEM_DHCP_HOSTNAME, \
                0, \
                strlen(SoAd_objstrDCFGType.objstrIPSettings.s8HostNameArray), \
                (UINT8 *)(SoAd_objstrDCFGType.objstrIPSettings.s8HostNameArray),\
                0 );
    if(SoAd_objstrDCFGType.objstrIPSettings.bDynamicIPv4 == STD_TRUE) /* Dynamic IP address */
    {
        UINT8 DHCP_OPTIONS[] =
                        {
                        DHCPOPT_SUBNET_MASK,
                        };
        /* Specify DHCP Service on IF-1 */
        bzero(&objstrDHCPServiceType, sizeof(objstrDHCPServiceType));
        objstrDHCPServiceType.cisargs.Mode   = CIS_FLG_IFIDXVALID;
        objstrDHCPServiceType.cisargs.IfIdx  = 1;
        objstrDHCPServiceType.cisargs.pCbSrv = &SoAd_vNetworkStatusChangeHook;
        objstrDHCPServiceType.param.pOptions = DHCP_OPTIONS;
        objstrDHCPServiceType.param.len = 1;
        CfgAddEntry(hCfgIpAddr, \
                    CFGTAG_SERVICE, \
                    CFGITEM_SERVICE_DHCPCLIENT, \
                    0,\
                    sizeof(objstrDHCPServiceType), \
                    (UINT8 *)&objstrDHCPServiceType, \
                    0);
        s32StatusReturn = 1;
        CfgAddEntry(hCfgIpAddr, \
                    CFGTAG_IP, \
                    CFGITEM_IP_SOCKTTLDEFAULT,\
                    CFG_ADDMODE_UNIQUE, \
                    sizeof(uint), \
                    (UINT8 *)&s32StatusReturn, \
                    0);
    }
    else /* static IP address */
    {
        /* Setup manual IP address */
        bzero(&objstrIPNetType, sizeof(objstrIPNetType));
        objstrIPNetType.IPAddr  = SoAd_objstrDCFGType.objstrIPSettings.u32LocalIP;
        objstrIPNetType.IPMask  = SoAd_objstrDCFGType.objstrIPSettings.u32SubnetMask;
        strcpy(objstrIPNetType.Domain, SoAd_objstrDCFGType.objstrIPSettings.s8DomainNameArray);
        objstrIPNetType.NetType = 0;
        /* add a new static IP entry */
        CfgAddEntry(hCfgIpAddr, CFGTAG_IPNET, 1, 0,sizeof(CI_IPNET), (UINT8 *)&objstrIPNetType, 0);
        /*  Add the default gateway. Since it is the default, the
        *  destination address and mask are both zero */
        bzero(&objstrRouteType, sizeof(objstrRouteType));
        objstrRouteType.IPDestAddr = 0;
        objstrRouteType.IPDestMask = 0;
        objstrRouteType.IPGateAddr = SoAd_objstrDCFGType.objstrIPSettings.u32GatewayIP;
        CfgAddEntry(hCfgIpAddr, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&objstrRouteType, 0);
        s32StatusReturn = 1;
        CfgAddEntry(hCfgIpAddr, \
                    CFGTAG_IP, \
                    CFGITEM_IP_SOCKTTLDEFAULT,\
                    CFG_ADDMODE_UNIQUE, \
                    sizeof(uint), \
                    (UINT8 *)&s32StatusReturn, \
                    0);
        /* Manually add the DNS server */
        objIPv4Type = SoAd_objstrDCFGType.objstrIPSettings.u32DNS1;
        CfgAddEntry(hCfgIpAddr, \
                    CFGTAG_SYSINFO, \
                    CFGITEM_DHCP_DOMAINNAMESERVER, \
                    0, \
                    sizeof(objIPv4Type), \
                    (UINT8 *)&objIPv4Type, \
                    0);
        objIPv4Type = SoAd_objstrDCFGType.objstrIPSettings.u32DNS2;
        CfgAddEntry(hCfgIpAddr, \
                    CFGTAG_SYSINFO, \
                    CFGITEM_DHCP_DOMAINNAMESERVER, \
                    1, \
                    sizeof(objIPv4Type), \
                    (UINT8 *)&objIPv4Type, \
                    0);
    }
}
  • also please find that attached screen shoot for memory allocation of the program which show that the bss is repeated for unkown reason.

  • Please attach the .cfg (it was not attached) and the linker file.
  • You are still auto-generating the networking thread. If you supply the networking thread, set the following in the .cfg file
    Global.enableCodeGeneration = false;
  • sorry for inconvenience,  the uploaded cfg file wasn't the one used during the testing, so here is the correct file5875.ICG.cfg

  • Ok. Can you attach the mapfile also? Are you simply trying to fit too much in the memory? How close were you when you had the .cfg generate the stack thread instead of you supplying it? Can you include the mapfile for that also?
    Todd
  • please find the attached zip which contains the following:

    1- the map file when i create the stack thread without the fitting problem (with commenting the  NC_SystemOpen(NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT) function). "Own_stack_Creation_no_fitting_problem.map"

    2- the map file when i create the stack thread with the fitting problem (with uncommenting the  NC_SystemOpen(NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT) function). "Own_stack_Creation_fitting_problem.map"

    3- the map file when i the stack thread is created by the GUI  "GUI_stack_Creation.map"

    4- Pic for the memory allocation for first map file "Own_stack_Creation_no_fitting_problem.png"

    5- Pic for the memory allocation for second map file "Own_stack_Creation_fitting_problem.png"

    6- Pic for the memory allocation for third map file" GUI_stack_Creation.png"

    Thanks,

    Mohammed Fawzy

    1586.required file.rar

  • Can you attach your Task create code? Or even better, can you attach your CCS project?

  • Task_Params ConfigurationTaskParameter;
    Task_Handle pConfigurationTaskHandler;

    Task_Params_init(&ConfigurationTaskParameter);
    ConfigurationTaskParameter.stackSize = 1024;
    ConfigurationTaskParameter.priority = 5;
    ConfigurationTaskParameter.instance->name = "SoAd Network Confgiuration Task";
    Error_init(&objstrErrorBlock);
    pConfigurationTaskHandler = Task_create(SoAd_vNetworkConfigurationTask, &ConfigurationTaskParameter, &objstrErrorBlock);
    bErrorStatus = Error_check(&objstrErrorBlock);
    if((pConfigurationTaskHandler == STD_NULL) || (bErrorStatus == STD_TRUE))
    {
    SoAd_vmLogError0(&objstrSoAdModuleInfoType, "Can't create SoAd config Task");
    }
    else
    {
    #if (SoAd_USE_DSM)
    objstrConfigTaskHandlerType.TaskHandler = pConfigurationTaskHandler;
    srOSStatus = DSM_srRegisterTask(&objstrConfigTaskHandlerType);
    if(srOSStatus == E_NOT_OK)
    {
    SoAd_vmLogError0(&objstrSoAdModuleInfoType, "Can't register SoAd config Task");
    }
    #endif
    }

  • Hi Mohamed,

    There is a bug with the NDK. The NDK has internal buffers (see the following for more details on them: processors.wiki.ti.com/.../TI-RTOS_Networking_Stack_Memory_Usage). The pre-built library have these buffers defined. When you have the .cfg generate code NDK code, internal buffers are generated and are used instead of the pre-built libraries ones. Here is an example of the generated ones.

    #ifdef __ti__
    #pragma DATA_ALIGN(ti_ndk_config_Global_pHdrMem, 128);
    #pragma DATA_SECTION(ti_ndk_config_Global_pHdrMem, ".bss:NDK_PACKETMEM");
    UINT8 ti_ndk_config_Global_pHdrMem[PKT_NUM_FRAMEBUF * sizeof(PBM_Pkt)];
    #elif defined (__IAR_SYSTEMS_ICC__)
    #pragma data_alignment = 128
    UINT8 ti_ndk_config_Global_pHdrMem[PKT_NUM_FRAMEBUF*sizeof(PBM_Pkt)];
    #else

    UINT8 ti_ndk_config_Global_pHdrMem[PKT_NUM_FRAMEBUF * sizeof(PBM_Pkt)] __attribute__ ((aligned(128), section(".bss:NDK_PACKETMEM")));
    #endif

    Where PKT_NUM_FRAMEBUF is determined by Global.pktNumFrameBufs in the .cfg (which in your case was 11).

    The NDK libraries for M4F are built with PKT_NUM_FRAMEBUF = 192! For M3 devices, we lower that number to 16. We don't lower the number of M4F devices...this is a bug! So when don't generate the NDK code in the .cfg, you get huge buffers for M4F devices. Note, the first device the NDK ran (15 years old) on was C6xxx which has lots of RAM (1MB and higher).

    The best fix is to change all the following statements in the <TI-RTOS install dir>\products\<ndk install dir>\packages\ti\ndk\stack\package.bld file

    if (target.name == "M3") {

    to

    if ((target.name == "M3") || (target.name == "M4F")) {

    and then rebuild the NDK (refer to the TI-RTOS User Guide). Now rebuild your application. The .bss should be much smaller now and fit into RAM.

    I've opened a defect report on this

    SDOCM00119490: NDK needs to use smaller numbers for M4F like it does for M3.

    Todd

  • Hello Tod,

    actually i did the following steps but i'm still getting the same problem:

    1- replaced every if (target.name == "M3") { to if ((target.name == "M3") || (target.name == "M4F")) { in the file 

    "C:\ti\tirtos_tivac_2_14_00_10\products\ndk_2_24_03_35\packages\ti\ndk\stack\package.bld"

    2- clean the NDK using the following command

    C:\ti\xdctools_3_31_02_38_core>gmake -f C:\ti\tirtos_tivac_2_14_00_10\tirtos.mak clean-ndk

    3- rebuild the NDK using the following command

    C:\ti\xdctools_3_31_02_38_core>gmake -f C:\ti\tirtos_tivac_2_14_00_10\tirtos.mak ndk

    4- clean my project

    5- rebuild my project

    So did i miss something?

    Thanks,

    Mohammed Fawzy

  • The check is missing for IPv6 in the package.bld file.

    Add the following bolded lines and rebuild the NDK again. This should fix it.

        /*
         * stk6.lib
         */
        var libName = "stk6";
        var libOptions = {
                copts: "-D_NDK_EXTERN_CONFIG -D_INCLUDE_NIMU_CODE " +
                       "-D_INCLUDE_IPv6_CODE",
                incs: ndkPathInclude,
        };

        if ((target.name == "M3") || (target.name == "M4F")) {
            libOptions.copts += m3PbmCopts;
        }
       
        var lib = Pkg.addLibrary("lib/" + libName, target, libOptions);
        lib.addObjects(coreLibFiles);

    Sorry I missed this. Your project took so long to build, I testing it on a smaller IPv4 example.

    Todd

  • Thank you Tod, now my code can fit the memory but i have a small problem which is related to the memory management in the NDK, such that i need to control NDK_MMBUFFER or in other meaning the page size/number of pages, how can i do it after disable the GUI code generation?

    but the most important thing for the time being that any trial to create a socket will fail and will return -1, so please advise.

  • Can you start a new thread on this issue?

    Todd