You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1019 B
56 lines
1019 B
#include <libopencm3/cm3/nvic.h>
|
|
#include <libopencm3/stm32/exti.h>
|
|
#include <libopencm3/stm32/gpio.h>
|
|
#include <libopencm3/stm32/rtc.h>
|
|
|
|
#include <rtc.h>
|
|
|
|
static int reset = 0;
|
|
|
|
void rtc_alarm_isr(void)
|
|
{
|
|
if (rtc_check_flag(RTC_ALR)) {
|
|
rtc_clear_flag(RTC_ALR);
|
|
|
|
rtc_disable_alarm();
|
|
exti_reset_request(EXTI17);
|
|
|
|
if (!reset) {
|
|
reset = 1;
|
|
gpio_set(GPIOA, GPIO1);
|
|
|
|
rtc_set_alarm_time(rtc_get_counter_val() + 5);
|
|
rtc_enable_alarm();
|
|
} else {
|
|
reset = 0;
|
|
gpio_set(GPIOA, GPIO1);
|
|
alarm_disable();
|
|
}
|
|
}
|
|
}
|
|
|
|
int alarm_enable(uint32_t timeout)
|
|
{
|
|
rtc_enable_alarm();
|
|
rtc_set_alarm_time(rtc_get_counter_val() + timeout);
|
|
|
|
exti_enable_request(EXTI17);
|
|
exti_set_trigger(EXTI17, EXTI_TRIGGER_RISING);
|
|
|
|
nvic_enable_irq(NVIC_RTC_ALARM_IRQ);
|
|
nvic_set_priority(NVIC_RTC_ALARM_IRQ, 1);
|
|
|
|
rtc_interrupt_enable(RTC_ALR);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int alarm_disable(void)
|
|
{
|
|
exti_disable_request(EXTI17);
|
|
nvic_disable_irq(NVIC_RTC_ALARM_IRQ);
|
|
rtc_interrupt_disable(RTC_ALR);
|
|
rtc_disable_alarm();
|
|
|
|
return 0;
|
|
}
|
|
|