Implement bkp's rtc alarm configuration
Since the alarm must be set each time it is to be used, a separated function is a better fit
This commit is contained in:
parent
7ab6622908
commit
24e412446d
25
drv/bkp.c
25
drv/bkp.c
@ -33,7 +33,7 @@ static BkpRtcCallback rtc_callback;
|
||||
//--public functions------------------------------------------------------------
|
||||
|
||||
void bkp_configure_rtc(uint32_t period_ms, enum BkpRtcClockSrc clock_src,
|
||||
enum BkpRtcIrq irq_mask, uint32_t alarm_tick, BkpRtcCallback callback)
|
||||
enum BkpRtcIrq irq_mask, BkpRtcCallback callback)
|
||||
{
|
||||
rcc_enable(RCC_AHB_NONE, RCC_APB1_BKP, RCC_APB2_NONE);
|
||||
|
||||
@ -55,8 +55,6 @@ void bkp_configure_rtc(uint32_t period_ms, enum BkpRtcClockSrc clock_src,
|
||||
//configure core registers
|
||||
rtc_regs->PRLH.PRL = prescaler >> 16;
|
||||
rtc_regs->PRLL.PRL = prescaler;
|
||||
rtc_regs->ALRH.RTC_ALR = alarm_tick >> 16;
|
||||
rtc_regs->ALRL.RTC_ALR = alarm_tick;
|
||||
|
||||
//apply irq config
|
||||
rtc_regs->CRH.word |= irq_mask & 0x7;
|
||||
@ -73,6 +71,27 @@ void bkp_configure_rtc(uint32_t period_ms, enum BkpRtcClockSrc clock_src,
|
||||
}
|
||||
}
|
||||
|
||||
void bkp_set_rtc_alam(uint32_t offset)
|
||||
{
|
||||
uint32_t alarm = bkp_read_rtc() + offset;
|
||||
|
||||
//wait for last operation to finish
|
||||
while (rtc_regs->CRL.RTOFF != 1) {}
|
||||
|
||||
//enable core configuration
|
||||
rtc_regs->CRL.CNF = 1;
|
||||
|
||||
//write alarm value
|
||||
rtc_regs->ALRH.RTC_ALR = alarm >> 16;
|
||||
rtc_regs->ALRL.RTC_ALR = alarm;
|
||||
|
||||
//disable/apply core configuration
|
||||
rtc_regs->CRL.CNF = 0;
|
||||
|
||||
//wait for last operation to finish
|
||||
while (rtc_regs->CRL.RTOFF != 1) {}
|
||||
}
|
||||
|
||||
uint32_t bkp_read_rtc(void)
|
||||
{
|
||||
//wait for core registers to be synchronized, immediate most of the time
|
||||
|
||||
15
drv/bkp.h
15
drv/bkp.h
@ -63,14 +63,23 @@ typedef void (*BkpRtcCallback)(enum BkpRtcIrq src);
|
||||
* Clocks must be enabled prior to calling this function
|
||||
*
|
||||
* Mulitple IRQs can be enabled and redirected to single callback. The alarm
|
||||
* IRQ, triggered at the specified tick value can be rerouted to an exti line
|
||||
* for wakeup from stanby, in wich case it doesn't need to be enabled here.
|
||||
* IRQ, triggered at the tick value specified by bkp_set_rtc_alam() can be
|
||||
* rerouted to an exti line for wakeup from stop and standby, in wich case it
|
||||
* doesn't need to be enabled here.
|
||||
*
|
||||
* Ensure backup domain writes are enabled (see pwr_configure_bkp_write()) while
|
||||
* calling this function
|
||||
*/
|
||||
void bkp_configure_rtc(uint32_t period_ms, enum BkpRtcClockSrc clock_src,
|
||||
enum BkpRtcIrq irq_mask, uint32_t alarm_tick, BkpRtcCallback callback);
|
||||
enum BkpRtcIrq irq_mask, BkpRtcCallback callback);
|
||||
|
||||
/**
|
||||
* Configure the alarm to trigger after the specified time in ticks, which can
|
||||
* be viewed as an offset to the current time value. This offset is only precise
|
||||
* to the tick and thus if the tick changes right after this function is
|
||||
* called, the observed offset will be close to 1 tick short
|
||||
*/
|
||||
void bkp_set_rtc_alam(uint32_t offset);
|
||||
|
||||
/**
|
||||
* Returns the current counter value of the RTC
|
||||
|
||||
Loading…
Reference in New Issue
Block a user