In a simple 2 task example, with one task sending items to a freeRTOS queue and the other receiving. The first call to xQueueReceive() always returns pdFALSE, even before the other task calls xQueueSendToBack(). After that it seems to be working. But why is it returning on the first call - that is totally unexpected. I even added xQueueReset() immediately after xQueueCreate() but still get the return from xQueueReceive the first call like its a timeout
The outline of the code looks like this:
#define TX_PRI (tskIDLE_PRIORITY + 2)
#define RX_PRI (tskIDLE_PRIORITY + 3)
typedef struct
{
unsigned int n[20];
}Msg;
taskInit()
{
myQ = xQueueCreate(20, sizeof(Msg));
xQueueReset(myQ);
xTaskCreate(sendTask, STACKSIZE, NULL, TX_PRI, NULL);
xTaskCreate(receiveTask, STACKSIZE, NULL, RX_PRI, NULL);
...
}
void sendTask( void *arg)
{
...
for(;;)
{
vTaskDelay(100);
testmsg(&msg);
xQueueSendToBack(myQ, &msg, 2);
}
}
void receiveTask(void *arg)
{
Msg msg;
BaseType_t status;
vtaskDelay(10);
for(;;)
{
status = xQueueReceive(myQ, &msg, portMAX_DELAY);
if(status == pdTRUE)
{
// receive returns normally for each msg sent after 1st call
}
else
{
// receive returns as if timeout on first call, even though portMAX_DELAY used
}
}
}