FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [April 2014 Threads] Passing a function pointer in a message queuePosted by moto95 on April 3, 2014 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.
Passing a function pointer in a message queuePosted by dumarjo on April 3, 2014 Hi,
How the queue is created ?
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.
>
> ------------------------------------------------------------------------
>
> Passing a function pointer in a message queue
> https://sourceforge.net/p/freertos/discussion/382005/thread/bc70730a/?limit=25#5400
>
> ------------------------------------------------------------------------
>
> Sent from sourceforge.net because you indicated interest in
> https://sourceforge.net/p/freertos/discussion/382005/
>
> To unsubscribe from further messages, please visit
> https://sourceforge.net/auth/subscriptions/
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner http://www.mailscanner.info/, and is
> believed to be clean.
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com
Passing a function pointer in a message queuePosted by richard_damon on April 3, 2014 The big problem would be you need to pass to xQueueSend the address that contains a buffer with the data to send, NOT the value it self.
Thus you need something like
void (*MsgWaiting)();
MsgWaiting = &MsgFunction;
xQueueSend(xMsgQueue, MsgWaiting);
Passing a function pointer in a message queuePosted by moto95 on April 3, 2014 This is how I've attempted it. Using a PIC32, I assumed a function pointer would be 4 bytes long.
int QUEUELEN = 20;
int MsgIDBytes = 4;
xMsgQueue = xQueueCreate( QUEUELEN, MsgIDBytes );
Passing a function pointer in a message queuePosted by moto95 on April 3, 2014 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();
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|