[LinuxPPS] status

Udo van den Heuvel udovdh at xs4all.nl
Sun Oct 21 10:18:09 CEST 2007


Udo van den Heuvel wrote:
> Udo van den Heuvel wrote:
>> So we can plug this into the atom driver (we can simplify it as you see)
>> or rather still try the NMEA driver?
> 
> Also: I hate to reboot back and forth.
> I am currently running 2.6.22.9 with the patches for that kernel from a
> few weeks ago.
> Can I still do valid compilation tests with the newer setup by unpacking
> 2.6.23 plus the latest kernel patch?

OK, I did the above as a starter.
I unpacked 2.6.23.1, patched with ntp-pps-2.6.23.diff and built the
kernel. I instaleld the kernel and made the links as described at
http://wiki.enneenne.com/index.php/LinuxPPS_support#The_userland_tools.

I changed the code to refclock_nmea.c (from ntp-4.2.4p2) as hinted by
Rodolfo some time ago. I used the old reflock_nmea patch as a basis.
I attached a patch. Over here it compiles fine.
There WILL be logical errors, depending on the situation (one gps on a
serial port, NMEA data and PPS on separate ports, etc).

Please have a good look at the patch and the resulting code and post
your remarks here so we can improve on this first attempt for this
npt-pps release.
-------------- next part --------------
--- ntp-4.2.4p2/ntpd/refclock_nmea.c.org	2006-06-06 22:16:53.000000000 +0200
+++ ntp-4.2.4p2/ntpd/refclock_nmea.c	2007-10-21 10:13:00.000000000 +0200
@@ -61,6 +61,7 @@
 # define DEVICE "COM%d:" 	/* COM 1 - 3 supported */
 #else
 # define DEVICE	"/dev/gps%d"	/* name of radio device */
+# define DEVICEPPS "/dev/pps%d"	/* name of PPS radio device */
 #endif
 #define	SPEED232	B4800	/* uart speed (4800 bps) */
 #define	PRECISION	(-9)	/* precision assumed (about 2 ms) */
@@ -71,6 +72,7 @@
 #define RANGEGATE	500000	/* range gate (ns) */
 
 #define LENNMEA		75	/* min timecode length */
+#define LENPPS		PPS_MAX_NAME_LEN
 
 /*
  * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -91,6 +93,7 @@
 	pps_params_t pps_params; /* pps parameters */
 	pps_info_t pps_info;	/* last pps data */
 	pps_handle_t handle;	/* pps handlebars */
+	int handle_created;	/* pps handle created flag */
 #endif /* HAVE_PPSAPI */
 };
 
@@ -139,15 +142,21 @@
 	register struct nmeaunit *up;
 	struct refclockproc *pp;
 	int fd;
+#ifdef PPS_HAVE_FINDPATH
+	char id[LENPPS] = "",
+	     path[LENPPS],
+	     link[LENPPS] = "/dev/gps0";    /* just a default device */
+#endif	/* PPS_HAVE_FINDPATH */
 	char device[20];
 
 	/*
 	 * Open serial port. Use CLK line discipline, if available.
-	 */
-	(void)sprintf(device, DEVICE, unit);
+         */
+        (void)sprintf(device, DEVICE, unit);
+
+        fd = refclock_open(device, SPEED232, LDISC_CLK);
+        if (fd <= 0) {
 
-	fd = refclock_open(device, SPEED232, LDISC_CLK);
-	if (fd <= 0) {
 #ifdef HAVE_READLINK
           /* nmead support added by Jon Miner (cp_n18 at yahoo.com)
            *
@@ -193,8 +202,38 @@
 #else
             return (0);
 #endif
+} else {
+#ifdef HAVE_PPSAPI
+/*
+ * Start the PPSAPI interface if it is there. Default to use
+ * the assert edge and do not enable the kernel hardpps.
+ */
+           if (time_pps_create(fd, &up->handle) < 0) {
+
+	   	   /* Try the alternare PPS device */
+		   (void) sprintf(device, DEVICEPPS, unit);
+		   fd = open(device, O_RDWR);
+		   if (fd < 0)
+                           goto pps_error;
+
+		   if (time_pps_create(fd, &up->handle) < 0)
+			   goto	pps_error;
+           }
+           return(nmea_ppsapi(peer, 0, 0));
+
+pps_error:
+           /* No luck, no PPS unit available! */
+           up->handle = 0;
+           msyslog(LOG_ERR,
+               "refclock_nmea: alternate PPS device %s fail : %m", device);
+           return (1);
+
+#else
+           return (1);
+#endif /* HAVE_PPSAPI */
         }
 
+
 	/*
 	 * Allocate and initialize unit structure
 	 */
@@ -230,12 +269,25 @@
 	 * Start the PPSAPI interface if it is there. Default to use
 	 * the assert edge and do not enable the kernel hardpps.
 	 */
+#ifdef PPS_HAVE_FINDPATH
+	/* Get the PPS source's real name */
+	time_pps_readlink(link, LENPPS, path, LENPPS);
+
+	/* Try to find the source */
+	fd = time_pps_findpath(path, LENPPS, id, LENPPS);
+	if (fd < 0) {
+		msyslog(LOG_ERR, "refclock_nmea: cannot find PPS path \"%s\" in the system", path);
+		return (0);
+	}
+	msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
+#endif	/* PPS_HAVE_FINDPATH */
 	if (time_pps_create(fd, &up->handle) < 0) {
-		up->handle = 0;
+		up->handle_created = 0;
 		msyslog(LOG_ERR,
 		    "refclock_nmea: time_pps_create failed: %m");
 		return (1);
 	}
+	up->handle_created = ~0;
 	return(nmea_ppsapi(peer, 0, 0));
 #else
 	return (1);
@@ -257,8 +309,10 @@
 	pp = peer->procptr;
 	up = (struct nmeaunit *)pp->unitptr;
 #ifdef HAVE_PPSAPI
-	if (up->handle != 0)
+	if (up->handle_created) {
 		time_pps_destroy(up->handle);
+		up->handle_created = 0;
+	}
 #endif /* HAVE_PPSAPI */
 	io_closeclock(&pp->io);
 	free(up);
@@ -366,7 +420,7 @@
 	/*
 	 * Convert the timespec nanoseconds field to ntp l_fp units.
 	 */ 
-	if (up->handle == 0)
+	if (!up->handle_created)
 		return (0);
 	timeout.tv_sec = 0;
 	timeout.tv_nsec = 0;


More information about the LinuxPPS mailing list