From 0548136a4c886830414fb575d9d0daa7f1a7d170 Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Wed, 8 May 2019 23:17:01 +0100 Subject: sysclk back to 168MHz, 10Mhz -> TIM2 --- app/gps.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'app/gps.c') diff --git a/app/gps.c b/app/gps.c index 9d5a992..c3ac2d1 100644 --- a/app/gps.c +++ b/app/gps.c @@ -1,8 +1,11 @@ #include "project.h" -#define PPS (GPIO9) +#define PPS (GPIO7) #define PPS_PORT GPIOC +#define NRESET (GPIO8) +#define NRESET_PORT GPIOC + #define UBX_BUF_LEN 256 #define TIMEOUT 4000 @@ -23,27 +26,28 @@ uint64_t gps_last_happy; static char fix, fix2; static int32_t freq = 0; -static const int fish[] = { 1, 2, 3, 4, 5, 6, 7 }; +//static const int fish[] = { 1, 2, 3, 4, 5, 6, 7 }; static Event_ring gps_ring; static char gps_info[60]; - void exti9_5_isr (void) { - uint32_t now = SCS_DWT_CYCCNT; + uint32_t now = HW_CLOCK_REG; int v; v = !!gpio_get (PPS_PORT, PPS); nvic_disable_irq (NVIC_EXTI9_5_IRQ); - exti_reset_request (EXTI9); + exti_reset_request (EXTI7); gps_ring.events[gps_ring.tx_ptr].when = now; gps_ring.events[gps_ring.tx_ptr].value = v; gps_ring.tx_ptr = (gps_ring.tx_ptr + 1) & ERING_MASK; + if (v) sysclk_event(); + nvic_enable_irq (NVIC_EXTI9_5_IRQ); } @@ -270,7 +274,7 @@ ubx_recv_utc (uint8_t *ptr, unsigned len) next_sec = gps_time; - now = SCS_DWT_CYCCNT; + now = HW_CLOCK_REG; abs = abs_extend (now); gps_last_happy = make_happy (abs, 180); @@ -578,7 +582,7 @@ static void gps_pps_dispatch (void) uint32_t now; uint64_t abs; int v; - EPOCH e; + //EPOCH e; //UTC u; if (gps_ring.rx_ptr == gps_ring.tx_ptr) return; @@ -601,7 +605,7 @@ static void gps_pps_dispatch (void) if (gps_happy > 30) pll_dispatch (gps_last_happy, abs, "GPS"); - e = pll_decompose (abs); + //e = pll_decompose (abs); //u = time_epoch_to_utc (e); @@ -957,12 +961,17 @@ gps_init (void) // printf ("GPS ready\r\n"); // ubx_get_clock_stats(); + // + + + SET (NRESET); MAP_INPUT (PPS); + MAP_OUTPUT_PP (NRESET); - exti_select_source (EXTI9, PPS_PORT); - exti_set_trigger (EXTI9, EXTI_TRIGGER_BOTH); - exti_enable_request (EXTI9); + exti_select_source (EXTI7, PPS_PORT); + exti_set_trigger (EXTI7, EXTI_TRIGGER_BOTH); + exti_enable_request (EXTI7); nvic_enable_irq (NVIC_EXTI9_5_IRQ); return 0; @@ -1009,7 +1018,7 @@ void gps_dump_almanac (void) #if 1 int gps_bs (void) { - uint32_t now = SCS_DWT_CYCCNT; + uint32_t now = HW_CLOCK_REG; uint64_t abs = abs_extend (now); EPOCH e = pll_decompose (abs); UTC u = time_epoch_to_utc (e); -- cgit v1.2.3