#include "project.h" #define FLASH 100 static unsigned led1 = FLASH, led2 = FLASH; static void metric_pll (void) { static uint32_t last; static int which; static unsigned ttg; EPOCH e; uint64_t v; if ((ticks - last) < ttg) return; e = rtc_get(); if (which) { led2 = FLASH; CLEAR (LED2); } else { led1 = FLASH; CLEAR (LED1); } last = ticks; which = !which; v = e.s; v %= 86400; v *= 1000; v += e.ns / 1000000; v %= 864; //printf("M: %5u %9u\r\n",(unsigned) v, (unsigned ) (e.ns/1000000)); ttg = 864 - (unsigned)v; } static void customary_pll (void) { static uint32_t last; static unsigned ttg; EPOCH e; uint64_t v; if ((ticks - last) < ttg) return; e = rtc_get(); led2 = FLASH; CLEAR (LED2); last = ticks; v = e.ns / 1000000; v %= 1000; ttg = 1000 - (unsigned)v; // printf("C: %9u\r\n",(unsigned ) (e.ns/1000000)); } void led_tick (void) { if (led1) { CLEAR (LED1); led1--; } else SET (LED1); if (led2) { CLEAR (LED2); led2--; } else SET (LED2); if (!rtc_ready) return; metric_pll(); // customary_pll(); } void leds_init (void) { MAP_OUTPUT_OD (LED1); MAP_OUTPUT_OD (LED2); }