Set User Timebase

This topic provides details on how to set the user timebase along with some overview info.

Usually, the automated time daemon handles time synchronization, but that may not always be desirable.

See User Timebase API reference docs


You never directly modify the RTC. Instead, the user timebase is stored (internally) as an offset from the RTC (plus/minus) so it's synchronized with the system clock.

This is how time synchronization works in Legato:

le_rtc.png

Overview

The modem manages a real time clock (battery backed clock VCOIN) that keeps time when the power is removed from the Legato module (if clock battery available). This clock is used by the modem to maintain several timebases derived from different domains (e.g., cellular or GPS). Apps shouldn't directly change the value of the real time clock as it may have undesirable effects on modem function.

The user timebase is provided to synchronize with the RTC.

GPS and Unix Time

The RTC counts milliseconds since the GPS Epoch, which is Jan 6, 1980; it increments on each count so that each second in GPS time has a unique number.

Unix time starts Jan 1, 1970 and has a fixed number of seconds per day. For days with an extra second in them (i.e., leap second) Unix uses the same second twice. This means that over the years an increasing number of leap seconds have to be accounted for when converting time between GPS and Unix domains. But the rate of drift is low: only 26 leap seconds added since they were introduced in 1972. It's impossible to predict in which years leap seconds will need to be added; the calculation must be done retroactively.

Under normal conditions, the time will be corrected from an external source (e.g., network time or GPS). If you are synchronizing with cellular network time only, the time-service daemon automatically provides this: call le_clk_GetAbsoluteTime() or linux 'date' command.

For most purposes, it's not necessary to convert time to real GPS time; it will suffice to use Unix epoch time.

The time stored is incremented by the millisecond and Unix time is incremented by the second. This means an arbitrary time stored needs to increment on a millisecond basis to be retrieved later (assuming a battery VCOIN keeps the RTC running).

When storing Unix time in the user time base, it must be multiplied by 1000 and divided by 1000 when retrieved.

Get/Set User Timebase

If you need to set the user timebase, you need to:

See User Timebase and System Clock API reference docs for complete API details.