lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] [OT] Sync local time to NTP


From: Giuseppe Modugno
Subject: [lwip-users] [OT] Sync local time to NTP
Date: Fri, 30 Dec 2022 17:10:56 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1

The typical scenario of lwip is an embedded platform. When a wall clock is needed and the device is network connected, NTP is usually used to retrieve automatically the correct time at startup and stay in sync with an accurate reference (in other cases, the user can set a time as he wants).

Consider an embedded device without a battery. At startup there's no notion of current time, so we can start from an epoch (1970, 2020 or whatever) and consider it the correct time. Another approach is considering the time not initialized at all.

lwip has a SNTP client implementation that magically calls a function SNTP_SET_SYSTEM_TIME_NTP(s, f) when a response from a SNTP server is received. Now the question is what to do with s, seconds from 1970 epoch (ignore fractional part, just to simplify).

One possibility is to have a system counter clocked at 1s that counts seconds from 1970. So SNTP_SET_SYSTEM_TIME_NTP() could simply overwrite the counter value. However this simple approach brings to a counter that isn't monotonic and continuous. I know the best approach is to slowed down or accelerate the reference clock of the system counter that tracks seconds from epoch.

Do you really implement something similar or are you happy with replacing the counter with the new value reported by NTP?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]