From c93861c733ced9c6659241cea69c7feed56afcce Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Wed, 20 Feb 2019 02:39:38 +0000 Subject: use OCXO, and auto fail-over between different clock sources --- app/gps.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'app/gps.c') diff --git a/app/gps.c b/app/gps.c index 5fc9994..b3c322d 100644 --- a/app/gps.c +++ b/app/gps.c @@ -12,8 +12,10 @@ static int ubx_ack_xfer = 0; static int current_ref_hz = 1; -int gps_locked; -int gps_happy; +static int gps_locked; +static int gps_happy; + +uint64_t gps_last_happy; static char fix, fix2; static int32_t freq = 0; @@ -214,7 +216,11 @@ ubx_recv_utc (uint8_t *ptr, unsigned len) now = SCS_DWT_CYCCNT; abs = abs_extend (now); + + gps_last_happy = abs + (int64_t) HZ * (int64_t) 60; + pll_set_offset (gps_time, abs); + } @@ -453,7 +459,8 @@ static void gps_pps_dispatch (void) - pll_dispatch (abs); + if (gps_happy) + pll_dispatch (gps_last_happy, abs, "GPS"); e = pll_decompose (abs); @@ -471,7 +478,7 @@ gps_dispatch (void) gps_pps_dispatch(); } -void +static void ubx_send (uint8_t class, uint8_t id, const void *_payload, unsigned len) { uint8_t ck_a = 0, ck_b = 0; @@ -502,7 +509,7 @@ ubx_send (uint8_t class, uint8_t id, const void *_payload, unsigned len) } -int +static int ubx_handshake (uint8_t class, uint8_t id, const void *payload, unsigned len) { uint32_t timeout; @@ -532,7 +539,7 @@ ubx_handshake (uint8_t class, uint8_t id, const void *payload, unsigned len) return 0; } -int +static int ubx_handshake_xfer (uint8_t class, uint8_t id, const void *payload, unsigned len) { @@ -567,7 +574,7 @@ ubx_handshake_xfer (uint8_t class, uint8_t id, const void *payload, -uint8_t * +static uint8_t * ubx_fetch (uint8_t class, uint8_t id, void *payload, unsigned len, unsigned *len_ptr) { @@ -584,7 +591,7 @@ ubx_fetch (uint8_t class, uint8_t id, void *payload, unsigned len, return ret; } -int +static int ubx_set_message_rate_port1 (uint8_t class, uint8_t id, uint8_t rate) { uint8_t buf[8], *ptr; @@ -604,7 +611,7 @@ ubx_set_message_rate_port1 (uint8_t class, uint8_t id, uint8_t rate) } -int +static int ubx_cfg_rst (uint16_t flags) { uint8_t buf[8], *ptr; @@ -620,7 +627,7 @@ ubx_cfg_rst (uint16_t flags) } -int +static int gps_set_ref (int ref_hz) { uint8_t buf[80], *ptr; @@ -852,7 +859,8 @@ gps_reset (void) } -int +#if 0 +static int ubx_get_clock_stats (void) { uint8_t *ptr; @@ -864,3 +872,4 @@ ubx_get_clock_stats (void) //return ubx_recv_clock_stats(ptr,len); return ptr ? 0 : -1; } +#endif -- cgit v1.2.3