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

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