xico2004 wrote on Tuesday, August 18, 2015:
Hi there
I am new to this forum and I am already bring some problems that I have been facing while exploring FreeRTOS on my STM32F4:
I want to pass a simple structure from one task to anoder. Actually am I followyig by the book (I think…) what is told on FreeRTOS API suport:
This is shortest example fo what I am doing:
#define WHEEL_PERIMETER 100
struct ENCODER_Motion
{
float Current_Speed;
float Current_Direction;
} ENCODER_MOTION_Read;
QueueHandle_t xQueueENCODER_Readings;
int main (void)
{
... Initiate system configuration ...
xQueueENCODER_Readings = xQueueCreate( 10 , sizeof( struct ENCODER_Motion* ) );
if ( xQueueENCODER_Readings == 0)
... flags with a flashing led;
... creates Task_A and Task_B and lauches scheduler....
while (1);
}
void Task:A ( void *pvParameters )
{
struct ENCODER_Motion *ENCODER_MOTION_NOW;
float RPM ;
float DIRECTION ;
while (1)
{
... Reads Encoder to RPM and DIRECTION ...
ENCODER_MOTION_Read.Current_Speed = RPM * WHEEL_PERIMETER;
ENCODER_MOTION_Read.Current_Direction = DIRECTION;
if ( xQueueENCODER_Readings != 0 )
{
ENCODER_MOTION_NOW = &ENCODER_MOTION_Read;
xQueueSend ( xQueueENCODER_Readings , (void *) &ENCODER_MOTION_NOW ,
(TickType) 10 );
}
}
void Task:B ( void *pvParameters )
{
struct ENCODER_Motion *ENCODER_Received;
float SPEED_RECEIVED;
float DIRCTION_RECEIVED;
while (1)
{
if ( xQueueENCODER_Readings )
{
if ( uxQueueMessagesWaiting ( xQueueENCODER_Readings ) )
{
if (xQueueReceive ( xQueueENCODER_Readings , &(ENCODER_Received) ,
QUEUE_TIME_TO_WAIT_10 ) );
{
SPEED_RECEIVED = ENCODER_Received->Current_Speed;
DIRCTION_RECEIVED = ENCODER_Received->Current_Direction;
}
}
}
}
My problems that; passing the struck though the queue or not (not calling the xQueueSend on Task_A) I still receive on TASK_B the information saved at this point of may code
ENCODER_MOTION_Read.Current_Speed = RPM * WHEEL_PERIMETER;
ENCODER_MOTION_Read.Current_Direction = DIRECTION;
It seems I am saving the data on a Global variable (structure) and not sending a pointer to a strcuture - one of the 10 that was created when I called xQueueCreat.
I tryed not using pointer on the TASK_B but it receives trash.
Any help will be highly appreciated
Thanks