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] [October 2008 Threads] Best way to use FreeRTOS message systemPosted by Grant Brown on October 22, 2008 Hi List
I have the following function that is designed to send a message via the FreeRTOS message system to my I2C module.
It then waits until the message has been processed and then retrieves the results.
My question is,
Is this the best way in which to do this or is there a better more efficient way in which to achieve the above function.
void Load_Current_I2C_GPO_Register(void) { I2C_CmdMsg TheMsgStruct; I2C_CmdMsg *TheMsgPtr;
TheMsgStruct.I2C_Status = I2C_DoCmd; // set the command status
TheMsgPtr = &TheMsgStruct; // create a pointer to the message structure
if (xQueueSendToBack( TheI2C_Queue, ( void * ) TheMsgPtr, ( portTickType ) 10 )!= pdPASS) SPI_DtaMessage->I2C_Status = I2C_CmdError;// message did not get posted else { // the message was posted successfully // wait until the I2C command has been processed while(TheMsgStruct.I2C_Status == I2C_DoCmd); // Load the new GPO register data from the message structure GPO_0_Byte = TheMsgStruct.Byte_1; GPO_1_Byte = TheMsgStruct.Byte_1; SPI_DtaMessage->I2C_Status = I2C_CmdDone; } }
Kind Regards Grant Brown
RE: Best way to use FreeRTOS message systemPosted by Dave on October 22, 2008 Without examining too much a couple of points.
Be careful passing a pointer to a stack variable. In this case it is fine as the variable remains valid until after you have waited for the result.
You are polling for the result which will only work in the task processing the message has a higher priority than the task running this code. Consider using a blocking mechanism like a semaphore, that will put task to sleep until there is actually some processing to do. That would be much more efficient.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|