int main( void )
{
// includes the RTC setup
prvSetupHardware();
NVIC_DisableIRQ(RTC_IRQn);
// C++ based xTaskCreate function
pearlrt::t_TASK3.activate()
NVIC_EnableIRQ(RTC_IRQn);
// set RTC second to 0
RTC_SetTime(LPC_RTC, RTC_TIMETYPE_SECOND, 0);
// throw alarm/interrupt on second 10
RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10);
/* Start the scheduler. */
vTaskStartScheduler();
/* IDLE task is used */
}
// --------- prvSetupHardware() ------------------
void prvSetupHardware( void )
{
[...]
// Enable RTC
init_RTC();
}
// --------- init_RTC()--------------------------
void init_RTC(void)
{
RTC_Init(LPC_RTC);
NVIC_DisableIRQ(RTC_IRQn);
NVIC_SetPriority(RTC_IRQn, ((0x01<<3)|0x01));
RTC_Cmd(LPC_RTC, ENABLE);
RTC_AlarmIntConfig (LPC_RTC, RTC_TIMETYPE_SECOND, ENABLE);
NVIC_EnableIRQ (RTC_IRQn);
}
// --------- RTC_IRQHandler() ---------------------
void RTC_IRQHandler()
{
if (RTC_GetIntPending(LPC_RTC, RTC_INT_ALARM))
{
debugMessage("Alarm");
// Clear pending interrupt
RTC_ClearIntPending(LPC_RTC, RTC_INT_ALARM);
}
}
FreeRTOS (NXP LPC1768) with RTC to throw an interrupt
Hi,
must something special be taken into account when using a RTC with FreeRTOS?
The code works fine without RTC. Once the RTC code is integrated to throw an alarm/interrupt, the system runs in a undefined state.
FreeRTOS (NXP LPC1768) with RTC to throw an interrupt
I don’t see you setting the interrupt priority BEFORE enabling it.
FreeRTOS (NXP LPC1768) with RTC to throw an interrupt
I was actually the opinion that the RTC must be reinitialized whenever the program (re-)starts but if I remove init_RTC() from prvSetupHardware(), everything works as expected. Reboot, reset the device, everything seems ok … weird!