Robobo
queue.h
1 /*
2  FreeRTOS V8.2.3 - Copyright (C) 2015 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  This file is part of the FreeRTOS distribution.
8 
9  FreeRTOS is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License (version 2) as published by the
11  Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12 
13  ***************************************************************************
14  >>! NOTE: The modification to the GPL is included to allow you to !<<
15  >>! distribute a combined work that includes FreeRTOS without being !<<
16  >>! obliged to provide the source code for proprietary components !<<
17  >>! outside of the FreeRTOS kernel. !<<
18  ***************************************************************************
19 
20  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  FOR A PARTICULAR PURPOSE. Full license text is available on the following
23  link: http://www.freertos.org/a00114.html
24 
25  ***************************************************************************
26  * *
27  * FreeRTOS provides completely free yet professionally developed, *
28  * robust, strictly quality controlled, supported, and cross *
29  * platform software that is more than just the market leader, it *
30  * is the industry's de facto standard. *
31  * *
32  * Help yourself get started quickly while simultaneously helping *
33  * to support the FreeRTOS project by purchasing a FreeRTOS *
34  * tutorial book, reference manual, or both: *
35  * http://www.FreeRTOS.org/Documentation *
36  * *
37  ***************************************************************************
38 
39  http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40  the FAQ page "My application does not run, what could be wrong?". Have you
41  defined configASSERT()?
42 
43  http://www.FreeRTOS.org/support - In return for receiving this top quality
44  embedded software for free we request you assist our global community by
45  participating in the support forum.
46 
47  http://www.FreeRTOS.org/training - Investing in training allows your team to
48  be as productive as possible as early as possible. Now you can receive
49  FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50  Ltd, and the world's leading authority on the world's leading RTOS.
51 
52  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54  compatible FAT file system, and our tiny thread aware UDP/IP stack.
55 
56  http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57  Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58 
59  http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60  Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61  licenses offer ticketed support, indemnification and commercial middleware.
62 
63  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64  engineered and independently SIL3 certified version for use in safety and
65  mission critical applications that require provable dependability.
66 
67  1 tab == 4 spaces!
68 */
69 
70 
71 #ifndef QUEUE_H
72 #define QUEUE_H
73 
74 #ifndef INC_FREERTOS_H
75  #error "include FreeRTOS.h" must appear in source files before "include queue.h"
76 #endif
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 
88 typedef void * QueueHandle_t;
89 
95 typedef void * QueueSetHandle_t;
96 
102 typedef void * QueueSetMemberHandle_t;
103 
104 /* For internal use only. */
105 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
106 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
107 #define queueOVERWRITE ( ( BaseType_t ) 2 )
108 
109 /* For internal use only. These definitions *must* match those in queue.c. */
110 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
111 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
112 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
113 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
114 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
115 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
116 
173 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
174 
255 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
256 
337 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
338 
421 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
422 
504 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
505 
506 
592 BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
593 
688 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
689 
721 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;
722 
814 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
815 
816 
913 BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeek ) PRIVILEGED_FUNCTION;
914 
928 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
929 
945 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
946 
959 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
960 
1029 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1030 
1031 
1100 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1101 
1187 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1188 
1261 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1262 
1340 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1341 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1342 
1430 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1431 
1432 /*
1433  * Utilities to query queues that are safe to use from an ISR. These utilities
1434  * should be used only from witin an ISR, or within a critical section.
1435  */
1436 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1437 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1438 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1439 
1440 
1441 /*
1442  * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
1443  * Likewise xQueueAltGenericReceive() is an alternative version of
1444  * xQueueGenericReceive().
1445  *
1446  * The source code that implements the alternative (Alt) API is much
1447  * simpler because it executes everything from within a critical section.
1448  * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
1449  * preferred fully featured API too. The fully featured API has more
1450  * complex code that takes longer to execute, but makes much less use of
1451  * critical sections. Therefore the alternative API sacrifices interrupt
1452  * responsiveness to gain execution speed, whereas the fully featured API
1453  * sacrifices execution speed to ensure better interrupt responsiveness.
1454  */
1455 BaseType_t xQueueAltGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1456 BaseType_t xQueueAltGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, BaseType_t xJustPeeking ) PRIVILEGED_FUNCTION;
1457 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
1458 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
1459 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
1460 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
1461 
1462 /*
1463  * The functions defined above are for passing data to and from tasks. The
1464  * functions below are the equivalents for passing data to and from
1465  * co-routines.
1466  *
1467  * These functions are called from the co-routine macro implementation and
1468  * should not be called directly from application code. Instead use the macro
1469  * wrappers defined within croutine.h.
1470  */
1471 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken );
1472 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken );
1473 BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
1474 BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait );
1475 
1476 /*
1477  * For internal use only. Use xSemaphoreCreateMutex(),
1478  * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1479  * these functions directly.
1480  */
1481 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1482 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1483 void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1484 
1485 /*
1486  * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1487  * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1488  */
1489 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1490 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) PRIVILEGED_FUNCTION;
1491 
1492 /*
1493  * Reset a queue back to its original empty state. The return value is now
1494  * obsolete and is always set to pdPASS.
1495  */
1496 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1497 
1498 /*
1499  * The registry is provided as a means for kernel aware debuggers to
1500  * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1501  * a queue, semaphore or mutex handle to the registry if you want the handle
1502  * to be available to a kernel aware debugger. If you are not using a kernel
1503  * aware debugger then this function can be ignored.
1504  *
1505  * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1506  * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1507  * within FreeRTOSConfig.h for the registry to be available. Its value
1508  * does not effect the number of queues, semaphores and mutexes that can be
1509  * created - just the number that the registry can hold.
1510  *
1511  * @param xQueue The handle of the queue being added to the registry. This
1512  * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1513  * handles can also be passed in here.
1514  *
1515  * @param pcName The name to be associated with the handle. This is the
1516  * name that the kernel aware debugger will display. The queue registry only
1517  * stores a pointer to the string - so the string must be persistent (global or
1518  * preferably in ROM/Flash), not on the stack.
1519  */
1520 #if configQUEUE_REGISTRY_SIZE > 0
1521  void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1522 #endif
1523 
1524 /*
1525  * The registry is provided as a means for kernel aware debuggers to
1526  * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1527  * a queue, semaphore or mutex handle to the registry if you want the handle
1528  * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1529  * remove the queue, semaphore or mutex from the register. If you are not using
1530  * a kernel aware debugger then this function can be ignored.
1531  *
1532  * @param xQueue The handle of the queue being removed from the registry.
1533  */
1534 #if configQUEUE_REGISTRY_SIZE > 0
1535  void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1536 #endif
1537 
1538 /*
1539  * Generic version of the queue creation function, which is in turn called by
1540  * any queue, semaphore or mutex creation function or macro.
1541  */
1542 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1543 
1544 /*
1545  * Queue sets provide a mechanism to allow a task to block (pend) on a read
1546  * operation from multiple queues or semaphores simultaneously.
1547  *
1548  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1549  * function.
1550  *
1551  * A queue set must be explicitly created using a call to xQueueCreateSet()
1552  * before it can be used. Once created, standard FreeRTOS queues and semaphores
1553  * can be added to the set using calls to xQueueAddToSet().
1554  * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1555  * or semaphores contained in the set is in a state where a queue read or
1556  * semaphore take operation would be successful.
1557  *
1558  * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1559  * for reasons why queue sets are very rarely needed in practice as there are
1560  * simpler methods of blocking on multiple objects.
1561  *
1562  * Note 2: Blocking on a queue set that contains a mutex will not cause the
1563  * mutex holder to inherit the priority of the blocked task.
1564  *
1565  * Note 3: An additional 4 bytes of RAM is required for each space in a every
1566  * queue added to a queue set. Therefore counting semaphores that have a high
1567  * maximum count value should not be added to a queue set.
1568  *
1569  * Note 4: A receive (in the case of a queue) or take (in the case of a
1570  * semaphore) operation must not be performed on a member of a queue set unless
1571  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1572  *
1573  * @param uxEventQueueLength Queue sets store events that occur on
1574  * the queues and semaphores contained in the set. uxEventQueueLength specifies
1575  * the maximum number of events that can be queued at once. To be absolutely
1576  * certain that events are not lost uxEventQueueLength should be set to the
1577  * total sum of the length of the queues added to the set, where binary
1578  * semaphores and mutexes have a length of 1, and counting semaphores have a
1579  * length set by their maximum count value. Examples:
1580  * + If a queue set is to hold a queue of length 5, another queue of length 12,
1581  * and a binary semaphore, then uxEventQueueLength should be set to
1582  * (5 + 12 + 1), or 18.
1583  * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1584  * should be set to (1 + 1 + 1 ), or 3.
1585  * + If a queue set is to hold a counting semaphore that has a maximum count of
1586  * 5, and a counting semaphore that has a maximum count of 3, then
1587  * uxEventQueueLength should be set to (5 + 3), or 8.
1588  *
1589  * @return If the queue set is created successfully then a handle to the created
1590  * queue set is returned. Otherwise NULL is returned.
1591  */
1592 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1593 
1594 /*
1595  * Adds a queue or semaphore to a queue set that was previously created by a
1596  * call to xQueueCreateSet().
1597  *
1598  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1599  * function.
1600  *
1601  * Note 1: A receive (in the case of a queue) or take (in the case of a
1602  * semaphore) operation must not be performed on a member of a queue set unless
1603  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1604  *
1605  * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1606  * the queue set (cast to an QueueSetMemberHandle_t type).
1607  *
1608  * @param xQueueSet The handle of the queue set to which the queue or semaphore
1609  * is being added.
1610  *
1611  * @return If the queue or semaphore was successfully added to the queue set
1612  * then pdPASS is returned. If the queue could not be successfully added to the
1613  * queue set because it is already a member of a different queue set then pdFAIL
1614  * is returned.
1615  */
1616 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1617 
1618 /*
1619  * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1620  * be removed from a set if the queue or semaphore is empty.
1621  *
1622  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1623  * function.
1624  *
1625  * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1626  * from the queue set (cast to an QueueSetMemberHandle_t type).
1627  *
1628  * @param xQueueSet The handle of the queue set in which the queue or semaphore
1629  * is included.
1630  *
1631  * @return If the queue or semaphore was successfully removed from the queue set
1632  * then pdPASS is returned. If the queue was not in the queue set, or the
1633  * queue (or semaphore) was not empty, then pdFAIL is returned.
1634  */
1635 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1636 
1637 /*
1638  * xQueueSelectFromSet() selects from the members of a queue set a queue or
1639  * semaphore that either contains data (in the case of a queue) or is available
1640  * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1641  * allows a task to block (pend) on a read operation on all the queues and
1642  * semaphores in a queue set simultaneously.
1643  *
1644  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1645  * function.
1646  *
1647  * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1648  * for reasons why queue sets are very rarely needed in practice as there are
1649  * simpler methods of blocking on multiple objects.
1650  *
1651  * Note 2: Blocking on a queue set that contains a mutex will not cause the
1652  * mutex holder to inherit the priority of the blocked task.
1653  *
1654  * Note 3: A receive (in the case of a queue) or take (in the case of a
1655  * semaphore) operation must not be performed on a member of a queue set unless
1656  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1657  *
1658  * @param xQueueSet The queue set on which the task will (potentially) block.
1659  *
1660  * @param xTicksToWait The maximum time, in ticks, that the calling task will
1661  * remain in the Blocked state (with other tasks executing) to wait for a member
1662  * of the queue set to be ready for a successful queue read or semaphore take
1663  * operation.
1664  *
1665  * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1666  * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1667  * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1668  * in the queue set that is available, or NULL if no such queue or semaphore
1669  * exists before before the specified block time expires.
1670  */
1671 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1672 
1673 /*
1674  * A version of xQueueSelectFromSet() that can be used from an ISR.
1675  */
1676 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1677 
1678 /* Not public API functions. */
1679 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1680 BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1681 void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1682 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1683 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1684 
1685 
1686 #ifdef __cplusplus
1687 }
1688 #endif
1689 
1690 #endif /* QUEUE_H */
1691