FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [November 2005 Threads] 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|