DCF77 driver seems to be broken

Achim Gratz Stromeko at nexgo.de
Sun Feb 19 20:26:30 UTC 2017


Achim Gratz writes:
> So, while the above gets the code to recognize the refclock time again,
> there's some timeout somewhere that makes the clock lose reach in the
> time between each successful detection of the minute.  That's probably
> somewhere where a constant should now be multiplied by 1000 (µs->ns),
> but isn't.  Haven't found that one yet.

It wasn't a timeout, but a reversed application of an offset and a wrong
conversion of the resulting delta value as an absolute timestamp… sigh.
Here's the full patch that restores the DCF77 driver to function.

--8<---------------cut here---------------start------------->8---
diff --git a/include/timespecops.h b/include/timespecops.h
index 399287d..03848cb 100644
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -215,9 +215,6 @@ abs_tspec(
  * compare previously-normalised a and b
  * return 1 / 0 / -1 if a < / == / > b
  */
-#define TIMESPEC_LESS_THAN     1
-#define TIMESPEC_EQUAL         0
-#define TIMESPEC_GREATER_THAN  -1
 
 static inline int
 cmp_tspec(
diff --git a/libparse/clk_rawdcf.c b/libparse/clk_rawdcf.c
index 4151f41..e3a03d8 100644
--- a/libparse/clk_rawdcf.c
+++ b/libparse/clk_rawdcf.c
@@ -509,11 +509,11 @@ calc_usecdiff(
        l_fp delt;
 
        delt = *ref;
-       bumplfpsint(delt, offset);
+       bumplfpsint(delt, -offset);
        delt -= *base;
-       delta = lfp_stamp_to_tspec(delt, NULL);
+       delta = lfp_uintv_to_tspec(delt);
 
-       delta_usec = 1000000 * (int32_t)delta.tv_sec + delta.tv_nsec/1000;
+       delta_usec = (NANOSECONDS/1000)*(int32_t)delta.tv_sec + delta.tv_nsec/1000;
        return delta_usec;
 }
 
@@ -553,7 +553,7 @@ snt_rawdcf(
                               parseio->parse_index - 1, delta_usec));
 
        if (((parseio->parse_dtime.parse_status & CVT_MASK) == CVT_OK) &&
-           (delta_usec < 500000 && delta_usec >= 0)) /* only if minute marker is available */
+           (delta_usec < (NANOSECONDS/2000) && delta_usec >= 0)) /* only if minute marker is available */
        {
                parseio->parse_dtime.parse_stime = *ptime;
 
@@ -578,7 +578,7 @@ inp_rawdcf(
          timestamp_t  *tstamp
          )
 {
-       static struct timespec timeout = { 1, 500000000 }; /* 1.5 secongs denote second #60 */
+       static struct timespec timeout = { 1, (NANOSECONDS/2) }; /* 1.5 seconds denote second #60 */
 
        parseprintf(DD_PARSE, ("inp_rawdcf(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
 
@@ -618,7 +618,7 @@ inp_rawdcf(
                                delta_usec = -1;
                        }
 
-                       if (delta_usec < 500000 && delta_usec >= 0)
+                       if (delta_usec < (NANOSECONDS/2000) && delta_usec >= 0)
                        {
                                parseprintf(DD_RAWDCF, ("inp_rawdcf: timeout time difference %ld usec - minute marker set\n", delta_usec));
                                /* collect minute markers only if spaced by 60 seconds */
diff --git a/libparse/parse.c b/libparse/parse.c
index 702b718..612eeeb 100644
--- a/libparse/parse.c
+++ b/libparse/parse.c
@@ -38,7 +38,7 @@ parse_timedout(
        delt = *tstamp;
        delt -= parseio->parse_lastchar;
        delta = lfp_uintv_to_tspec(delt);
-       if (cmp_tspec(delta, *del) == TIMESPEC_GREATER_THAN)
+       if (cmp_tspec(delta, *del) > 0)
        {
                parseprintf(DD_PARSE, ("parse: timedout: TRUE\n"));
                return true;
--8<---------------cut here---------------end--------------->8---


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Samples for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldSamplesExtra



More information about the devel mailing list