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.

RTOS/TM4C129XNCZAD: Getting time server information

Part Number: TM4C129XNCZAD

Tool/software: TI-RTOS

So... just can't leave well enough alone.

I now have my device acquiring it's IP and domain from DHCP.

I need to implement a SNTP client on this machine, in order to get the correct time.

Is there any way I can get the IP of the SNTP server that was provided by DHCP?

It's provided as entry #4, but not sure how to retrieve it, or if I can.

PS: Somehow, the headings on this page got set to only show Chinese.  How do I change them back, or can I?

  • Hi David,

    An engineer has been assigned to answer the SNTP question. Regarding the Chinese characters...can you attach a snapshot of this.

    Todd
  • David,

    Sorry for the delay. I have been working up a test bench to investigate the issue. I will keep you posted.

    ~Ramsey

  •  At least some of the labels have corrected themselves.  When I wrote the question, the "+ Ask a related question" and "+Ask a new question" were Chinese characters.  Also, when I brought up a page to edit, all the text was Chinese.  If I hadn't known what the buttons meant, I'd have been lost.

    Now, I just have Chinese characters over in the upper right corner.

  • David,

    I finally have a reply for you, but it is not a simple one.

    To acquire the NTP Server address from the DHCP server, requires the following three steps:

    1. Request the NTP Server address using DHCP option
    2. Parse the DHCP response and extract the option reply
    3. Wait for the NDK IP address hook, then fetch the NTP address

    Step one is a configuration setting you would make to enable the DHCP option. Step 2 would be handled by the NDK stack thread. You would take care of step three by invoking an NDK API to retrieve the NTP server address.

    Unfortunately, we have discovered a bug in the NDK regarding step one; the NDK does not implement step 2; and there is no API to support step three. But if you are so inclined, I can offer a work around for you.

    Step 1. Request the NTP Server address from the DHCP server

    There are two options which relate to time servers. I'm not sure which one you want. If needed, you can refer to RFC2132 to figure out which one you want.

    The normal way to enable these options, is to add one of the following to your application configuration script.

    Time Server Option (RFC code #4)

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

    Network Time Protocol Servers Option (RFC code #42)

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

    Please note the name above is mis-spelled; it should be NTP instead of NIS. But we must use it as defined.

    However, due to a bug in the NDK, this will not work. As an alternative, you can enable the option by setting its default bit in the DHCPTypeCode array defined in the NDK. Edit the following file:

    /ti/ndk/nettools/dhcp/dhcptag.c

    Add the flag FLG_DEFAULT to the option. This will enable the option by default, and it will be included in the DHCP Discover packet. For example, to enable the NTP Server option, modify option 42 as follows:

    4 | FLG_ISADDRESS | FLG_DEFAULT, /* 42 - NIS time protocol servers */

    You will need to rebuild the NDK libraries for this change to take effect (see below).

    Step 2. Parse the DHCP response and extract the option reply

    When the NDK receives the DHCP reponse, the packet is parsed in the function dhcpVerifyMessage(). This function already handles two options, but not the time server option. You can add the following case statement which will parse the NTP Server option. I've stored the value of the first IP address in a global variable, so you can access it later. Note that this option might return a list of server addresses. I'm only saving the first one. You would need to modify the code to save the entire list. Edit the following file:

    /ti/ndk/nettools/dhcp/dhcppkt.c

    Define a global variable just before the dhcpVerifyMessage() function:

    IPN NDK_NTPServer = 0;

    Add the following case statement in the dhcpVerifyMessage() function.

    case DHCPOPT_NIS_TIME_PROTOCOL_SERVERS:
        TagLength = *pv++;
        if( TagLength == 4 )
            bcopy( pv, &NDK_NTPServer, 4 );
        pv += TagLength;
        BufferSize -= TagLength+2;
        break;

    You will need to rebuild the NDK libraries for this change to take effect.

    3. Wait for the NDK IP address hook, then fetch the NTP address

    The DHCP server would send you the NTP server address in the response packet. So, the NDK IP address hook would be a good place to fetch it.

    extern IPN NDK_NTPServer;

    void netAddrHook(uint32_t addr, uint32_t IfIdx, uint32_t fAdd)
    {
        char IPString[50];

        NtIPN2Str(NDK_NTPServer, IPString);
        System_printf("NTP Server: %s\n", IPString);
    }

    To rebuild the NDK libraries, please use the instruction on the following link:

    The NDK product ships in your TI-RTOS TivaC installation. You can find it in the products folder:

    /tirtos_tivac_2_16_01_14/products/ndk_2_25_00_09

    Let me know if you have any questions.

    ~Ramsey

    PS. Regarding the Chinese font on the forums. The button in the upper right hand corner takes you to the China web site. If you go there by mistake, the same button returns you to the US web site. Maybe you went the by accident.

  • I've been pulled off for another project for a moment. As soon as I can, I'll implement this change, and see if it provides the solution I need. DHCP Option 4 is what I'm looking for I believe, and I'll instantiate the ntpd daemon provided once that's available.

    For now, this is resolved