Skip to content

Commit

Permalink
ts2phc: Move upper/lower rejection limit calculation.
Browse files Browse the repository at this point in the history
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 <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
  • Loading branch information
mlichvar authored and richardcochran committed Jul 28, 2024
1 parent 0011504 commit 6967e52
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ts2phc_pps_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6967e52

Please sign in to comment.