mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #4453 from c1728p9/lp_ticker_fix
Safely initialize RTC on kinetis devicespull/3506/merge
commit
01e4520548
|
@ -33,16 +33,26 @@ static int lptmr_schedule = 0;
|
|||
|
||||
static void rtc_isr(void)
|
||||
{
|
||||
RTC_DisableInterrupts(RTC, kRTC_AlarmInterruptEnable);
|
||||
RTC->TAR = 0; /* Write clears the IRQ flag */
|
||||
uint32_t sr = RTC->SR;
|
||||
if (sr & RTC_SR_TOF_MASK) {
|
||||
// Reset RTC to 0 so it keeps counting
|
||||
RTC_StopTimer(RTC);
|
||||
RTC->TSR = 0;
|
||||
RTC_StartTimer(RTC);
|
||||
} else if (sr & RTC_SR_TAF_MASK) {
|
||||
RTC_DisableInterrupts(RTC, kRTC_AlarmInterruptEnable);
|
||||
RTC->TAR = 0; /* Write clears the IRQ flag */
|
||||
|
||||
/* Wait subsecond remainder if any */
|
||||
if (lptmr_schedule) {
|
||||
LPTMR_SetTimerPeriod(LPTMR0, lptmr_schedule);
|
||||
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
|
||||
LPTMR_StartTimer(LPTMR0);
|
||||
} else {
|
||||
lp_ticker_irq_handler();
|
||||
/* Wait subsecond remainder if any */
|
||||
if (lptmr_schedule) {
|
||||
LPTMR_SetTimerPeriod(LPTMR0, lptmr_schedule);
|
||||
LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
|
||||
LPTMR_StartTimer(LPTMR0);
|
||||
} else {
|
||||
lp_ticker_irq_handler();
|
||||
}
|
||||
} else if (sr & RTC_SR_TIF_MASK) {
|
||||
RTC_DisableInterrupts(RTC, kRTC_TimeOverflowInterruptEnable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +83,7 @@ void lp_ticker_init(void)
|
|||
RTC_StartTimer(RTC);
|
||||
}
|
||||
|
||||
RTC->TAR = 0; /* Write clears the IRQ flag */
|
||||
NVIC_ClearPendingIRQ(RTC_IRQn);
|
||||
NVIC_SetVector(RTC_IRQn, (uint32_t)rtc_isr);
|
||||
NVIC_EnableIRQ(RTC_IRQn);
|
||||
|
|
Loading…
Reference in New Issue