Quality RTOS & Embedded Software

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


Queue Overwrite with more than 1 item

Posted by celephicus1 on September 22, 2014

Before using FreeRTOS I used a simple ring buffer to hold a trace of information, arranged so that if it filled new items would overwrite the oldest, so I always had the newest information if they were written before they can be read. What is the easiest way of implementing this in FreeRTOS, by checking if the queue is ful and then eleting the oldest item before inserting a new one? Or I could just use a semaphore with my existing ring buffer code.

Queue Overwrite with more than 1 item

Posted by heinbali01 on September 23, 2014

Hi Tom,

For tracing, I would keep on using the ring buffer because it is 'lite'.

Here's another example:


which can easily be used during an ISR.

For 'real-time' tracing, I would prefer to occasionally lose a message rather than protect every trace action with a semaphore.

But if you want to use queues, that is possible of course. Note that a queue could either store characters (which is 'expensive') or pointers to messages. And also the caller will have to make sure that there is space by removing an old message if it is full... and action which could also be protected by a semaphore...

Regards, Hein

Queue Overwrite with more than 1 item

Posted by celephicus1 on September 24, 2014

Thanks for the answer, the post you pointed to provided the answers. I shall use my lightweight ringbuffer implementation, with protection whilst I modify the buffer pointers with a critical section, that will disable interrupts for a few cycles only. FreeRTOS queues are far too heavy a solution for just logging a few events. I don't need to log in interrupts, only in tasks, but the critical sections will prevent a task switch in the middle of modifying the ring buffer pointers.

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

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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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

Xilinx Microblaze and Zynq partner