Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists