diff -uNrBbd ntp-dev-4.2.5p158.org/ntpd/refclock_nmea.c ntp-dev-4.2.5p158/ntpd/refclock_nmea.c --- ntp-dev-4.2.5p158.org/ntpd/refclock_nmea.c 2008-06-07 01:13:46.000000000 +0200 +++ ntp-dev-4.2.5p158/ntpd/refclock_nmea.c 2009-02-13 10:19:24.000000000 +0100 @@ -74,6 +74,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 alternate PPS radio device */ #endif #define SPEED232 B4800 /* uart speed (4800 bps) */ #define PRECISION (-9) /* precision assumed (about 2 ms) */ @@ -265,17 +266,37 @@ gps_send(pp->io.fd,"$PMOTG,RMC,0000*1D\r\n", peer); #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) { - up->handle = 0; - msyslog(LOG_ERR, - "refclock_nmea: time_pps_create failed: %m"); - return (1); + msyslog(LOG_ERR, "refclock_nmea: found GPS source \"%s\"", device); + if (time_pps_create(pp->io.fd, &up->handle) == 0) + { + msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\"", device); + return(nmea_ppsapi(peer, 0, 0, &(pp->fudgetime1))); } - return(nmea_ppsapi(peer, 0, 0, NULL)); + + /* Try the alternate PPS device */ + (void) snprintf(device, sizeof(device), DEVICEPPS, unit); + fd = open(device, O_RDWR); + if (fd >= 0) /* /dev/pps0 exists */ + { + msyslog(LOG_ERR, "refclock_nmea: try \"%s\" for PPS", device); + + if (time_pps_create(fd, &up->handle) == 0) + { + msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\"", device); + return(nmea_ppsapi(peer, 0, 0, &(pp->fudgetime1))); + } + + close(fd); + } + else if (errno != EEXIST) + { + msyslog(LOG_ERR, "refclock_nmea: error opening %s: %m", device); + } + + /* No luck, no PPS unit available! */ + up->handle = -1; + msyslog(LOG_ERR, "refclock_nmea: no PPS devices found at %s", device); + return (1); #else return (1); #endif /* HAVE_PPSAPI */ @@ -296,7 +317,6 @@ pp = peer->procptr; up = (struct nmeaunit *)pp->unitptr; #ifdef HAVE_PPSAPI - if (up->handle != 0) time_pps_destroy(up->handle); #endif /* HAVE_PPSAPI */ io_closeclock(&pp->io); @@ -314,20 +334,20 @@ struct refclockstat *out, /* output parameters (not used) */ struct peer *peer /* peer structure pointer */ ) -{ + { struct refclockproc *pp; pp = peer->procptr; nmea_ppsapi(peer, pp->sloppyclockflag & CLK_FLAG2, pp->sloppyclockflag & CLK_FLAG3, &(pp->fudgetime1)); -} + } -/* + /* * Initialize PPSAPI */ -int -nmea_ppsapi( + int + nmea_ppsapi( struct peer *peer, /* peer structure pointer */ int enb_clear, /* clear enable */ int enb_hardpps, /* hardpps enable */ @@ -422,7 +442,7 @@ /* * Convert the timespec nanoseconds field to ntp l_fp units. */ - if (up->handle == 0) + if (up->handle == -1) return (0); timeout.tv_sec = 0; timeout.tv_nsec = 0;