mTower
queue.h
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27 
28 
29 #ifndef QUEUE_H
30 #define QUEUE_H
31 
32 #ifndef INC_FREERTOS_H
33  #error "include FreeRTOS.h" must appear in source files before "include queue.h"
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include "task.h"
41 
47 struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
48 typedef struct QueueDefinition * QueueHandle_t;
49 
55 typedef struct QueueDefinition * QueueSetHandle_t;
56 
63 
64 /* For internal use only. */
65 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
66 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
67 #define queueOVERWRITE ( ( BaseType_t ) 2 )
68 
69 /* For internal use only. These definitions *must* match those in queue.c. */
70 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
71 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
72 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
73 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
74 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
75 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
76 
145 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
146  #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
147 #endif
148 
231 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
232  #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
233 #endif /* configSUPPORT_STATIC_ALLOCATION */
234 
313 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
314 
395 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
396 
479 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
480 
562 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
563 
564 
650 BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
651 
744 BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
745 
777 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;
778 
868 BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
869 
883 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
884 
900 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
901 
914 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
915 
984 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
985 
986 
1055 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1056 
1142 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1143 
1216 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1217 
1295 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1296 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1297 
1385 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1386 
1387 /*
1388  * Utilities to query queues that are safe to use from an ISR. These utilities
1389  * should be used only from witin an ISR, or within a critical section.
1390  */
1391 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1392 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1393 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1394 
1395 /*
1396  * The functions defined above are for passing data to and from tasks. The
1397  * functions below are the equivalents for passing data to and from
1398  * co-routines.
1399  *
1400  * These functions are called from the co-routine macro implementation and
1401  * should not be called directly from application code. Instead use the macro
1402  * wrappers defined within croutine.h.
1403  */
1404 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken );
1405 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken );
1406 BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
1407 BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait );
1408 
1409 /*
1410  * For internal use only. Use xSemaphoreCreateMutex(),
1411  * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1412  * these functions directly.
1413  */
1414 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1415 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1416 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1417 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1418 BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1419 TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1420 TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1421 
1422 /*
1423  * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1424  * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1425  */
1426 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1427 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
1428 
1429 /*
1430  * Reset a queue back to its original empty state. The return value is now
1431  * obsolete and is always set to pdPASS.
1432  */
1433 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1434 
1435 /*
1436  * The registry is provided as a means for kernel aware debuggers to
1437  * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1438  * a queue, semaphore or mutex handle to the registry if you want the handle
1439  * to be available to a kernel aware debugger. If you are not using a kernel
1440  * aware debugger then this function can be ignored.
1441  *
1442  * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1443  * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1444  * within FreeRTOSConfig.h for the registry to be available. Its value
1445  * does not effect the number of queues, semaphores and mutexes that can be
1446  * created - just the number that the registry can hold.
1447  *
1448  * @param xQueue The handle of the queue being added to the registry. This
1449  * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1450  * handles can also be passed in here.
1451  *
1452  * @param pcName The name to be associated with the handle. This is the
1453  * name that the kernel aware debugger will display. The queue registry only
1454  * stores a pointer to the string - so the string must be persistent (global or
1455  * preferably in ROM/Flash), not on the stack.
1456  */
1457 #if( configQUEUE_REGISTRY_SIZE > 0 )
1458  void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcQueueName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1459 #endif
1460 
1461 /*
1462  * The registry is provided as a means for kernel aware debuggers to
1463  * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1464  * a queue, semaphore or mutex handle to the registry if you want the handle
1465  * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1466  * remove the queue, semaphore or mutex from the register. If you are not using
1467  * a kernel aware debugger then this function can be ignored.
1468  *
1469  * @param xQueue The handle of the queue being removed from the registry.
1470  */
1471 #if( configQUEUE_REGISTRY_SIZE > 0 )
1472  void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1473 #endif
1474 
1475 /*
1476  * The queue registry is provided as a means for kernel aware debuggers to
1477  * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1478  * up and return the name of a queue in the queue registry from the queue's
1479  * handle.
1480  *
1481  * @param xQueue The handle of the queue the name of which will be returned.
1482  * @return If the queue is in the registry then a pointer to the name of the
1483  * queue is returned. If the queue is not in the registry then NULL is
1484  * returned.
1485  */
1486 #if( configQUEUE_REGISTRY_SIZE > 0 )
1487  const char *pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1488 #endif
1489 
1490 /*
1491  * Generic version of the function used to creaet a queue using dynamic memory
1492  * allocation. This is called by other functions and macros that create other
1493  * RTOS objects that use the queue structure as their base.
1494  */
1495 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1496  QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1497 #endif
1498 
1499 /*
1500  * Generic version of the function used to creaet a queue using dynamic memory
1501  * allocation. This is called by other functions and macros that create other
1502  * RTOS objects that use the queue structure as their base.
1503  */
1504 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
1505  QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1506 #endif
1507 
1508 /*
1509  * Queue sets provide a mechanism to allow a task to block (pend) on a read
1510  * operation from multiple queues or semaphores simultaneously.
1511  *
1512  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1513  * function.
1514  *
1515  * A queue set must be explicitly created using a call to xQueueCreateSet()
1516  * before it can be used. Once created, standard FreeRTOS queues and semaphores
1517  * can be added to the set using calls to xQueueAddToSet().
1518  * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1519  * or semaphores contained in the set is in a state where a queue read or
1520  * semaphore take operation would be successful.
1521  *
1522  * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1523  * for reasons why queue sets are very rarely needed in practice as there are
1524  * simpler methods of blocking on multiple objects.
1525  *
1526  * Note 2: Blocking on a queue set that contains a mutex will not cause the
1527  * mutex holder to inherit the priority of the blocked task.
1528  *
1529  * Note 3: An additional 4 bytes of RAM is required for each space in a every
1530  * queue added to a queue set. Therefore counting semaphores that have a high
1531  * maximum count value should not be added to a queue set.
1532  *
1533  * Note 4: A receive (in the case of a queue) or take (in the case of a
1534  * semaphore) operation must not be performed on a member of a queue set unless
1535  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1536  *
1537  * @param uxEventQueueLength Queue sets store events that occur on
1538  * the queues and semaphores contained in the set. uxEventQueueLength specifies
1539  * the maximum number of events that can be queued at once. To be absolutely
1540  * certain that events are not lost uxEventQueueLength should be set to the
1541  * total sum of the length of the queues added to the set, where binary
1542  * semaphores and mutexes have a length of 1, and counting semaphores have a
1543  * length set by their maximum count value. Examples:
1544  * + If a queue set is to hold a queue of length 5, another queue of length 12,
1545  * and a binary semaphore, then uxEventQueueLength should be set to
1546  * (5 + 12 + 1), or 18.
1547  * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1548  * should be set to (1 + 1 + 1 ), or 3.
1549  * + If a queue set is to hold a counting semaphore that has a maximum count of
1550  * 5, and a counting semaphore that has a maximum count of 3, then
1551  * uxEventQueueLength should be set to (5 + 3), or 8.
1552  *
1553  * @return If the queue set is created successfully then a handle to the created
1554  * queue set is returned. Otherwise NULL is returned.
1555  */
1556 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1557 
1558 /*
1559  * Adds a queue or semaphore to a queue set that was previously created by a
1560  * call to xQueueCreateSet().
1561  *
1562  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1563  * function.
1564  *
1565  * Note 1: A receive (in the case of a queue) or take (in the case of a
1566  * semaphore) operation must not be performed on a member of a queue set unless
1567  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1568  *
1569  * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1570  * the queue set (cast to an QueueSetMemberHandle_t type).
1571  *
1572  * @param xQueueSet The handle of the queue set to which the queue or semaphore
1573  * is being added.
1574  *
1575  * @return If the queue or semaphore was successfully added to the queue set
1576  * then pdPASS is returned. If the queue could not be successfully added to the
1577  * queue set because it is already a member of a different queue set then pdFAIL
1578  * is returned.
1579  */
1580 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1581 
1582 /*
1583  * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1584  * be removed from a set if the queue or semaphore is empty.
1585  *
1586  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1587  * function.
1588  *
1589  * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1590  * from the queue set (cast to an QueueSetMemberHandle_t type).
1591  *
1592  * @param xQueueSet The handle of the queue set in which the queue or semaphore
1593  * is included.
1594  *
1595  * @return If the queue or semaphore was successfully removed from the queue set
1596  * then pdPASS is returned. If the queue was not in the queue set, or the
1597  * queue (or semaphore) was not empty, then pdFAIL is returned.
1598  */
1599 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1600 
1601 /*
1602  * xQueueSelectFromSet() selects from the members of a queue set a queue or
1603  * semaphore that either contains data (in the case of a queue) or is available
1604  * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1605  * allows a task to block (pend) on a read operation on all the queues and
1606  * semaphores in a queue set simultaneously.
1607  *
1608  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1609  * function.
1610  *
1611  * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1612  * for reasons why queue sets are very rarely needed in practice as there are
1613  * simpler methods of blocking on multiple objects.
1614  *
1615  * Note 2: Blocking on a queue set that contains a mutex will not cause the
1616  * mutex holder to inherit the priority of the blocked task.
1617  *
1618  * Note 3: A receive (in the case of a queue) or take (in the case of a
1619  * semaphore) operation must not be performed on a member of a queue set unless
1620  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1621  *
1622  * @param xQueueSet The queue set on which the task will (potentially) block.
1623  *
1624  * @param xTicksToWait The maximum time, in ticks, that the calling task will
1625  * remain in the Blocked state (with other tasks executing) to wait for a member
1626  * of the queue set to be ready for a successful queue read or semaphore take
1627  * operation.
1628  *
1629  * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1630  * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1631  * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1632  * in the queue set that is available, or NULL if no such queue or semaphore
1633  * exists before before the specified block time expires.
1634  */
1635 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1636 
1637 /*
1638  * A version of xQueueSelectFromSet() that can be used from an ISR.
1639  */
1640 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1641 
1642 /* Not public API functions. */
1643 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1644 BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1645 void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1646 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1647 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1648 
1649 
1650 #ifdef __cplusplus
1651 }
1652 #endif
1653 
1654 #endif /* QUEUE_H */
1655 
Definition: tasks.c:269
Definition: queue.c:97
Definition: FreeRTOS.h:1063