NTP

Till Straumann strauman at slac.stanford.edu
Wed Oct 13 15:49:48 UTC 2010


On 10/12/2010 10:09 AM, Martin Grim wrote:
> Hi,
>
> Did someone mange to get updated date/time via NTP in its target? If
> so, how?

1) make sure networking is properly configured and initialized (at least
    one NTP server must be configured and be reachable (e.g., via a
    gateway).

2) call rtems_bsdnet_synchronize_ntp(0,0). This will fetch NTP time
    and force an immediate update of the system clock.

    If you want something more sophisticated then you can use the
    rtems_bsdnet_get_ntp() routine and supply your own callback routine
    (or just use it to fetch NTP time:

     struct timespec ntp_now;

     status = rtems_bsdnet_ntp_get( -1, 0, &ntp_now );

    If you repeatedly use rtems_bsdnet_ntp_get() then you may create
    (and bind etc.) your own socket and supply it instead of the '-1'
    argument since '-1' instructs the routine to create and setup a
    socket on the fly and then destroy it again before returning.
    You can avoid this overhead by supplying (and reusing) your own
    socket.


Note that rtems_bsdnet_synchronize() is not very sophisticated. It would
be desirable to have the kernel clock run D. Mills' algorithm and use
a proper NTP daemon to discipline this kernel clock. This would yield
a well synchronized and continuous system time.

Since I didn't want to mess with the kernel clock internals I have
ported the Mills clock to RTEMS and created a very simple ntp daemon.
However, this clock is running separately from the system wall-clock
and can/must be read through a dedicated API (ntp_gettime()).

The code is available here (look for 'ntpNanoclock'):

http://www.slac.stanford.edu/~strauman/rtems/software.html

HTH
-- Till

>
> I've set the ntp servers in the rtems_bsc_config structure and I call
> the rtems_bsdnet_synchronize_ntp function somewhere in the beginning
> of my app, but to no avail. I get either a "no more processes"
> (EAGAIN) or a "host not reachable" out of the rtems_bsdnet_get_ntp()
> function.
>
> Any clues what I might be doing wrong?
>
> Regards,
>
> Martin
>




More information about the users mailing list