summaryrefslogtreecommitdiffstats
path: root/app/pll.c
blob: d2d1495b49c6b16d073cb7cc187e4280b9f1638e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "project.h"
#define WARM_UP     30

void pll_set_offset (EPOCH epoch, uint64_t abs, uint64_t ptp)
{

  ref_set_offset (epoch, abs);
  ptp_set_offset (epoch, ptp);
}


void pll_dispatch (uint64_t happy, uint64_t edge, uint64_t ptp_edge, const char *src)
{
  //  int64_t delta_f;

  if (((!gps_last_happy) && (!dcf77_last_happy) && (!msf_last_happy)) ||
      (happy < gps_last_happy)  ||
      (happy < dcf77_last_happy)  ||
      (happy < msf_last_happy) ||
      (edge < ((uint64_t) WARM_UP  * (uint64_t) HW_CLOCK_HZ)))
    return;

  led_blink (100);


  ref_dispatch (edge, src);
  ptp_dispatch (ptp_edge, src);
}

void pll_check (void)
{
  uint64_t ptp = ptp_get();
  uint64_t ref = ref_get();
  EPOCH re, pe;
  UTC ru, pu;
  static unsigned m;



  re = ref_decompose (ref);
  ru = time_epoch_to_utc (re);


  if (m == ru.minute) return;

  m = ru.minute;

  pe = ptp_decompose (ptp);


  pu = time_epoch_to_utc (pe);


  printf ("PLL checks: R %04d-%02d-%02d %02d:%02d:%02d.%09d  P %04d-%02d-%02d %02d:%02d:%02d.%09d\r\n",
          ru.year,
          ru.month + 1,
          ru.mday,
          ru.hour,
          ru.minute,
          ru.second,
          ru.nanosecond,
          pu.year,
          pu.month + 1,
          pu.mday,
          pu.hour,
          pu.minute,
          pu.second,
          pu.nanosecond);









}