passing a queuehandle_t pointer?

nigel-m wrote on Thursday, July 05, 2018:

I’m trying to create a queue to communicate between 2 tasks, But passing a pointer to a task seems to crash it.

The following code seems to work fine.

QueueHandle_t queue = xQueueCreate(10, sizeof(int);
if( uxQueueMessagesWaiting(queue) ) {
    // a message
} else {
    // no message
}

But having a pointer seems to let my program crash.

QueueHandle_t queue = xQueueCreate(10, sizeof(int);
QueueHandle_t *pqueue = &queue;
if( uxQueueMessagesWaiting(pqueue) ) {
    // a message
} else {
    // no message
}

which is the same as passing it to a task using pvparameters.

	void Thread(void *pvParameters)
	{
QueueHandle_t *handle = (QueueHandle_t*)pvParameters;
if( uxQueueMessagesWaiting(handle) ) {

What am i doing wrong, comparing my code to examples I dont see any strange difference.

rtel wrote on Thursday, July 05, 2018:

QueueHandle_t queue = xQueueCreate(10, sizeof(int);
if( uxQueueMessagesWaiting(queue) ) {
// a message
} else {
// no message
}

In this case, the type of the parameter you are passing to
uxQueueMessagesWaiting() is a QueueHandle_t, which is correct.

But having a pointer seems to let my program crash.

QueueHandle_t queue = xQueueCreate(10, sizeof(int);
QueueHandle_t *pqueue = &queue;
if( uxQueueMessagesWaiting(pqueue) ) {
// a message
} else {
// no message
}

In this case, the type of the parameter you are passing to
uxQueueMessagesWaiting() is a pointer to a QueueHandle_t, which is not
correct.

which is the same as passing it to a task using pvparameters.

If you want to pass a QueueHandle_t into another task using the task
parameter then pass it directly, as a value. For example:

xTaskCreate( a, b, c, ( void * ) queue, x, y, z );

Then just cast it back to a QueueHandle_t within the created task.

Alternatively you could pass a pointer to the queue, then deference the
pointer at the other end to get back to the queue, but that is not
necessary.

[this is a C question really]

nigel-m wrote on Thursday, July 05, 2018:

Doh, I was thinking way to hard on this one.
Thx for the great answer!