I am trying to pass the pointer to a function via a message queue. The send/receive mechanism is working, i.e. the task waits on a message being received and unblocks when something is in the queue. However, I struggle to then execute the function that the queue contents points to.
Here is my send statement:
xQueueSend( xMsgQueue, ( void * ) &MsgFunction, 0 );
Here is my receive statement (inside the FreeRTOS task):
xQueueReceive( xMsgQueue, &(MsgWaiting), portMAX_DELAY );
And here is the dereferencing of the function pointer to actually call the function:
(*MsgWaiting)();
MsgWaiting is declared as:
void (*MsgWaiting) (void);
MsgFunction is declared as:
void MsgFunction (void);
However, the function never gets called. I’m sure it has something to do with the usage of pointers, or rather incorrect usage of pointers. Anyone mind to point out my mistake?
Jonathan
Le 2014-04-03 06:02, Felix Hirzel a écrit :
I am trying to pass the pointer to a function via a message queue. The
send/receive mechanism is working, i.e. the task waits on a message
being received and unblocks when something is in the queue. However, I
struggle to then execute the function that the queue contents points to.
Here is my send statement:
xQueueSend( xMsgQueue, ( void * ) &MsgFunction, 0 );
Here is my receive statement (inside the FreeRTOS task):
xQueueReceive( xMsgQueue, &(MsgWaiting), portMAX_DELAY );
And here is the dereferencing of the function pointer to actually call
the function:
(*MsgWaiting)();
MsgWaiting is declared as:
void (*MsgWaiting) (void);
MsgFunction is declared as:
void MsgFunction (void);
However, the function never gets called. I’m sure it has something to
do with the usage of pointers, or rather incorrect usage of pointers.
Anyone mind to point out my mistake?
Many thanks to Jonathan. I initially created the queue with only 2 bytes for the item size. Once correct to 4 bytes as per my post just above, it worked perfectly! So, it seems all my pointer handling was correct. Even the simpler de-referencing of the function pointer as follows worked equally well:
MsgWaiting();