In your code you are only creating one structure, then sending pointers to that one structure through the queue. All the pointers will be pointing to the same structure, and reading anything out from the structure will result in whatever value was last written to the structure by any task (all tasks are accessing the same one). Is this correct?
If the structure is small you might be better of sending the structure itself, so each time you send the structure to the queue you send a copy of a strcture, rather than a pointer to a single structure. So the queue would be created as:
// The * has been removed
xQueueENCODER
Readings = xQueueCreate( 10 , sizeof( struct ENCODERMotion) );
Then Task a can do this to send a copy of its local variable, rather than a pointer to it, to the queue
void Task:A ( void *pvParameters )
{
struct ENCODER_Motion ENCODER_MOTION_NOW;
for( ;; )
{
ENCODER_MOTION_NOW.Current_Speed = // whatever
ENCODER_MOTION_NOW.Current_Direction = // whatever
// Send a copy of the queue to the other task.
xQueueSend ( xQueueENCODER_Readings ,
(void *) &ENCODER_MOTION_NOW ,
(TickType) 10 );
// Reset of code follows
And Task B can receive a copy into its own local variable, as follows:
void Task:B ( void *pvParameters )
{
struct ENCODER_Motion ENCODER_Received;
while (1)
{
if (xQueueReceive ( xQueueENCODER_Readings ,
&(ENCODER_Received) ,
QUEUE_TIME_TO_WAIT_10 ) );
// Reset of code follows
I think if you wanted to queue pointers, maybe for efficiency reasons, then you would have to have a set of structures available that could be pointed to, so no two tasks point to the same structure at the same time – or perhaps dynamically allocate a structure then send a pointer to the dynamically allocated structure, and have the receiving task free the dynamically allocated structure again after it has received it.
Regards.