Quality RTOS & Embedded Software

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


Loading

xQueuePeek() ?

Posted by Nobody/Anonymous on November 12, 2005
Hello everyone.

I am finding myself in need of a function to "peek" at the items in the queue (not restricted to only the first item), but without removing these items. I am trying to implement such a function.

To save myself some work, I am wondering if such a function has already been made by someone.

Also, I am wondering about which short-cuts I can take in the implementation. Peeking the queue will never block or unblock a task, and it will not change the queue itself.

Thanks in advance for any information.
Kind regards,
Thiadmer Riemersma

RE: xQueuePeek() ?

Posted by Nobody/Anonymous on November 12, 2005
The queue storage area is simply an array packed with sequential data items. If all you are doing is looking at what is in the queue then you can simply inspect pxQueue->pcReadFrom, then increment to the next item, wrapping where necessary. As you are not removing anything or effecting any task states then it should be simple.

Something like:

QueuePeak(aQueue)
{
void *Next

Next = aQueue->pcReadFrom;

// Move to the next itme.
Next += pxQueue->uxItemSize;

// Wrap if necessary.
if( pxQueue->pcReadFrom >= pxQueue->pcTail ) {
Next = pxQueue->pcHead;
}

// Next now points to the first item that would be
// removed from the queue.

// If you want the next item after then then
// simply jump over the item again, checking
// for a wrap.
Next += pxQueue->uxItemSize;
if( pxQueue->pcReadFrom >= pxQueue->pcTail ) {
Next = pxQueue->pcHead;
}

// Next now points to the second item that would
// be removed from the queue. As we are using
// the local variable Next, the queue itself is
// unchanged.
}

Of coarse you need to check how many items are actually in the queue, and take care of mutual exclusion to ensure an interrupt does not alter the queue as you are accessing it.




RE: xQueuePeek() ?

Posted by Nobody/Anonymous on November 13, 2005
Thanks.

This is basically what I implemented myself.

I was hoping to also be able to leave the queue unlocked, but in the general case, this is dangerous.

Thiadmer


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


Careers

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

Renesas

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