Passing a queue to an external function

Hello! Maybe my question is a little weird, but anyways.
I’ve got a project with three tasks and four queues.
TaskB and TaskC only need to communicate with TaskA.

TaskA, TaskB, TaskC
QueueAtoB, QueueAtoC, QueueBtoA, QueueCtoA

To keep my tasks kind of slim I’ve included my functions with a header.
I then call the needed function and pass a pointer to my task-variable.
Works fine for me.

Now i wanted to write a function, which should tace care of a queue.
I want to call the function from maybe TaskC and hand over the queue handle.
Something like this:

bool reactToQueue(QueueHandle_t *QueueCtoA, int x, int y,…){
_____char *myPointer;
_____if (xQueueReceive( QueueCtoA,
______________________ &myPointer,
______________________(TickType_t) 10) == pdPASS) {
___________…do stuff with x and y…

In the header I included the <FreeRTOS.h> and the <queue.h>.

I implemented the queue with

QueueHandle_t QueueCtoA;

In the task I call the function with

reactToQueue(&QueueCtoA, int x, int y);

Trying this always ends up with blocking my whole uC. :slightly_frowning_face:

Is it possible to hand over a queue to an external function?
If so - what am I doing wrong?

Thanks in advance!

Pass the Queue handles by value, they are simple values. reactToQueue should have as a parameter a QueueHandle_t, not a QueueHandle_t*.

If you really want to pass pointers to queue handles, then the function could be

bool reactTOueue*QueueHandle_t *pQueueCtoA, …){
… if(xQueueReceive(*pQueueCtoA, &myPointer, …)

You aren’t getting the compile errors that could be created as for backwards compatibility reasons, all handles are defined on user side as just void* pointers, which ways that you could pass any sort of pointer there, not just the right type of handle.

1 Like