Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Mar 1999 14:58:01 +0200 (SAT)
From:      John Hay <jhay@mikom.csir.co.za>
To:        phk@critter.freebsd.dk (Poul-Henning Kamp)
Cc:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/sys timepps.h src/sys/i386/isa sio.c
Message-ID:  <199903301258.OAA23930@zibbi.mikom.csir.co.za>
In-Reply-To: <23520.922786178@critter.freebsd.dk> from Poul-Henning Kamp at "Mar 30, 1999 11:29:38 am"

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> >  Modified files:
> >    sys/i386/isa         sio.c 
> >  Log:
> >  Add PPS-API support for DCD on serial ports.
> 
...
> 
> Now we just need somebody to write a ntpd refclock module which
> will grok the PPSAPI interface, any takers ?

Here is what I have been using so far. It is probably not perfect, but
it works for me. It only work on the assert edge and it will always
enable hardpps(). It should work for any refclock that use the
refclock_gtlin() function. I have used it with the NMEA driver.
You just need to add a "pps /dev/yourdevice" in your ntp.conf file.

John
-- 
John Hay -- John.Hay@mikom.csir.co.za


--- ntpd/ntp_refclock.c.orig	Wed Feb 17 07:16:29 1999
+++ ntpd/ntp_refclock.c	Sun Mar 28 10:29:30 1999
@@ -28,6 +28,10 @@
 #include <sys/ppsclock.h>
 #endif /* PPS */
 
+#ifdef HAVE_PPSAPI
+#include <sys/timepps.h>
+#endif /* HAVE_PPSAPI */
+
 /*
  * Reference clock support is provided here by maintaining the fiction
  * that the clock is actually a peer. As no packets are exchanged with a
@@ -82,7 +86,7 @@
 extern	struct	interface *any_interface;
 extern	struct	interface *loopback_interface;
 
-#ifdef PPS
+#if defined(PPS) || defined(HAVE_PPSAPI)
 int fdpps;			/* pps file descriptor */
 #endif /* PPS */
 
@@ -629,6 +633,11 @@
 #ifdef TIOCDCDTIMESTAMP
 	struct timeval dcd_time;
 #endif
+#ifdef HAVE_PPSAPI
+	pps_info_t pi;
+	struct timespec *tsp;
+	double a;
+#endif
 
 	/*
 	 * Check for the presence of a timestamp left by the tty_clock
@@ -641,6 +650,30 @@
 	dpend = dpt + rbufp->recv_length;
 	trtmp = rbufp->recv_time;
 
+#ifdef HAVE_PPSAPI
+	if ((rbufp->fd == fdpps) && (time_pps_fetch(fdpps, &pi) >= 0)) {
+		tsp = &pi.assert_timestamp;
+		a = tsp->tv_nsec;
+		a /= 1e9;
+		tstmp.l_uf =  a * 4294967296.0;
+		tstmp.l_ui = tsp->tv_sec;
+		tstmp.l_ui += JAN_1970;
+		L_SUB(&trtmp, &tstmp);
+		if (trtmp.l_ui == 0) {
+#ifdef DEBUG
+			if (debug > 1) {
+				printf(
+				    "refclock_gtlin: fd %d time_pps_fetch %s",
+				    fdpps, lfptoa(&tstmp, 6));
+				printf(" sigio %s\n", lfptoa(&trtmp, 6));
+			}
+#endif
+			trtmp = tstmp;
+			goto gotit;
+		} else
+			trtmp = rbufp->recv_time;
+	}
+#endif /* HAVE_PPSAPI */
 #ifdef TIOCDCDTIMESTAMP
 	if(ioctl(rbufp->fd, TIOCDCDTIMESTAMP, &dcd_time) != -1) {
 		TVTOTS(&dcd_time, &tstmp);
@@ -657,6 +690,7 @@
 			}
 #endif
 			trtmp = tstmp;
+			goto gotit;
 		} else
 			trtmp = rbufp->recv_time;
 	}
@@ -685,6 +719,7 @@
 		}
 	}
 
+gotit:
 	/*
 	 * Edit timecode to remove control chars. Don't monkey with the
 	 * line buffer if the input buffer contains no ASCII printing
@@ -1073,7 +1108,7 @@
 		(void)tcflush(fd, TCIOFLUSH);
 	}
 #endif /* TTYCLK */
-#ifdef PPS
+#ifdef HAVE_PPSAPI
 	/*
 	 * The PPS option provides timestamping at the driver level.
 	 * It uses a 1-pps signal and level converter (gadget box) and
@@ -1081,14 +1116,35 @@
 	 * systems.
 	 */
 	if (flags & LDISC_PPS) {
+		pps_params_t	pp;
+		int mode;
+
 		if (fdpps > 0) {
 			msyslog(LOG_ERR,
 			    "refclock_ioctl: ppsclock already configured");
 			return (0);
 		}
-		fdpps = fd;
+		if (time_pps_create(fd, &fdpps) < 0) {
+			msyslog(LOG_ERR,
+			    "refclock_ioctl: time_pps_create failed");
+			fdpps = 0;
+			return (0);
+		}
+		if (time_pps_getcap(fdpps, &mode) < 0) {
+			msyslog(LOG_ERR,
+			    "refclock_ioctl: time_pps_getcap failed");
+			fdpps = 0;
+			return (0);
+		}
+		pp.mode = PPS_CAPTUREASSERT | PPS_HARDPPSONASSERT;
+		if (time_pps_setparams(fdpps, &pp) < 0) {
+			msyslog(LOG_ERR,
+			    "refclock_ioctl: time_pps_setparams failed");
+			fdpps = 0;
+			return (0);
+		}
 	}
-#endif /* PPS */
+#endif /* HAVE_PPSAPI */
 #endif /* HAVE_TERMIOS */
 
 #ifdef HAVE_BSD_TTYS


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903301258.OAA23930>