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.

DHCP

Hi,

How to find the variable which holds the IP address assigned by DHCP server in auto generated code?

Thank you

  • When the IP address is received from the DHCP server, and then bound in the stack, a hook function is called (the same hook is also called when an IP address is removed, too, so you must handle that when implementing the hook).

    You can configure your app to have it call such a hook function.  So, you would defined the hook function and within it, you can save the IP address.

    The hook function is configured in the application *.cfg file.  Please see screen shot below.

    Steve

  • Hi Steve,

    Thanks for your reply.
    I have one more issue, I am trying to enable/disable static ip and dynamic ip at run time. What are the settings I need to make in xconfig window. I want to write my own NDK stack thread , where I need to assign my function ? I searched in TI forum I found below information
    1. Global.stackThreadUser = "&userNdkStackThread"
    Here I'm not able to find "stackThreadUser" in Global structure.

    I found it in thislink
    e2e.ti.com/.../1567909.

    static or dynamic selection will be decided at the run time and user input will decide it.

    Please help me to solve this

    Thank you
    Apoorva
  • Hi Apoorva,

    1. Global.stackThreadUser = "&userNdkStackThread"
    Here I'm not able to find "stackThreadUser" in Global structure.

    This option is somewhat hidden.  You should be able to find it in the "advanced view":

    static or dynamic selection will be decided at the run time and user input will decide it.

    You can't really do this with the XGCONF config (well, part of it you can).  But, you need to handle most of this in C code.  But, you can use the XGCONF tool to create the C code that you need to do this.

    I would suggest the following:

    1. Open a new project in CCS. You should import an NDK application, preferably.  If not, create one from scratch and then use XGCONF to bring in the NDK.

    2. Make sure the Ip settings are set for DHCP client ("obtain IP address automatically" is checked).

    3. Build the project.

    4. The settings of your XGCONF config will generate C code in a file that's named with the format "<application name>_<target>.c". This file can be found in the Debug or Release subfolder of your project and is named using your project name and hardware platform. For example, for the NDK Hello World example on the 'C6748, the generated file is generated at Debug\configPkg\package\cfg\helloWorld_pe674.c. You should see a similarly named C file in an
    NDK project that has been built.

    5. Open the "<application name>_<target>.c" that was just described.

    6. Look for the C code that configures the application to run as a DHCP client.  It should be in the function ti_ndk_config_ip_init().  Copy that code and save it in a different file.  This is the code you will need to use when the user input says "use DHCP"

    7. Come back to XGCONF.  In the IP settings, uncheck the box to auto obtain the IP address, and then enter a static IP address, mask, etc.  These values don't really matter, as you will need to replace them in the code.

    8. Build the project and reload/reopen the "<application name>_<target>.c".  Again, find the ti_ndk_config_ip_init() function.

    9. The file (and function) has been re-generated based on the settings of your *.cfg file.  Now the C code is for adding a static IP.  Copy this code and save it to a different file.

    10. In addition to that code, you need to also search the file for the following, for example.  These variable are used in the config C code described in the previous step:

    /* Static IP Address settings */
    char *LocalIPAddr = "192.168.1.2";     // set this to the user's input
    char *LocalIPMask = "255.255.2.2";   // set this to the user's input
    char *GatewayIP   = "1.1.1.1";            // set this to the user's input
    char *DomainName  = "demo.net";     // set this to the user's input

    11. Copy and save that code into the file you saved in step 9. 

    12. You now have the C configuration code for adding a static IP address, and for configuring the NDK to run as a DHCP client.  You are now done with this temporary application/example.

    13. Come back to your original application.  Set the NDK to configure no IP address.  In the IP settings of XGCONF, enter "none" for the IP address (must uncheck the checkbox for DHCP).  This causes the NDK to come up without configuring any IP - static nor dynamic.

    At this point, you can run your application.  The stack will start up, but no IP address will be set.  At this point you can wait for user input.  When the user enters "run as DHCP client", you need to run the C code you got in step 6.  When they enter a static IP, mask, gateway, etc., you need to run the C code you found in step 9.

    Steve

  • Hi Steve,

    I could not able to find stackThreadUser . I am using NDK version 2.23.01.01.

    I tried adding Global.stackThreadUser explicitly to .cfg file , but it is showing an error.

    Thanks

    Apoorva

  • Apoorva,

    That feature didn't yet exist in that NDK.  You need to upgrade to the latest NDK.

    Please get it from this link.

    Steve

  • Hi Steve,

    How to update this NDK file to main TI folder?

    Thanks

    Apoorva

  • Apoorva,

    Follow these steps:

    Download the NDK as a zipped archive from TI's Embedded Software

    Download Page (link I gave you above).

    Unzip the downloaded file (on Windows or Linux) in the directory where you installed

    Code Composer Studio (CCS). For example, if you unzip the downloaded NDK file in the c:\ti directory on

    Windows, the <NDK_INSTALL_DIR> will be c:\ti\ndk_#_##_##_##, where # is a digit in the version

    number.

    After you install the NDK, start CCS. You will be notified that CCS found one or more products and asked

    if you want to use them. You will need to restart CCS in order to make new products available within CCS.

    Right click on your project in CCS and open the build options.  Make sure the version of the NDK you installed is selected:

    In the same properties view, select the "Order" tab.  Use the "Up" button to make sure that "NDK_INSTALL_DIR" is above the "COM_TI_RTSC_TIRTOS..." variable in the list:

    Steve