Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Best way to use FreeRTOS message system

Posted 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 system

Posted 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS