This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 5eb573b827c92e1978efa6bb406d40304b008bac Author: zhuliang5 <[email protected]> AuthorDate: Fri Jul 3 18:11:07 2026 +0800 netutils/ptpd: step the clock on the first sync sample. The local clock was only stepped when the offset exceeded CONFIG_NETUTILS_PTPD_SETTIME_THRESHOLD_MS. A smaller initial offset was slewed instead, which takes a long time to converge after boot. Always set the clock from the first sample, then slew as before. The "initialized" flag lives in struct ptp_state_s, so every ptpd instance, including one restarted after ptpd_stop(), steps its clock again. Signed-off-by: zhuliang5 <[email protected]> Assisted-by: Kiro:claude-opus-4 --- netutils/ptpd/ptpd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netutils/ptpd/ptpd.c b/netutils/ptpd/ptpd.c index 44ab05f99..2740cafe0 100644 --- a/netutils/ptpd/ptpd.c +++ b/netutils/ptpd/ptpd.c @@ -158,6 +158,7 @@ struct ptp_state_s int64_t last_adjtime_ns; long drift_avg_total_ms; long drift_ppb; + bool clock_initialized; /* Clock set from the first sample */ bool has_last_delta; #if CONFIG_NETUTILS_PTPD_OUTLIER_THRESHOLD_NS > 0 int64_t delta_hist[PTP_OUTLIER_HISTORY]; @@ -1588,14 +1589,15 @@ static int ptp_update_local_clock(FAR struct ptp_state_s *state, delta_ns += state->path_delay_ns; absdelta_ns = (delta_ns < 0) ? -delta_ns : delta_ns; - if (absdelta_ns > adj_limit_ns) + if (absdelta_ns > adj_limit_ns || !state->clock_initialized) { - /* Large difference, move by jumping. + /* First call or large difference, move by jumping. * Account for delay since packet was received. */ struct timespec new_time; + state->clock_initialized = true; ptp_gettime(state, &new_time); clock_timespec_subtract(&new_time, local_timestamp, &new_time); clock_timespec_add(&new_time, remote_timestamp, &new_time);
