Merge pull request #4453 from c1728p9/lp_ticker_fix

Safely initialize RTC on kinetis devices
pull/3506/merge
Sam Grove 2017-06-07 09:58:49 -05:00 committed by GitHub
commit 01e4520548
1 changed files with 20 additions and 9 deletions

View File

@ -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);