I’m new by FreeRTOS and I’d like to ask your help to understand it better.
Please let me address a few questions based on the piece of code below, running in a ESP32.
It regards a function (“xT_1s000”) that watches to a queue (“xQ_1s000”) fed by a timer triggered function (“Contagem”). The idea is that “Contagem()” catches millis() count and feeds it in the queue every second, so that “xT_1000” performs GPIO readings whenever the queue is fed. Initially, I’m just checking how long does it take for “xT_1000” to get ready, but that’s not the point.
…
timer = timerBegin(0, 80, true); // prescaler for 1µs
timerAttachInterrupt(timer, &Contagem, true);
timerAlarmWrite(timer, 1000000, true); // 1 second cyclical
timerAlarmEnable(timer);
…
IRAM_ATTR void Contagem() // triggered by timer interruption
{
…
xQueueSendFromISR(xQ_1s000, &millis_atual, &xHigherPriorityTaskWoken);
…
}
void xT_1s000(void *pvParameters) // checks queue every second
{
unsigned long T_Chamada = 0;
unsigned long callDelay = 0;
while(true) {
if( xQueueReceive( xQ_1s000, &T_Chamada, 0)) {
callDelay = millis() - T_Chamada;
Serial.printf("\n\t[Core %u]: TIMER - tempo de chamada = %lums, delay = %lums.", xPortGetCoreID(), T_Chamada, callDelay);
}
delay(1); // required to avoid WDT reset
}
}
Within this code, I’m assuming that function “xT_1000()” should get self suspended when it calls
xQueueReceive( xQ_1s000, &T_Chamada, 0);
and the queue is empty. Is it a correct assumption?
When I run this code, it is reset after a few cycles by the WDT. The way I found to keep it running was including
delay(1)
in order to force it idle. I don’t like this solution. It’s just a trick. Moreover, a 1ms delay in such function will make it cycle 999 times unnecessarily until the next time the queue is fed.
Is this the only solution?
Thank you.
Regards,
Ciro.