I enabled the input capture of the IEEE1588, with the associated interrupt (ENET_1588_Timer_IRQn).
The priority is higher (1) than the ENET_IRQn interrupt (6) which uses lwip calls, thus FreeRTOS.
Both interrupts though have the callback s_enetTsIsr, which is populated with ENET_TimeStampIRQHandler(). It, among other things, increments the seconds counter. It can happen that the ENET_1588_Timer_IRQn interrupt can preempt the ENET_IRQn interrupt. If this happens at the point indicated below, it happens that there is erroneously a double increment of seconds.
void ENET_TimeStampIRQHandler(ENET_Type *base, enet_handle_t *handle)
{
assert(handle != NULL);
/* Check if the PTP time stamp interrupt happen. */
if (0U != ((uint32_t)kENET_TsTimerInterrupt & base->EIR))
{
/* <--- if highr priority irq is triggered here we have a double increment of seconds */
/* Clear the time stamp interrupt. */
base->EIR = (uint32_t)kENET_TsTimerInterrupt;
/* Increase timer second counter. */
handle->msTimerSecond++;
My focus is on ENET_Ptp1588IRQHandler(), where I find these lines:
#if defined(ENET_ENHANCEDBUFFERDESCRIPTOR_MODE) && ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
/* In some platforms, the 1588 event uses same irq with timestamp event. */
if ((s_enetTsIrqId[instance] == s_enet1588TimerIrqId[instance]) && (s_enetTsIrqId[instance] != NotAvail_IRQn))
{
I wonder if RT105x is one of these platforms. In other words, assuming that the occasional double seconds increment is a bug, does it come from the fact that inside the ENET_Ptp1588IRQHandler() function shouldn't be called the s_enetTsIsr callback, or from the fact that the TimeStampIRQHandler() function is not safe for reentrant?
best regards
Max