Skip to content

Commit

Permalink
ts2phc: Allow longer NMEA delays.
Browse files Browse the repository at this point in the history
Timestamps from PPS sources are rounded to the nearest pulse, i.e. for
correct synchronization the offset between the source timestamp and
external PPS event timestamp needs to be between -0.5 and +0.5 seconds.
For the pulse edge rejection to work correctly it needs to be even
smaller, between -pulsewidth/2 and +pulsewidth/2.

With the NMEA PPS source the offset is the delay in the reception of the
RMC message. This message is not expected to come exactly on time with
the corresponding pulse. A positive delay is expected, typically at
least few tens of milliseconds, but some receivers have delays longer
than 0.5 seconds.

Add NMEA-specific rounding of the offset to not expect negative delays
and allow positive delays of up to 1 second, or whole pulsewidth if the
edge rejection is enabled.

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 6967e52 commit c6e5766
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ts2phc.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,16 @@ static int ts2phc_pps_source_implicit_tstamp(struct ts2phc_private *priv,
* deduce the timestamp (actually only seconds part, nanoseconds are by
* construction zero) of this edge at the emitter based on the
* emitter's current time.
*
* With an NMEA source assume its messages always follow the pulse, i.e.
* assign the timestamp to the previous pulse instead of nearest pulse.
*/
if (source_ts.tv_nsec > NS_PER_SEC / 2)
if (ts2phc_pps_source_get_type(priv->src) == TS2PHC_PPS_SOURCE_NMEA) {
source_ts.tv_sec++;
} else {
if (source_ts.tv_nsec > NS_PER_SEC / 2)
source_ts.tv_sec++;
}
source_ts.tv_nsec = 0;

tmv = timespec_to_tmv(source_ts);
Expand Down
9 changes: 7 additions & 2 deletions ts2phc_pps_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,13 @@ static bool ts2phc_pps_sink_ignore(struct ts2phc_private *priv,
source_tmv = tmv_sub(source_tmv, priv->perout_phase);
source_ts = tmv_to_timespec(source_tmv);

ignore_upper = 1000000000 - sink->pulsewidth / 2;
ignore_lower = sink->pulsewidth / 2;
if (ts2phc_pps_source_get_type(priv->src) == TS2PHC_PPS_SOURCE_NMEA) {
ignore_upper = sink->pulsewidth;
ignore_lower = 0;
} else {
ignore_upper = 1000000000 - sink->pulsewidth / 2;
ignore_lower = sink->pulsewidth / 2;
}

return source_ts.tv_nsec > ignore_lower &&
source_ts.tv_nsec < ignore_upper;
Expand Down

0 comments on commit c6e5766

Please sign in to comment.