Difference between revisions of "RTOS Basics : Queue"
m |
m |
||
Line 93: | Line 93: | ||
:portTickType xTicksToWait) | :portTickType xTicksToWait) | ||
|- | |- | ||
− | | Input Arguments ||xQueueHandle : handle to the queue in which data is to be posted | + | | Input Arguments || |
+ | #xQueueHandle : handle to the queue in which data is to be posted | ||
#const void * : pointer to the item to be posted | #const void * : pointer to the item to be posted | ||
#portTickType : the max amount of time for which task will wait for a space to become available on the queue if queue is full | #portTickType : the max amount of time for which task will wait for a space to become available on the queue if queue is full | ||
Line 104: | Line 105: | ||
xQueueSendToBack(MyQueueHandleId,TxBuffer,100) | xQueueSendToBack(MyQueueHandleId,TxBuffer,100) | ||
− | |} | + | |} |
− | + | ||
====Receiving data from the queue==== | ====Receiving data from the queue==== |
Revision as of 16:02, 14 April 2015
Amruta (talk) 15:58, 14 April 2015 (IST)
Contents
Intro
A queue is a FIFO (First In First Out) type buffer where data is written to the end (tail) of the queue and removed from the front (head) of the queue. It is also possible to write to the front of a queue.
A queue can either hold the data or pointer to the data. In FreeRTOS, the data items are directly copied to the queue. Each data item is of fixed size. The size of data item and maximum number of data items are fixed when queue is created.
Operations on queue
- Create
- Read
- In read operation, the data item is returned. If queue is empty the requesting task will wait for specified time.If multiple tasks are waiting, then data item will be returned to the either highest priority task or the one which made the request first depending upon RTOS implementation.For the second case waiting list is maintained with each queue. In FreeRTOS, queue is implemented in FIRST way.
- Write(Pend)
- In write operation, the data item is directly copied to queue. If queue is full the requesting task will wait for specified time. For multiple tasks in waite state, process is same as read operation.
API Details
Defination | xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength,
|
Input Arguments |
|
Return Value | xQueueHandle : NULL when queue is not created
Non NULL when queue is created. |
Description | It creates queue. |
Usage | xQueueHandle MyQueueHandleId;
MyQueueHandleId = xQueueCreate(3,20); |
Writting data to the queue
Defination | portBASE_TYPE xQueueSend(
|
Description | It is equivalent to xQueueSendToBack(). |
Usage | char TxBuffer[MaxElementsPerQueue]={"Hello world"};
xQueueSend(MyQueueHandleId,TxBuffer,100) |
Writting data at the front of queue
Defination | portBASE_TYPE xQueueSendToFront( xQueueHandle xQueue,
|
Input Arguments |
|
Return Value | returns TRUE on successfully posting the item else FALSE |
Description | It posts item at the back of the queue. |
Usage | char TxBuffer[MaxElementsPerQueue]={"Hello world"};
xQueueSendToFront(MyQueueHandleId,TxBuffer,100) |
Writting data at the back of queue
Defination | portBASE_TYPE xQueueSendToBack( xQueueHandle xQueue,
|
Input Arguments |
|
Return Value | returns TRUE on successfully posting the item else FALSE |
Description | It posts item at the front of the queue. |
Usage | char TxBuffer[MaxElementsPerQueue]={"Hello world"};
xQueueSendToBack(MyQueueHandleId,TxBuffer,100) |
Receiving data from the queue
Defination | portBASE_TYPE xQueueReceive(xQueueHandle xQueue,
|
Input Arguments | #xQueueHandle : handle to the queue in which data write is desired.
|
Return Value | returns TRUE on successfully posting the item else FALSE |
Description | |
Usage | char RxBuffer[MaxElementsPerQueue];
xQueueReceive(MyQueueHandleId,RxBuffer,100); |