Hello, Michal,

You might want to take a look at PTP (Precision Time Protocol)
        https://en.wikipedia.org/wiki/PTPd <https://en.wikipedia.org/wiki/PTPd>

and PTPd, a BSD-licensed implementation:
        https://github.com/ptpd/ptpd <https://github.com/ptpd/ptpd>

PTP is designed to sync the system clock to IEEE 1588 time.  This is overkill 
for what you’ve requested, but you could strip out the 1588 code, and use the 
shell to interface with the RTC.

Best regards,
-david



> On Mar 20, 2023, at 3:20 PM, Michal Lenc <michall...@seznam.cz> wrote:
> 
> Hello all,
> 
> 
> 
> NuttX offers a function clock_synchronize() that synchronizes system clock
> with clock from RTC (internal or external). The synchronization is done 
> during board initialization and I suppose this can also be called from an 
> application level if required. However I was not able to find any
> implementation that would automatically synchronize system time with
> (correct) values from RTC if system clock drifts from real time. It seems 
> the only possible option is to "force" the synchronization by calling the 
> mentioned clock_synchronize() function periodically from application level.
> 
> 
> 
> 
> What is your view on adding some sort of automatic synchronization that 
> would ensure system clock stays in sync with RTC (or at least error is less
> than some value) even when i drifts away from "real time"? Quite simple 
> solution is to let clock_gettime() to update base time after N reads however
> this would add some computation complexity to gettime (I2C communication 
> delay for external RTC etc.) and I am not sure if we really want this inside
>  clock_gettime().
> 
> 
> 
> 
> Best regards,
> Michal Lenc

Reply via email to