[ntp:hackers] NTP - fraction part to nanoseconds on memory constrained systems

Josef Lusticky xlusti00 at stud.fit.vutbr.cz
Sun Aug 12 11:02:34 UTC 2012


Dear NTP community,
I've been working on a Simple NTP client for embedded systems past
months and I met a problem with required code size in order to compute
exact timestamp conversion:
- FP operations on systems without FPU are extremely memory expensive
  and may be not accurate
- 64 bit multiplication is 100% accurate, but on 8-bit MCU the routine
  supplied by the compiler still takes a lot of memory (1KB on AVR)

Therefore I created a shift-and-add version of the conversion, that
computes (ntp * 10^9 / 2^32) on 32 bits with a maximum error of 5ns.
My conversion requires no routines and uses 300B of code on an 8-bit AVR
platform.

I am attaching the code to this e-mail and the thesis in which I
describe the algorithm can be obtained at
http://dl.dropbox.com/u/66930188/projekt.pdf - page 26 and 33 -
and the source code of the whole client for Contiki OS at
http://dl.dropbox.com/u/66930188/contiki-ntp-fit.zip

I though this could be handy for someone developing an NTP client in
a memory constrained environment.

Kind regards,
Josef Lusticky


More information about the hackers mailing list