gpio_set_mode(RTC_DCF77_ENABLE_PORT,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,RTC_DCF77_ENABLE_PIN);// set pin to output push-pull to be able to enable the module
rtc_dcf77_off();// disable module at start
// setup signal input
rcc_periph_clock_enable(RTC_DCF77_SIGNAL_RCC);// enable clock for signal input peripheral
gpio_set_mode(RTC_DCF77_SIGNAL_PORT,GPIO_MODE_INPUT,GPIO_CNF_INPUT_FLOAT,RTC_DCF77_SIGNAL_PIN);// set signal pin to input
rcc_periph_clock_enable(RCC_AFIO);// enable alternate function clock for external interrupt
exti_select_source(RTC_DCF77_SIGNAL_EXTI,RTC_DCF77_SIGNAL_PORT);// mask external interrupt of this pin only for this port
exti_set_trigger(RTC_DCF77_SIGNAL_EXTI,EXTI_TRIGGER_BOTH);// trigger on both edges
rcc_periph_clock_enable(RTC_DCF77_TIMER_RCC);// enable clock for timer peripheral
timer_reset(RTC_DCF77_TIMER);// reset timer state
timer_set_mode(RTC_DCF77_TIMER,TIM_CR1_CKD_CK_INT,TIM_CR1_CMS_EDGE,TIM_CR1_DIR_UP);// set timer mode, use undivided timer clock, edge alignment (simple count), and count up
timer_set_prescaler(RTC_DCF77_TIMER,RTC_DCF77_TIMER_MAX_TIME*(rcc_ahb_frequency/1000)/(1<<16));// set prescaler to count up to the maximum time
timer_enable_counter(RTC_DCF77_TIMER);// start timer to measure time
}
voidrtc_dcf77_on(void)
{
gpio_clear(RTC_DCF77_ENABLE_PORT,RTC_DCF77_ENABLE_PIN);// enable module by pull pin low
}
voidrtc_dcf77_off(void)
{
gpio_set(RTC_DCF77_ENABLE_PORT,RTC_DCF77_ENABLE_PIN);// disable module by pull pin high
to_return[2]=1*((rtc_dcf77_frame>>36)&(0x1))+2*((rtc_dcf77_frame>>37)&(0x1))+4*((rtc_dcf77_frame>>38)&(0x1))+8*((rtc_dcf77_frame>>39)&(0x1))+10*((rtc_dcf77_frame>>40)&(0x1))+20*((rtc_dcf77_frame>>34)&(0x41));// read day of the month (01-31)
to_return[3]=1*((rtc_dcf77_frame>>42)&(0x1))+2*((rtc_dcf77_frame>>43)&(0x1))+4*((rtc_dcf77_frame>>44)&(0x1));// read day of the week (1=Monday - 7=Sunday)
to_return[4]=1*((rtc_dcf77_frame>>45)&(0x1))+2*((rtc_dcf77_frame>>46)&(0x1))+4*((rtc_dcf77_frame>>47)&(0x1))+8*((rtc_dcf77_frame>>48)&(0x1))+10*((rtc_dcf77_frame>>49)&(0x1));// read month of the year (01-12)
to_return[5]=1*((rtc_dcf77_frame>>50)&(0x1))+2*((rtc_dcf77_frame>>51)&(0x1))+4*((rtc_dcf77_frame>>52)&(0x1))+8*((rtc_dcf77_frame>>53)&(0x1))+10*((rtc_dcf77_frame>>54)&(0x1))+20*((rtc_dcf77_frame>>55)&(0x1))+40*((rtc_dcf77_frame>>56)&(0x1))+80*((rtc_dcf77_frame>>57)&(0x1));// read year of the century (00-99)