API to correlate system time with external time sources #28977
This PR has content I've been working on for about six months, to locally timestamp sensor observations with standard time rather than time-since boot.
It provides data structures to capture a timestamp in two different clocks, monitor the drift between those clocks, and using a base instant with estimated drift convert between the clocks. This provides the core technology to convert between system uptime and an external continuous time scale like TAI (UTC without applying leap seconds).
A sample is provided that demonstrates using this technology to measure local clock error between Nordic HFCLK and LFCLK.
There are some questions in the first comment that need to be resolved. There are also some follow-on commits that will be submitted separately after this seems to be going forward:
Some notes on the design, with a few questions that should be answered before it's ready to merge:
What is this?
There's already a
It then adds API under
The API does not automatically do time maintenance. Something has to invoke
Why isn't this
@pabigot Would it be feasible to drop the
I tried that. The dynamic range due to the need to translate between different frequencies causes problems even with 64-bit integer math. There are overflows and underflows during the intermediate calculation that makes the skew estimate horribly unstable even when the clocks are stable.
This ties to #29569 in that while this is proposed to be in