BASICS: Task suspending

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

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
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.

The question above does not seem to match the piece of code you posted. Do you mean to say xQueueReceive? If so, it will not block as you are giving the block time as 0. Read the documentation of xTicksToWait parameter here: FreeRTOS - Open Source Software for Embedded Systems - FreeRTOS xQueueReceive() API function description and example


You’re right. I’m sorry. I’ve been interrupted here while writing this question.

Yes, this is clear. I’m afraid that’s not what I’m trying to ask.

The question is: If the queue is empty when the program reaches
if( xQueueReceive( xQ_1s000, &T_Chamada, 0)) {
callDelay = millis() - T_Chamada;
will this task (“xT_1s000”) suspend itself until some message is posted in the queue?

Again if you specify that you don”t want to wait/block (block time 0) you don’t.
That’s common sense in other OS, too.

Ok, I’ve been confusing blocked and suspended, so I went back to Developers Docs.

So, blocking won’t block the core in the means of keeping it stuck in this point of this task. It blocks only the task itself until the queue receives something or times out. Correct?

So, If blocking time is portMAX_DELAY then this task will unblock only when the queue receives a message. Correct? In other words, the placement of a message in this queue will trigger the task to continue.



Always useful to check the docs.