From 6967e52d659e9f001e4648826afa1e3021f4580b Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 3 Jun 2024 16:43:52 +0200 Subject: [PATCH] ts2phc: Move upper/lower rejection limit calculation. The ignore_upper and ignore_lower fields of the ts2phc_pps_sink struct are calculated when the PPS source is not known yet. Replace the fields with the configured pulsewidth and calculate the limits locally later when needed in ts2phc_pps_sink_ignore(). This will allow an NMEA-specific calculation of the limits. Signed-off-by: Miroslav Lichvar Reviewed-by: Jacob Keller --- ts2phc_pps_sink.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ts2phc_pps_sink.c b/ts2phc_pps_sink.c index 33df9683..be3bd9a1 100644 --- a/ts2phc_pps_sink.c +++ b/ts2phc_pps_sink.c @@ -30,8 +30,7 @@ struct ts2phc_pps_sink { struct ptp_pin_desc pin_desc; unsigned int polarity; tmv_t correction; - uint32_t ignore_lower; - uint32_t ignore_upper; + uint32_t pulsewidth; struct ts2phc_clock *clock; }; @@ -153,8 +152,8 @@ static struct ts2phc_pps_sink *ts2phc_pps_sink_create(struct ts2phc_private *pri struct config *cfg = priv->cfg; struct ptp_extts_request extts; struct ts2phc_pps_sink *sink; - int err, pulsewidth; int32_t correction; + int err; sink = calloc(1, sizeof(*sink)); if (!sink) { @@ -174,12 +173,9 @@ static struct ts2phc_pps_sink *ts2phc_pps_sink_create(struct ts2phc_private *pri correction = config_get_int(cfg, device, "ts2phc.extts_correction"); sink->correction = nanoseconds_to_tmv(correction); - pulsewidth = config_get_int(cfg, device, "ts2phc.pulsewidth"); - if (pulsewidth > 500000000) - pulsewidth = 1000000000 - pulsewidth; - pulsewidth /= 2; - sink->ignore_upper = 1000000000 - pulsewidth; - sink->ignore_lower = pulsewidth; + sink->pulsewidth = config_get_int(cfg, device, "ts2phc.pulsewidth"); + if (sink->pulsewidth > 500000000) + sink->pulsewidth = 1000000000 - sink->pulsewidth; sink->clock = ts2phc_clock_add(priv, device); if (!sink->clock) { @@ -248,12 +244,16 @@ static bool ts2phc_pps_sink_ignore(struct ts2phc_private *priv, struct timespec source_ts) { tmv_t source_tmv = timespec_to_tmv(source_ts); + uint32_t ignore_lower, ignore_upper; source_tmv = tmv_sub(source_tmv, priv->perout_phase); source_ts = tmv_to_timespec(source_tmv); - return source_ts.tv_nsec > sink->ignore_lower && - source_ts.tv_nsec < sink->ignore_upper; + ignore_upper = 1000000000 - sink->pulsewidth / 2; + ignore_lower = sink->pulsewidth / 2; + + return source_ts.tv_nsec > ignore_lower && + source_ts.tv_nsec < ignore_upper; } static enum extts_result ts2phc_pps_sink_event(struct ts2phc_private *priv,