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

Queues and compiler optimization (GCC)

Posted by Luca Bassanello on September 29, 2006
Hi all,

I had a bunch of problems with FreeRTOS queues in my MCU serial communication. I've made the H8S-2633 port of FreeRTOS (if someone is interested I can upload it somewhere), and started
my project with a modified version of serial.c of GCC H8S2329 demo example. In my application, the serial port is "hammered" with a protocol packets, and sometimes data byte inserted in queue (from serial RX ISR) with xQueueSendFromISR was "lost" in the queue itself ( or "delayed" of some positions inside the queue ). This because uxMessagesWaiting, uxLength and uxItemSize aren't
updated in compilation level with -O2 parameter.

The solution is modify QueueDefinition in queue.c like this :

volatile unsigned portBASE_TYPE uxMessagesWaiting;
volatile unsigned portBASE_TYPE uxLength;
volatile unsigned portBASE_TYPE uxItemSize;

I hope this solution can be useful :)

Luca

RE: Queues and compiler optimization (GCC)

Posted by Nobody/Anonymous on September 29, 2006
Why just those three members? This would seem to also apply to the pcWriteTo, pcReadFrom, xRxLock and xTxLock members?

RE: Queues and compiler optimization (GCC)

Posted by Nobody/Anonymous on September 29, 2006
Why would the optimizer not change them?

uxLength is set once when the queue is created. It is set at the same time as all the other members so if it were not set I would not expect any of the other members to be set either. The structure being created is passed back as the return value so the optimizer cannot guess how the values are used so should do what the C code says.

Likewise of uxItemSize.

Messages waiting is a bit different. This is set and tested from both task level and ISR level. However it is only ever accessed via a pointer parameter, so again the optimizer cannot determine how the set value is used, if at all, so should do what the C code says.

RE: Queues and compiler optimization (GCC)

Posted by Luca Bassanello on September 29, 2006
Probably the "volatile" key isn't need in all three members, in my spare time I can investigate more deeply. Anyway these changes at QueueDefinition structure, resolved my all my communication problems...

RE: Queues and compiler optimization (GCC)

Posted by Nobody/Anonymous on September 29, 2006
Maybe some of the parameters need to be declared volatile as

portBASE_TYPE xQueueSend( volatile portBASE_TYPE xQueueHandle xQueue, const void * pvItemToQueue, portTickType xTicksToWait );

Although I think maybe this is a red herring and that it is a GCC peculiarity. I used VxWorks/GCC once and had to turn off certain optimization options to get that to work. Never found the actual problem, just removing which option made the problem go away.


[ 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