]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Many files:
authorHarlan Stenn <stenn@ntp.org>
Tue, 14 Sep 1999 23:56:28 +0000 (23:56 -0000)
committerHarlan Stenn <stenn@ntp.org>
Tue, 14 Sep 1999 23:56:28 +0000 (23:56 -0000)
  * ntpd/refclock_atom.c: PPS cleanup
  * ntpd/ntp_refclock.c (refclock_ioctl): PPS cleanup
  From: Dave Mills <mills@udel.edu>
  * ntptrace/ntptrace.c (ReceiveBuf): addserver() can return NIL.
  Reported by: "Alan J. Wylie" <alanw@cyrano.com>
  * libntp/ieee754io.c:
  * ntpd/ntp_proto.c:
  * ntpd/ntp_refclock.c:
  Lint cleanup.
  From: Marc.Brett@westgeo.com

bk: 37dee0acScPndV55d-ps3sJcusb8QQ

ChangeLog
libntp/ieee754io.c
ntpd/ntp_proto.c
ntpd/ntp_refclock.c
ntpd/refclock_atom.c
ntptrace/ntptrace.c

index 47ecc291d8e0e4e837e13a85ba1f0a3b1aafc152..4e08e5308cc06c6b38731d2cd31e6df5bc6ae98c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+1999-09-14  Harlan Stenn  <stenn@whimsy.udel.edu>
+
+       * ntpd/refclock_atom.c: PPS cleanup
+       * ntpd/ntp_refclock.c (refclock_ioctl): PPS cleanup
+       From: Dave Mills <mills@udel.edu>
+
+       * ntptrace/ntptrace.c (ReceiveBuf): addserver() can return NIL.
+       Reported by: "Alan J. Wylie" <alanw@cyrano.com>
+
+       * libntp/ieee754io.c:
+       * ntpd/ntp_proto.c:
+       * ntpd/ntp_refclock.c:
+       Lint cleanup.
+       From: Marc.Brett@westgeo.com
+
 1999-09-12  Harlan Stenn  <stenn@whimsy.udel.edu>
 
        * ntpd/ntp_refclock.c (refclock_ioctl): Declaration cleanup.
