adding APTS to participate in BMCA

Passing the announce message for external source to ptp4l using virtual
port to avoid selection of master from PTP source.

Signed-off-by: Greg Armstrong <greg.armstrong...@renesas.com>
Signed-off-by: Leon Goldin <leon.goldin...@renesas.com>
Signed-off-by: Vipin Sharma <vipin.sha...@syncmonk.net>
Signed-off-by: Devasish Dey <devasish....@syncmonk.net>
---
 ts2phc_phc_pps_source.c | 16 ++++++++++++++++
 ts2phc_phc_pps_source.h |  2 ++
 ts2phc_pps_sink.c       |  6 +++++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/ts2phc_phc_pps_source.c b/ts2phc_phc_pps_source.c
index 5f15e8e..fa9d286 100644
--- a/ts2phc_phc_pps_source.c
+++ b/ts2phc_phc_pps_source.c
@@ -14,10 +14,12 @@
 #include "print.h"
 #include "ts2phc_phc_pps_source.h"
 #include "ts2phc_pps_source_private.h"
+#include "ts2phc_vport.h"
 #include "util.h"
 
 struct ts2phc_phc_pps_source {
        struct ts2phc_pps_source pps_source;
+       struct ts2phc_vport *vport;
        clockid_t clkid;
        int channel;
        int fd;
@@ -82,6 +84,15 @@ static int ts2phc_phc_pps_source_getppstime(struct 
ts2phc_pps_source *src,
        return clock_gettime(s->clkid, ts);
 }
 
+int ts2phc_phc_pps_source_vport_transmit(struct ts2phc_pps_source *src,
+                                       struct timespec *ts)
+{
+       struct ts2phc_phc_pps_source *s =
+               container_of(src, struct ts2phc_phc_pps_source, pps_source);
+       return ts2phc_vport_tx_announce(s->vport);
+}
+
+
 struct ts2phc_pps_source *ts2phc_phc_pps_source_create(struct config *cfg,
                                                       const char *dev)
 {
@@ -94,6 +105,11 @@ struct ts2phc_pps_source 
*ts2phc_phc_pps_source_create(struct config *cfg,
        }
        s->pps_source.destroy = ts2phc_phc_pps_source_destroy;
        s->pps_source.getppstime = ts2phc_phc_pps_source_getppstime;
+       s->vport = ts2phc_vport_create(cfg);
+       if (!s->vport) {
+               free(s);
+               return NULL;
+       }
 
        s->clkid = posix_clock_open(dev, &junk);
        if (s->clkid == CLOCK_INVALID) {
diff --git a/ts2phc_phc_pps_source.h b/ts2phc_phc_pps_source.h
index c9ab54e..01c1d8d 100644
--- a/ts2phc_phc_pps_source.h
+++ b/ts2phc_phc_pps_source.h
@@ -11,4 +11,6 @@
 struct ts2phc_pps_source *ts2phc_phc_pps_source_create(struct config *cfg,
                                                       const char *dev);
 
+int ts2phc_phc_pps_source_vport_transmit(struct ts2phc_pps_source *src,
+                                        struct timespec *ts);
 #endif
diff --git a/ts2phc_pps_sink.c b/ts2phc_pps_sink.c
index 91bd7c9..6e6acc0 100644
--- a/ts2phc_pps_sink.c
+++ b/ts2phc_pps_sink.c
@@ -23,6 +23,7 @@
 #include "servo.h"
 #include "ts2phc_pps_sink.h"
 #include "ts2phc_pps_source.h"
+#include "ts2phc_phc_pps_source.h"
 #include "util.h"
 
 #define NS_PER_SEC             1000000000LL
@@ -426,7 +427,10 @@ int ts2phc_pps_sink_poll(struct ts2phc_pps_source *src)
 
        err = ts2phc_pps_source_getppstime(src, &source_ts.ts);
        source_ts.valid = err ? false : true;
-
+       if (source_ts.valid) {
+               /* Send Announce and Sync Message on Virtual Port  */
+               ts2phc_phc_pps_source_vport_transmit(src, &source_ts.ts);
+       }
        for (i = 0; i < ts2phc_n_sinks; i++) {
                if (polling_array.pfd[i].revents & (POLLIN|POLLPRI)) {
                        ts2phc_pps_sink_event(polling_array.sink[i], source_ts);
-- 
2.25.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to