From 74e577ac110513669a6d677842ceca4c5b1252ca Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Sat, 4 May 2019 12:37:04 +0100 Subject: cut #1 --- app/dcf77.c | 89 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 32 deletions(-) (limited to 'app/dcf77.c') diff --git a/app/dcf77.c b/app/dcf77.c index 2a952cd..e55fcfc 100644 --- a/app/dcf77.c +++ b/app/dcf77.c @@ -1,37 +1,54 @@ #include "project.h" -#define P1 (GPIO11) -#define P1_PORT GPIOD +#define J2(a,b) a ## b +#define J3(a,b,c) a ## b ## c -#define T (GPIO12) -#define T_PORT GPIOD +#define P1 (GPIO4) +#define P1_PORT GPIOE + +#define T_BIT 2 +#define T_PORT GPIOE +#define T_EXTI_LINE T_BIT + + + +#define M_T(a) J2(GPIO,a) +#define T M_T(T_BIT) +#define M_EXTI_T(a) J2(EXTI,a) +#define EXTI_T M_EXTI_T(T_EXTI_LINE) +#define M_exti_t_isr(a) J3(exti,a,_isr) +#define exti_t_isr M_exti_t_isr(T_EXTI_LINE) +#define M_NVIC_EXTI_T_IRQ(a) J3(NVIC_EXTI,a,_IRQ) +#define NVIC_EXTI_T_IRQ M_NVIC_EXTI_T_IRQ(T_EXTI_LINE) static Event_ring dcf77_ring; +static EPOCH dcf77_time; static uint64_t dcf77_last_second; uint64_t dcf77_last_happy; -void exti15_10_isr (void) +static char dcf77_info[40]; + +void exti_t_isr (void) { uint32_t now = SCS_DWT_CYCCNT; int v; v = !!gpio_get (T_PORT, T); - nvic_disable_irq (NVIC_EXTI15_10_IRQ); - exti_reset_request (EXTI12); + nvic_disable_irq (NVIC_EXTI_T_IRQ); + + exti_reset_request (EXTI_T); dcf77_ring.events[dcf77_ring.tx_ptr].when = now; dcf77_ring.events[dcf77_ring.tx_ptr].value = v; dcf77_ring.tx_ptr = (dcf77_ring.tx_ptr + 1) & ERING_MASK; - nvic_enable_irq (NVIC_EXTI15_10_IRQ); -} - - + nvic_enable_irq (NVIC_EXTI_T_IRQ); +} static uint8_t bits[60]; @@ -39,7 +56,7 @@ static uint8_t bits[60]; static void process_bits (uint64_t abs) { UTC u; - EPOCH dcf77_time; + EPOCH e; if (bits[0]) return; @@ -63,23 +80,28 @@ static void process_bits (uint64_t abs) - dcf77_time = time_utc_to_epoch (u); + e = time_utc_to_epoch (u); + + + e.s -= 3600; /*CET*/ - dcf77_time.s -= 2; /*Message arrives 2s early*/ + if (bits[17]) e.s -= 3600; /*CEST*/ - dcf77_time.s -= 3600; /*CET*/ - if (bits[17]) dcf77_time.s -= 3600; /*CEST*/ + e.s -= 2; /*Message arrives 2s early*/ + + dcf77_time = e; dcf77_last_happy = make_happy (abs, 60); - pll_set_offset (dcf77_time, abs); + pll_set_offset (e, abs); + printf ("DCF77: Next minute is: %02d-%02d-%02d %02d:%02d\r\n", u.year, u.month, u.mday, u.hour, u.minute); - time_print_epoch ("DCF77: ", dcf77_time); + time_print_epoch ("DCF77: ", e, dcf77_info); dump_bits ("dcf77", bits); } @@ -97,14 +119,6 @@ static void report_bit (uint64_t abs, int second, int b) } -static void report_time (uint64_t abs) -{ -#if 1 - EPOCH e = pll_decompose (abs); - time_print_epoch ("DCF77: ", e); -#endif -} - void dcf77_dispatch (void) { @@ -117,6 +131,7 @@ void dcf77_dispatch (void) uint32_t now; int v; + led2_set (!!gpio_get (T_PORT, T)); @@ -125,6 +140,9 @@ void dcf77_dispatch (void) v = dcf77_ring.events[dcf77_ring.rx_ptr].value; now = dcf77_ring.events[dcf77_ring.rx_ptr].when; + + //led2_set(v); + dcf77_ring.rx_ptr = (dcf77_ring.rx_ptr + 1) & ERING_MASK; if (v) { @@ -137,6 +155,7 @@ void dcf77_dispatch (void) last_s = now; is_s = 1; second++; + dcf77_time.s++; } if (pulse_w > 1300) { @@ -153,6 +172,9 @@ void dcf77_dispatch (void) else bit = 0; + + sprintf (dcf77_info, "m=%d s=%02d b=%d", had_m, second, bit); + if (had_m) report_bit (abs, second, bit); @@ -168,8 +190,7 @@ void dcf77_dispatch (void) pll_dispatch (dcf77_last_happy, abs, "DCF77"); - if (time_known) - report_time (abs); + report_time ("DCF", dcf77_time, abs, dcf77_info); } @@ -183,12 +204,16 @@ dcf77_init (void) MAP_INPUT (T); MAP_OUTPUT_PP (P1); + + gpio_set (P1_PORT, P1); + delay_ms (50); gpio_clear (P1_PORT, P1); - exti_select_source (EXTI12, T_PORT); - exti_set_trigger (EXTI12, EXTI_TRIGGER_BOTH); - exti_enable_request (EXTI12); - nvic_enable_irq (NVIC_EXTI15_10_IRQ); + exti_select_source (EXTI_T, T_PORT); + exti_set_trigger (EXTI_T, EXTI_TRIGGER_BOTH); + exti_enable_request (EXTI_T); + + nvic_enable_irq (NVIC_EXTI_T_IRQ); } -- cgit v1.2.3