uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
queue.h
Go to the documentation of this file.
1 /*
2  FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
3  All rights reserved
4 
5  VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6 
7  ***************************************************************************
8  * *
9  * FreeRTOS provides completely free yet professionally developed, *
10  * robust, strictly quality controlled, supported, and cross *
11  * platform software that has become a de facto standard. *
12  * *
13  * Help yourself get started quickly and support the FreeRTOS *
14  * project by purchasing a FreeRTOS tutorial book, reference *
15  * manual, or both from: http://www.FreeRTOS.org/Documentation *
16  * *
17  * Thank you! *
18  * *
19  ***************************************************************************
20 
21  This file is part of the FreeRTOS distribution.
22 
23  FreeRTOS is free software; you can redistribute it and/or modify it under
24  the terms of the GNU General Public License (version 2) as published by the
25  Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
26 
27  >>! NOTE: The modification to the GPL is included to allow you to distribute
28  >>! a combined work that includes FreeRTOS without being obliged to provide
29  >>! the source code for proprietary components outside of the FreeRTOS
30  >>! kernel.
31 
32  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34  FOR A PARTICULAR PURPOSE. Full license text is available from the following
35  link: http://www.freertos.org/a00114.html
36 
37  1 tab == 4 spaces!
38 
39  ***************************************************************************
40  * *
41  * Having a problem? Start by reading the FAQ "My application does *
42  * not run, what could be wrong?" *
43  * *
44  * http://www.FreeRTOS.org/FAQHelp.html *
45  * *
46  ***************************************************************************
47 
48  http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49  license and Real Time Engineers Ltd. contact details.
50 
51  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53  compatible FAT file system, and our tiny thread aware UDP/IP stack.
54 
55  http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56  Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
57  licenses offer ticketed support, indemnification and middleware.
58 
59  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60  engineered and independently SIL3 certified version for use in safety and
61  mission critical applications that require provable dependability.
62 
63  1 tab == 4 spaces!
64 */
65 
66 
67 #ifndef QUEUE_H
68 #define QUEUE_H
69 
70 #ifndef INC_FREERTOS_H
71  #error "include FreeRTOS.h" must appear in source files before "include queue.h"
72 #endif
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 
84 typedef void * xQueueHandle;
85 
91 typedef void * xQueueSetHandle;
92 
98 typedef void * xQueueSetMemberHandle;
99 
100 /* For internal use only. */
101 #define queueSEND_TO_BACK ( ( portBASE_TYPE ) 0 )
102 #define queueSEND_TO_FRONT ( ( portBASE_TYPE ) 1 )
103 #define queueOVERWRITE ( ( portBASE_TYPE ) 2 )
104 
105 /* For internal use only. These definitions *must* match those in queue.c. */
106 #define queueQUEUE_TYPE_BASE ( ( unsigned char ) 0U )
107 #define queueQUEUE_TYPE_SET ( ( unsigned char ) 0U )
108 #define queueQUEUE_TYPE_MUTEX ( ( unsigned char ) 1U )
109 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( unsigned char ) 2U )
110 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( unsigned char ) 3U )
111 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( unsigned char ) 4U )
112 
169 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
170 
251 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
252 
333 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
334 
417 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
418 
500 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
501 
502 
588 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;
589 
684 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
685 
717 signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION;
718 
810 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
811 
812 
909 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek ) PRIVILEGED_FUNCTION;
910 
924 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
925 
941 unsigned portBASE_TYPE uxQueueSpacesAvailable( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
942 
955 void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
956 
1025 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1026 
1027 
1096 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1097 
1183 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1184 
1257 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1258 
1335 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;
1336 
1424 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1425 
1426 /*
1427  * Utilities to query queues that are safe to use from an ISR. These utilities
1428  * should be used only from witin an ISR, or within a critical section.
1429  */
1430 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1431 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1432 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1433 
1434 
1435 /*
1436  * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
1437  * Likewise xQueueAltGenericReceive() is an alternative version of
1438  * xQueueGenericReceive().
1439  *
1440  * The source code that implements the alternative (Alt) API is much
1441  * simpler because it executes everything from within a critical section.
1442  * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
1443  * preferred fully featured API too. The fully featured API has more
1444  * complex code that takes longer to execute, but makes much less use of
1445  * critical sections. Therefore the alternative API sacrifices interrupt
1446  * responsiveness to gain execution speed, whereas the fully featured API
1447  * sacrifices execution speed to ensure better interrupt responsiveness.
1448  */
1449 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
1450 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
1451 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
1452 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
1453 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
1454 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
1455 
1456 /*
1457  * The functions defined above are for passing data to and from tasks. The
1458  * functions below are the equivalents for passing data to and from
1459  * co-routines.
1460  *
1461  * These functions are called from the co-routine macro implementation and
1462  * should not be called directly from application code. Instead use the macro
1463  * wrappers defined within croutine.h.
1464  */
1465 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
1466 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
1467 signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait );
1468 signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );
1469 
1470 /*
1471  * For internal use only. Use xSemaphoreCreateMutex(),
1472  * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1473  * these functions directly.
1474  */
1475 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION;
1476 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION;
1477 void* xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION;
1478 
1479 /*
1480  * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1481  * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1482  */
1483 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION;
1485 
1486 /*
1487  * Reset a queue back to its original empty state. pdPASS is returned if the
1488  * queue is successfully reset. pdFAIL is returned if the queue could not be
1489  * reset because there are tasks blocked on the queue waiting to either
1490  * receive from the queue or send to the queue.
1491  */
1492 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1493 
1494 /*
1495  * The registry is provided as a means for kernel aware debuggers to
1496  * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1497  * a queue, semaphore or mutex handle to the registry if you want the handle
1498  * to be available to a kernel aware debugger. If you are not using a kernel
1499  * aware debugger then this function can be ignored.
1500  *
1501  * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1502  * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1503  * within FreeRTOSConfig.h for the registry to be available. Its value
1504  * does not effect the number of queues, semaphores and mutexes that can be
1505  * created - just the number that the registry can hold.
1506  *
1507  * @param xQueue The handle of the queue being added to the registry. This
1508  * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1509  * handles can also be passed in here.
1510  *
1511  * @param pcName The name to be associated with the handle. This is the
1512  * name that the kernel aware debugger will display.
1513  */
1514 #if configQUEUE_REGISTRY_SIZE > 0
1515  void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName ) PRIVILEGED_FUNCTION;
1516 #endif
1517 
1518 /*
1519  * The registry is provided as a means for kernel aware debuggers to
1520  * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1521  * a queue, semaphore or mutex handle to the registry if you want the handle
1522  * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1523  * remove the queue, semaphore or mutex from the register. If you are not using
1524  * a kernel aware debugger then this function can be ignored.
1525  *
1526  * @param xQueue The handle of the queue being removed from the registry.
1527  */
1528 #if configQUEUE_REGISTRY_SIZE > 0
1529  void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1530 #endif
1531 
1532 /*
1533  * Generic version of the queue creation function, which is in turn called by
1534  * any queue, semaphore or mutex creation function or macro.
1535  */
1536 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION;
1537 
1538 /*
1539  * Queue sets provide a mechanism to allow a task to block (pend) on a read
1540  * operation from multiple queues or semaphores simultaneously.
1541  *
1542  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1543  * function.
1544  *
1545  * A queue set must be explicitly created using a call to xQueueCreateSet()
1546  * before it can be used. Once created, standard FreeRTOS queues and semaphores
1547  * can be added to the set using calls to xQueueAddToSet().
1548  * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1549  * or semaphores contained in the set is in a state where a queue read or
1550  * semaphore take operation would be successful.
1551  *
1552  * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1553  * for reasons why queue sets are very rarely needed in practice as there are
1554  * simpler methods of blocking on multiple objects.
1555  *
1556  * Note 2: Blocking on a queue set that contains a mutex will not cause the
1557  * mutex holder to inherit the priority of the blocked task.
1558  *
1559  * Note 3: An additional 4 bytes of RAM is required for each space in a every
1560  * queue added to a queue set. Therefore counting semaphores that have a high
1561  * maximum count value should not be added to a queue set.
1562  *
1563  * Note 4: A receive (in the case of a queue) or take (in the case of a
1564  * semaphore) operation must not be performed on a member of a queue set unless
1565  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1566  *
1567  * @param uxEventQueueLength Queue sets store events that occur on
1568  * the queues and semaphores contained in the set. uxEventQueueLength specifies
1569  * the maximum number of events that can be queued at once. To be absolutely
1570  * certain that events are not lost uxEventQueueLength should be set to the
1571  * total sum of the length of the queues added to the set, where binary
1572  * semaphores and mutexes have a length of 1, and counting semaphores have a
1573  * length set by their maximum count value. Examples:
1574  * + If a queue set is to hold a queue of length 5, another queue of length 12,
1575  * and a binary semaphore, then uxEventQueueLength should be set to
1576  * (5 + 12 + 1), or 18.
1577  * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1578  * should be set to (1 + 1 + 1 ), or 3.
1579  * + If a queue set is to hold a counting semaphore that has a maximum count of
1580  * 5, and a counting semaphore that has a maximum count of 3, then
1581  * uxEventQueueLength should be set to (5 + 3), or 8.
1582  *
1583  * @return If the queue set is created successfully then a handle to the created
1584  * queue set is returned. Otherwise NULL is returned.
1585  */
1586 xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength ) PRIVILEGED_FUNCTION;
1587 
1588 /*
1589  * Adds a queue or semaphore to a queue set that was previously created by a
1590  * call to xQueueCreateSet().
1591  *
1592  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1593  * function.
1594  *
1595  * Note 1: A receive (in the case of a queue) or take (in the case of a
1596  * semaphore) operation must not be performed on a member of a queue set unless
1597  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1598  *
1599  * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1600  * the queue set (cast to an xQueueSetMemberHandle type).
1601  *
1602  * @param xQueueSet The handle of the queue set to which the queue or semaphore
1603  * is being added.
1604  *
1605  * @return If the queue or semaphore was successfully added to the queue set
1606  * then pdPASS is returned. If the queue could not be successfully added to the
1607  * queue set because it is already a member of a different queue set then pdFAIL
1608  * is returned.
1609  */
1610 portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;
1611 
1612 /*
1613  * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1614  * be removed from a set if the queue or semaphore is empty.
1615  *
1616  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1617  * function.
1618  *
1619  * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1620  * from the queue set (cast to an xQueueSetMemberHandle type).
1621  *
1622  * @param xQueueSet The handle of the queue set in which the queue or semaphore
1623  * is included.
1624  *
1625  * @return If the queue or semaphore was successfully removed from the queue set
1626  * then pdPASS is returned. If the queue was not in the queue set, or the
1627  * queue (or semaphore) was not empty, then pdFAIL is returned.
1628  */
1629 portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;
1630 
1631 /*
1632  * xQueueSelectFromSet() selects from the members of a queue set a queue or
1633  * semaphore that either contains data (in the case of a queue) or is available
1634  * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1635  * allows a task to block (pend) on a read operation on all the queues and
1636  * semaphores in a queue set simultaneously.
1637  *
1638  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1639  * function.
1640  *
1641  * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1642  * for reasons why queue sets are very rarely needed in practice as there are
1643  * simpler methods of blocking on multiple objects.
1644  *
1645  * Note 2: Blocking on a queue set that contains a mutex will not cause the
1646  * mutex holder to inherit the priority of the blocked task.
1647  *
1648  * Note 3: A receive (in the case of a queue) or take (in the case of a
1649  * semaphore) operation must not be performed on a member of a queue set unless
1650  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1651  *
1652  * @param xQueueSet The queue set on which the task will (potentially) block.
1653  *
1654  * @param xBlockTimeTicks The maximum time, in ticks, that the calling task will
1655  * remain in the Blocked state (with other tasks executing) to wait for a member
1656  * of the queue set to be ready for a successful queue read or semaphore take
1657  * operation.
1658  *
1659  * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1660  * a xQueueSetMemberHandle type) contained in the queue set that contains data,
1661  * or the handle of a semaphore (cast to a xQueueSetMemberHandle type) contained
1662  * in the queue set that is available, or NULL if no such queue or semaphore
1663  * exists before before the specified block time expires.
1664  */
1665 xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks ) PRIVILEGED_FUNCTION;
1666 
1667 /*
1668  * A version of xQueueSelectFromSet() that can be used from an ISR.
1669  */
1670 xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;
1671 
1672 /* Not public API functions. */
1673 void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
1674 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION;
1675 void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;
1676 unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1677 unsigned char ucQueueGetQueueType( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1678 
1679 
1680 #ifdef __cplusplus
1681 }
1682 #endif
1683 
1684 #endif /* QUEUE_H */
1685