]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Changes from Dave Mills. Sawtooth filter for audio IRIG, mainly.
authorHarlan Stenn <stenn@ntp.org>
Thu, 24 Oct 2002 03:30:41 +0000 (23:30 -0400)
committerHarlan Stenn <stenn@ntp.org>
Thu, 24 Oct 2002 03:30:41 +0000 (23:30 -0400)
bk: 3db76961qOL8YXKuYKUvwcuDq8h5Kw

ntpd/ntp_proto.c
ntpd/ntp_request.c
ntpd/refclock_irig.c

index 017f653e9aade0852d71290ce9cebb88bbd63e8e..cf8a33f689704b71f8927790d8d6f038c8901bde 100644 (file)
@@ -1884,7 +1884,7 @@ clock_select(void)
         */
        low = 1e9;
        high = -1e9;
-       for (allow = 0; allow < nlist / 2; allow++) {
+       for (allow = 0; 2 * allow < nlist; allow++) {
                int     found;
 
                /*
index 0aced1f87afdaeb1bab96cee90b5e9ad0080fa5a..61c664c310c25165119e5637ebb4b88f62d60753 100644 (file)
@@ -2636,7 +2636,7 @@ get_clock_info(
                ic->timestarted = htonl((u_int32)clock_stat.timereset);
                DTOLFP(clock_stat.fudgetime1, &ltmp);
                HTONL_FP(&ltmp, &ic->fudgetime1);
-               DTOLFP(clock_stat.fudgetime1, &ltmp);
+               DTOLFP(clock_stat.fudgetime2, &ltmp);
                HTONL_FP(&ltmp, &ic->fudgetime2);
                ic->fudgeval1 = htonl((u_int32)clock_stat.fudgeval1);
                ic->fudgeval2 = htonl((u_int32)clock_stat.fudgeval2);
index e9f40cd04bf9791cff87ba953679878f6374eabb..e34c40599458834d2ccd8e6a9192bd18bda734bf 100644 (file)
@@ -97,9 +97,9 @@
  *
  * The timecode format used for debugging and data recording includes
  * data helpful in diagnosing problems with the IRIG signal and codec
- * connections. With debugging enabled (-d -d -d on the ntpd command
- * line), the driver produces one line for each timecode in the
- * following format:
+ * connections. With debugging enabled (-d on the ntpd command line),
+ * the driver produces one line for each timecode in the following
+ * format:
  *
  * 00 1 98 23 19:26:52 721 143 0.694 20 0.1 66.5 3094572411.00027
  *
  * timestamp in NTP format.
  *
  * The fraction part of the on-time timestamp is a good indicator of how
- * well the driver is doing. With an UltrSPARC 30, this thing can keep
- * the clock within a few tens of microseconds relative to the IRIG-B
- * signal. Accuracy with IRIG-E is about ten times worse.
+ * well the driver is doing. With an UltrSPARC 30 and Solaris 2.7, this
+ * thing can keep the clock within a few tens of microseconds relative
+ * to the IRIG-B signal. Accuracy with IRIG-E is about ten times worse.
+ * Unfortunately, Sun broke the 2.7 audio driver in 2.8, which has a
+ * 10-ms sawtooth modulation. The driver attempts to remove the
+ * modulation by some clever estimation techniques which mostly work.
+ * Your experience may vary.
  *
  * Unlike other drivers, which can have multiple instantiations, this
  * one supports only one. It does not seem likely that more than one
@@ -246,6 +250,9 @@ struct irigunit {
        int     fieldcnt;       /* subfield count in field */
        int     bits;           /* demodulated bits */
        int     bitcnt;         /* bit count in subfield */
+       l_fp    waggle;         /* sawtooth accumulator (s) */
+       l_fp    wiggle;         /* sawtooth correction (s) */
+       l_fp    wuggle;         /* sawtooth monitor (s) */
 };
 
 /*
@@ -822,7 +829,64 @@ irig_decode(
                up->fieldcnt = 0;
                up->lastbit = 0;
                if (up->errflg == 0) {
-                       refclock_process(pp);
+                       l_fp    ltemp, mtemp;
+
+                       /*
+                        * You didn't see this; I wasn't here.
+                        *
+                        * Recent Sun kernels have developed an evil
+                        * 10-ms sawtooth modulation that ruined what
+                        * once was an excellent, low-jitter time
+                        * reference. This code tries to unmodulate the
+                        * sawtooth by using each measured time
+                        * difference to estimate the next one as the
+                        * sawtooth amplitude increases with time. Upon
+                        * retrace, the accumulated difference relative
+                        * to the current offset is uset to interpolate
+                        * and produce an unbiased result.
+                        *
+                        * It's important to remember these samples are
+                        * processed by the median filter, which tosses
+                        * out noisy samples and averages the rest. This
+                        * just helps reduce the jitter and leave at
+                        * least some good samples for the middle of the
+                        * filter. 
+                        */
+                       mtemp = pp->lastrec;
+                       if (L_ISZERO(&pp->lastrec) ||
+                           L_ISZERO(&pp->lastref)) {
+                               L_CLR(&ltemp);
+                       } else {
+                               ltemp = pp->lastrec;
+                               L_SUB(&ltemp, &pp->lastref);
+                       }
+                       if (ltemp.l_f < 0)
+                               ltemp.l_i = -1;
+                       else
+                               ltemp.l_i = 0;
+                       L_SUB(&pp->lastrec, &up->waggle);
+                       if (!L_ISNEG(&ltemp)) {
+                               L_ADD(&ltemp, &up->waggle);
+                               up->waggle = ltemp;
+                       } else {
+                               L_SUB(&ltemp, &up->wiggle);
+                               if (L_ISNEG(&ltemp)) {
+                                       L_NEG(&ltemp);
+                                       L_RSHIFT(&ltemp);
+                                       L_RSHIFT(&ltemp);
+                                       L_RSHIFT(&ltemp);
+                                       L_NEG(&ltemp);
+                               } else {
+                                       L_RSHIFT(&ltemp);
+                                       L_RSHIFT(&ltemp);
+                                       L_RSHIFT(&ltemp);
+                               }
+                               L_ADD(&up->wiggle, &ltemp);
+                               L_ADD(&up->waggle, &up->wiggle);
+                               refclock_process(pp);
+                               up->wuggle = pp->lastrec;
+                       }
+                       pp->lastrec = mtemp;
                        pp->lastref = pp->lastrec;
                }
                up->errflg = 0;
@@ -880,7 +944,7 @@ irig_decode(
                            pp->hour, pp->minute, pp->second,
                            up->maxsignal, up->gain, up->modndx,
                            up->tc, up->exing * 1e6 / SECOND, up->freq *
-                           1e6 / SECOND, ulfptoa(&pp->lastrec, 6));
+                           1e6 / SECOND, ulfptoa(&up->wuggle, 6));
                        pp->lencode = strlen(pp->a_lastcode);
                        if (pp->sloppyclockflag & CLK_FLAG4) {
                                record_clock_stats(&peer->srcadr,