27 #include <libopencm3/stm32/rcc.h>
28 #include <libopencm3/stm32/gpio.h>
29 #include <libopencm3/stm32/spi.h>
30 #include <libopencm3/stm32/timer.h>
31 #include <libopencm3/cm3/nvic.h>
32 #include <libopencmsis/core_cm3.h>
50 rcc_periph_clock_enable(RCC_AFIO);
59 timer_set_mode(
RTC_DCF77_TIMER, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
76 static uint8_t to_return[6] = {0};
86 for (uint8_t bit=21; bit<=28; bit++) {
95 if (to_return[0]>59) {
100 for (uint8_t bit=29; bit<=35; bit++) {
109 if (to_return[1]>23) {
114 for (uint8_t bit=36; bit<=58; bit++) {
123 if (to_return[2]==0 || to_return[2]>31) {
127 if (to_return[3]==0 || to_return[3]>7) {
131 if (to_return[4]==0 || to_return[4]>12) {
135 if (to_return[5]>99) {
145 static uint16_t old_state = 0;
146 static uint8_t pulse = 0;
147 static uint16_t pulse_edge = 0;
148 static uint64_t rtc_dcf77_frame_tmp = 0;
152 if (old_state!=new_state) {
157 }
else if (time < 1030) {
162 }
else if (time < 1980) {
164 }
else if (time < 2130) {
178 }
else if (time < 120) {
179 rtc_dcf77_frame_tmp &= ~((uint64_t)1<<pulse);
180 }
else if (time < 190) {
182 }
else if (time < 220) {
183 rtc_dcf77_frame_tmp |= ((uint64_t)1<<pulse);
188 old_state = new_state;
#define RTC_DCF77_TIMER_MAX_TIME
the maximum time in ms the timer can count.
#define RTC_DCF77_ENABLE_PIN
GPIO pinto enable the module.
#define RTC_DCF77_TIMER_RCC
timer peripheral clock
volatile uint64_t rtc_dcf77_frame
the received DCF77 frame bits
void rtc_dcf77_setup(void)
setup DCF77 time receiver module
void RTC_DCF77_SIGNAL_ISR(void)
interrupt service routine called when signal edge is detected, decoding the received DCF77 frame (com...
#define RTC_DCF77_SIGNAL_PORT
GPIO port to capture the DCF signal.
global definitions and methods
void rtc_dcf77_off(void)
switch off DCF77 time receiver module
#define RTC_DCF77_SIGNAL_IRQ
GPIO line interrupt.
#define RTC_DCF77_ENABLE_PORT
GPIO port to enable the module.
volatile bool rtc_dcf77_time_flag
set when time information has been received
#define RTC_DCF77_SIGNAL_PIN
GPIO pin to capture the DCF signal.
#define RTC_DCF77_SIGNAL_RCC
GPIO peripheral clock to capture the DCF signal.
uint8_t * rtc_dcf77_time(void)
get last received DCF77 time
#define RTC_DCF77_TIMER
timer peripheral
library to get time from a DCF77 module (API)
#define RTC_DCF77_SIGNAL_EXTI
GPIO external interrupt to capture the DCF signal.
void rtc_dcf77_on(void)
switch on DCF77 time receiver module
#define RTC_DCF77_ENABLE_RCC
GPIO peripheral clock to enable the module.