index 54eebf9f92b6e779e0867eb504ba7e5fbe6cabd4..4aa9920a32783319ebcbce831e38726b64cd1f0b 100644 (file)
@@ -144,21 +144,27 @@ fetch_ieee754(
   u_long mantissa_high;
   u_long characteristic;
   long exponent;
+#ifdef LIBDEBUG
   int length;
+#endif
   unsigned char val;
   int fieldindex = 0;
   
   switch (size)
     {
     case IEEE_DOUBLE:
+#ifdef LIBDEBUG
       length = 8;
+#endif
       mbits  = 52;
       bias   = 1023;
       maxexp = 2047;
       break;
 
     case IEEE_SINGLE:
+#ifdef LIBDEBUG
       length = 4;
+#endif
       mbits  = 23;
       bias   = 127;
       maxexp = 255;
@@ -369,15 +375,19 @@ put_ieee754(
            )
 {
   l_fp outlfp;
+#ifdef LIBDEBUG
   unsigned int sign;
   unsigned int bias;
+#endif
 /*unsigned int maxexp;*/
   int mbits;
   int msb;
   u_long mantissa_low = 0;
   u_long mantissa_high = 0;
+#ifdef LIBDEBUG
   u_long characteristic = 0;
   long exponent;
+#endif
 /*int length;*/
   unsigned long mask;
   
@@ -388,14 +398,18 @@ put_ieee754(
     case IEEE_DOUBLE:
     /*length = 8;*/
       mbits  = 52;
+#ifdef LIBDEBUG
       bias   = 1023;
+#endif
     /*maxexp = 2047;*/
       break;
 
     case IEEE_SINGLE:
     /*length = 4;*/
       mbits  = 23;
+#ifdef LIBDEBUG
       bias   = 127;
+#endif
     /*maxexp = 255;*/
       break;
 
@@ -409,16 +423,22 @@ put_ieee754(
   if (L_ISNEG(&outlfp))
     {
       L_NEG(&outlfp);
+#ifdef LIBDEBUG
       sign = 1;
+#endif
     }
   else
     {
+#ifdef LIBDEBUG
       sign = 0;
+#endif
     }
 
   if (L_ISZERO(&outlfp))
     {
+#ifdef LIBDEBUG
       exponent = mantissa_high = mantissa_low = 0; /* true zero */
+#endif
     }
   else
     {
@@ -475,10 +495,10 @@ put_ieee754(
            }
        }
 
+#ifdef LIBDEBUG
       exponent = msb - 32;
       characteristic = exponent + bias;
-      
-#ifdef LIBDEBUG
+
       if (debug > 4)
        printf("FP: %s\n", fmt_flt(sign, mantissa_high, mantissa_low, characteristic));
 #endif
index ff006fe82d2099161a2481fac357d7ec8bfecc1f..d691b27e25ac419ead7fd4db526fb5b70bf93348 100644 (file)
@@ -220,7 +220,8 @@ receive(
        int is_authentic;               /* cryptosum ok */
        int is_mystic;                  /* session key exists */
        int is_error;                   /* parse error */
-       u_long skeyid, pkeyid, tkeyid;
+/*     u_long pkeyid; */
+       u_long skeyid, tkeyid;
        struct peer *peer2;
        int retcode = AM_NOMATCH;
 
@@ -295,7 +296,8 @@ receive(
         * the extension field and the MAC follows that.
         */
        has_mac = 0;
-       skeyid = pkeyid = tkeyid = 0;
+/*     pkeyid = 0; */
+       skeyid = tkeyid = 0;
        authlen = LEN_PKT_NOMAC;
        has_mac = rbufp->recv_length - authlen;
        if (has_mac <= 5 * sizeof(u_int32)) {
@@ -312,7 +314,7 @@ receive(
                 * Note that keyid3 is actually the key ident of the
                 * MAC itself.
                 */
-               pkeyid = (u_long)ntohl(pkt->keyid2) & 0xffffffff;
+/*             pkeyid = (u_long)ntohl(pkt->keyid2) & 0xffffffff; */
                skeyid = tkeyid = (u_long)ntohl(pkt->keyid3) & 0xffffffff;
        }
 
index bfdfdce3a4eb6df8cd2b4ac2f81a14d142327c76..58b19b75921f95d8a4d60a53adbf7cedfa055e68 100644 (file)
@@ -950,6 +950,7 @@ refclock_ioctl(
 #ifndef SYS_VXWORKS
 #if defined(HAVE_TERMIOS) || defined(HAVE_SYSV_TTYS) || defined(HAVE_BSD_TTYS)
 
+#ifdef TTYCLK
 #ifdef HAVE_TERMIOS
        struct termios ttyb, *ttyp;
 #endif /* HAVE_TERMIOS */
@@ -959,6 +960,7 @@ refclock_ioctl(
 #ifdef HAVE_BSD_TTYS
        struct sgttyb ttyb, *ttyp;
 #endif /* HAVE_BSD_TTYS */
+#endif /* TTYCLK */
 
 #ifdef DEBUG
        if (debug)
@@ -993,7 +995,9 @@ refclock_ioctl(
                return (0);
        }
 #endif /* HAVE_TERMIOS HAVE_BSD_TTYS */
+#ifdef TTYCLK
        ttyp = &ttyb;
+#endif /* TTYCLK */
 #ifdef STREAM
 #ifdef TTYCLK
        /*
@@ -1104,9 +1108,10 @@ refclock_ioctl(
                pps_params_t    pp;
                int mode;
 
+               memset((char *)&pp, 0, sizeof(pp));
                if (fdpps > 0) {
                        msyslog(LOG_ERR,
-                           "refclock_ioctl: ppsclock already configured");
+                           "refclock_ioctl: ppsapi already configured");
                        return (0);
                }
                if (time_pps_create(fd, &fdpps) < 0) {
@@ -1121,12 +1126,13 @@ refclock_ioctl(
                        fdpps = 0;
                        return (0);
                }
-               if(pps_assert)
-                       pp.mode = PPS_CAPTUREASSERT;
+               pp.mode = PPS_TSFMT_TSPEC;
+               if (pps_assert)
+                       pp.mode |= PPS_CAPTUREASSERT;
                else
-                       pp.mode = PPS_CAPTURECLEAR;
-               if(pps_hardpps) {
-                       if(pps_assert)
+                       pp.mode |= PPS_CAPTURECLEAR;
+               if (pps_hardpps) {
+                       if (pps_assert)
                                pp.mode |= PPS_HARDPPSONASSERT;
                        else
                                pp.mode |= PPS_HARDPPSONCLEAR;
index 196781254757a6fe71115f02ce7b36593a173f15..e40c4781d845bb7b3383cc6abeafad92f577f6c4 100644 (file)
  * In order for this driver to work, the local clock must be set to
  * within +-500 ms by another means, such as a radio clock or NTP
  * itself. The 1-pps signal is connected via a serial port and gadget
- * box consisting of a one-shot and RS232 level converter. When operated
- * at 38.4 kbps with a SPARCstation IPC, this arrangement has a worst-
- * case jitter less than 26 us.
+ * box consisting of a one-shot flopflop and RS232 level converter.
+ * Conntection is either via the carrier detect (DCD) lead or via the
+ * receive data (RD) lead. The incidental jitter using the DCD lead is
+ * essentially the interrupt latency. The incidental jitter using the RD
+ * lead has an additional component due to the line sampling clock. When
+ * operated at 38.4 kbps, this arrangement has a worst-case jitter less
+ * than 26 us.
  *
- * There are three ways in which this driver can be used. The first way
- * uses the LDISC_PPS line discipline and works only for the baseboard
- * serial ports of the Sun SPARCstation. The PPS signal is connected via
- * a gadget box to the carrier detect (CD) line of a serial port and
- * flag3 of the driver configured for that port is set. This causes the
- * ppsclock streams module to be configured for that port and capture a
- * timestamp at the on-time transition of the PPS signal. This driver
- * then reads the timestamp directly by a designated ioctl() system
- * call. This provides the most accurate time and least jitter of any
- * other scheme. There is no need to configure a dedicated device for
- * this purpose, which ordinarily is the device used for the associated
- * radio clock.
+ * There are four ways in which this driver can be used. They are
+ * described in decreasing order of merit below. The first way uses the
+ * ppsapi STREAMS module and the LDISC_PPS line discipline, while the
+ * second way uses the ppsclock STREAMS module and the LDISC_PPS line
+ * discipline. Either of these works only for the baseboard serial ports
+ * of the Sun SPARC IPC and clones. However, the ppsapi uses the
+ * proposed IETF interface expected to become standard for PPS signals.
+ * The serial port to be used is specified by the pps command in the
+ * configuration file. This driver reads the timestamp directly by a
+ * designated ioctl() system call.
  *
- * The second way uses the LDISC_CLKPPS line discipline and works for
+ * The third way uses the LDISC_CLKPPS line discipline and works for
  * any architecture supporting a serial port. If after a few seconds
  * this driver finds no ppsclock module configured, it attempts to open
  * a serial port device /dev/pps%d, where %d is the unit number, and
  * discipline, this produces an ASCII DEL character ('\377') followed by
  * a timestamp at each seconds epoch. 
  *
- * The third way involves an auxiliary radio clock driver which calls
+ * The fourth way involves an auxiliary radio clock driver which calls
  * the PPS driver with a timestamp captured by that driver. This use is
  * documented in the source code for the driver(s) involved.  Note that
  * some drivers collect the sample information themselves before calling
- * our pps_sample(), and others call us knowing only that they are running
- * shortly after an on-time tick and they expect us to retrieve the PPS
+ * pps_sample(), and others call knowing only that they are running
+ * shortly after an on-time tick and they expect to retrieve the PPS
  * offset, fudge their result, and insert it into the timestream.
  *
  * Fudge Factors
  *
- * There are no special fudge factors other than the generic and those
- * explicitly defined above. The fudge time1 parameter can be used to
- * compensate for miscellaneous UART and OS delays. Allow about 247 us
- * for uart delays at 38400 bps and about 1 ms for SunOS streams
- * nonsense.
+ * There are no special fudge factors other than the generic. The fudge
+ * time1 parameter can be used to compensate for miscellaneous UART and
+ * OS delays. Allow about 247 us for uart delays at 38400 bps and about
+ * 1 ms for STREAMS nonsense with older workstations. Velocities may
+ * vary with modern workstations. 
  */
-
 /*
  * Interface definitions
  */
@@ -267,7 +268,7 @@ atom_pps(
 {
        register struct atomunit *up;
        struct refclockproc *pp;
-       struct timespec *tsp;
+       struct timespec ts;
        l_fp lftmp;
        double doffset;
        int i;
@@ -285,7 +286,8 @@ atom_pps(
         * Convert the timeval to l_fp and save for billboards. Sign-
         * extend the fraction and stash in the buffer. No harm is done
         * if previous data are overwritten. If the discipline comes bum
-        * or the data grow stale, just forget it.
+        * or the data grow stale, just forget it. Round the nanoseconds
+        * to microseconds with great care.
         */ 
 #ifdef HAVE_PPSAPI
        i = up->pps_info.assert_sequence;
@@ -295,17 +297,18 @@ atom_pps(
                return (1);
        if (i == up->pps_info.assert_sequence)
                return (2);
-       if(pps_assert)
-               tsp = &up->pps_info.assert_timestamp;
+       if (pps_assert)
+               ts = up->pps_info.assert_timestamp;
        else
-               tsp = &up->pps_info.clear_timestamp;
-       pp->lastrec.l_ui = tsp->tv_sec + JAN_1970;
-       TVUTOTSF(tsp->tv_nsec, pp->lastrec.l_uf);
-
-printf("pps %d %s\n", up->pps_info.assert_sequence, lfptoa(&pp->lastrec, 6));
-
+               ts = up->pps_info.clear_timestamp;
+       pp->lastrec.l_ui = ts.tv_sec + JAN_1970;
+       ts.tv_nsec = (ts.tv_nsec + 500) / 1000;
+       if (ts.tv_nsec > 1000000) {
+               ts.tv_nsec -= 1000000;
+               ts.tv_sec++;
+       }
+       TVUTOTSF(ts.tv_nsec, pp->lastrec.l_uf);
 #else
-
        i = up->ev.serial;
        if (fdpps <= 0)
                return (1);
@@ -320,7 +323,8 @@ printf("pps %d %s\n", up->pps_info.assert_sequence, lfptoa(&pp->lastrec, 6));
        L_CLR(&lftmp);
        L_ADDF(&lftmp, pp->lastrec.l_f);
        LFPTOD(&lftmp, doffset);
-       pp->filter[pp->coderecv++ % pp->nstages] = -doffset + pp->fudgetime1;
+       pp->filter[pp->coderecv++ % pp->nstages] = -doffset +
+           pp->fudgetime1;
        up->pollcnt = 2 * 60;
        return (0);
 }
@@ -356,7 +360,8 @@ atom_receive(
        /*
         * Save the timestamp for billboards. Sign-extend the fraction
         * and stash in the buffer. No harm is done if previous data are
-        * overwritten. Do this only if the ppsclock gizmo is not working.
+        * overwritten. Do this only if the ppsclock gizmo is not
+        * working.
         */
        if (up->flags & FLAG_PPS)
                return;
@@ -385,16 +390,14 @@ pps_sample(
        double doffset;
 
        /*
-        * This routine is called once per second when the external clock driver
-        * processes PPS information. It processes the pps timestamp
-        * and saves the sign-extended fraction in a circular
+        * This routine is called once per second when the external
+        * clock driver processes PPS information. It processes the pps
+        * timestamp and saves the sign-extended fraction in a circular
         * buffer for processing at the next poll event.
         */
        peer = pps_peer;
-
        if (peer == 0)          /* nobody home */
                return 1;
-       
        pp = peer->procptr;
        up = (struct atomunit *)pp->unitptr;
 
@@ -409,7 +412,8 @@ pps_sample(
        L_CLR(&lftmp);
        L_ADDF(&lftmp, pp->lastrec.l_f);
        LFPTOD(&lftmp, doffset);
-       pp->filter[pp->coderecv++ % pp->nstages] = -doffset + pp->fudgetime1;
+       pp->filter[pp->coderecv++ % pp->nstages] = -doffset +
+           pp->fudgetime1;
        up->pollcnt = 2 * 60;
        return (0);
 }
@@ -429,14 +433,15 @@ atom_poll(
 
        /*
         * Accumulate samples in the median filter. At the end of each
-        * poll interval, do a little bookeeping and process the samples.
+        * poll interval, do a little bookeeping and process the
+        * samples.
         */
        pp = peer->procptr;
        up = (struct atomunit *)pp->unitptr;
 #if defined(PPS) || defined(HAVE_PPSAPI)
        if (!(up->flags & FLAG_AUX)) {
-       if (atom_pps(peer))
-               return;
+               if (atom_pps(peer))
+                       return;
        }
        if (peer->burst > 0)
                return;
@@ -455,9 +460,9 @@ atom_poll(
         * the pps time is within +-0.5 s of the local time and the
         * seconds numbering is unambiguous.
         */
-       if (pps_update)
+       if (pps_update) {
                pp->leap = LEAP_NOWARNING;
-       else {
+       else {
                pp->leap = LEAP_NOTINSYNC;
                return;
        }
index 93622c198d77d282e216f832f092f9acf03fdec5..d7a4140c05a6bee30b760312af8590d5b378ff40 100644 (file)
@@ -503,7 +503,8 @@ ReceiveBuf(
 
        nextia.s_addr = server->refid;
        nextserver = addserver(&nextia);
-       DoTrace(nextserver);
+       if (nextserver)
+         DoTrace(nextserver);
        return(1);
 }