Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ts2phc.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ static void ts2phc_synchronize_clocks(struct ts2phc_private *priv, int autocfg)
double adj;
tmv_t ts;

if (c->clkid == CLOCK_REALTIME) {
struct timespec real_time_ts;
if (clock_gettime(CLOCK_REALTIME, &real_time_ts) == -1) {
return;
}
c->last_ts.ns = tmv_to_nanoseconds(timespec_to_tmv(real_time_ts));
c->is_ts_available = true;
c->is_target = true;
}

if (!c->is_target)
continue;

Expand Down Expand Up @@ -813,7 +823,7 @@ int main(int argc, char *argv[])
pr_err("poll failed");
break;
}
if (err > 0) {
if (err >= 0) {
err = ts2phc_collect_pps_source_tstamp(&priv);
if (err) {
pr_err("failed to collect PPS source tstamp");
Expand Down
9 changes: 9 additions & 0 deletions ts2phc_pps_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ static struct ts2phc_pps_sink *ts2phc_pps_sink_create(struct ts2phc_private *pri
pr_debug("PPS sink %s has ptp index %d", device,
sink->clock->phc_index);

if (sink->clock->clkid == CLOCK_REALTIME)
return sink;

if (phc_number_pins(sink->clock->clkid) > 0) {
err = phc_pin_setfunc(sink->clock->clkid, &sink->pin_desc);
if (err < 0) {
Expand Down Expand Up @@ -228,12 +231,16 @@ static void ts2phc_pps_sink_destroy(struct ts2phc_pps_sink *sink)
{
struct ptp_extts_request extts;

if (sink->clock->clkid == CLOCK_REALTIME)
goto destroy;

memset(&extts, 0, sizeof(extts));
extts.index = sink->pin_desc.chan;
extts.flags = 0;
if (ioctl(sink->clock->fd, PTP_EXTTS_REQUEST2, &extts)) {
pr_err(PTP_EXTTS_REQUEST_FAILED);
}
destroy:
ts2phc_clock_destroy(sink->clock);
free(sink->name);
free(sink);
Expand Down Expand Up @@ -343,6 +350,8 @@ int ts2phc_pps_sink_arm(struct ts2phc_private *priv)
memset(&extts, 0, sizeof(extts));

STAILQ_FOREACH(sink, &priv->sinks, list) {
if (sink->clock->clkid == CLOCK_REALTIME)
continue;
extts.index = sink->pin_desc.chan;
extts.flags = sink->polarity | PTP_ENABLE_FEATURE;
err = ioctl(sink->clock->fd, PTP_EXTTS_REQUEST2, &extts);
Expand Down