queue.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef QUEUE_H
  29. #define QUEUE_H
  30. /* *INDENT-OFF* */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* *INDENT-ON* */
  35. /**
  36. * Type by which queues are referenced. For example, a call to xQueueCreate()
  37. * returns an QueueHandle_t variable that can then be used as a parameter to
  38. * xQueueSend(), xQueueReceive(), etc.
  39. */
  40. struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
  41. typedef struct QueueDefinition * QueueHandle_t;
  42. /* For internal use only. */
  43. #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
  44. #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
  45. #define queueOVERWRITE ( ( BaseType_t ) 2 )
  46. /* For internal use only. These definitions *must* match those in queue.c. */
  47. #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
  48. #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
  49. #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
  50. #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
  51. #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
  52. #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
  53. /**
  54. * queue. h
  55. * @code{c}
  56. * BaseType_t xQueueGenericSend(
  57. * QueueHandle_t xQueue,
  58. * const void * pvItemToQueue,
  59. * TickType_t xTicksToWait
  60. * BaseType_t xCopyPosition
  61. * );
  62. * @endcode
  63. *
  64. * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
  65. * xQueueSendToBack() are used in place of calling this function directly.
  66. *
  67. * Post an item on a queue. The item is queued by copy, not by reference.
  68. * This function must not be called from an interrupt service routine.
  69. * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  70. *
  71. * @param xQueue The handle to the queue on which the item is to be posted.
  72. *
  73. * @param pvItemToQueue A pointer to the item that is to be placed on the
  74. * queue. The size of the items the queue will hold was defined when the
  75. * queue was created, so this many bytes will be copied from pvItemToQueue
  76. * into the queue storage area.
  77. *
  78. * @param xTicksToWait The maximum amount of time the task should block
  79. * waiting for space to become available on the queue, should it already
  80. * be full. The call will return immediately if this is set to 0 and the
  81. * queue is full. The time is defined in tick periods so the constant
  82. * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  83. *
  84. * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  85. * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  86. * at the front of the queue (for high priority messages).
  87. *
  88. * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  89. *
  90. * Example usage:
  91. * @code{c}
  92. * struct AMessage
  93. * {
  94. * char ucMessageID;
  95. * char ucData[ 20 ];
  96. * } xMessage;
  97. *
  98. * uint32_t ulVar = 10UL;
  99. *
  100. * void vATask( void *pvParameters )
  101. * {
  102. * QueueHandle_t xQueue1, xQueue2;
  103. * struct AMessage *pxMessage;
  104. *
  105. * // Create a queue capable of containing 10 uint32_t values.
  106. * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  107. *
  108. * // Create a queue capable of containing 10 pointers to AMessage structures.
  109. * // These should be passed by pointer as they contain a lot of data.
  110. * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  111. *
  112. * // ...
  113. *
  114. * if( xQueue1 != 0 )
  115. * {
  116. * // Send an uint32_t. Wait for 10 ticks for space to become
  117. * // available if necessary.
  118. * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
  119. * {
  120. * // Failed to post the message, even after 10 ticks.
  121. * }
  122. * }
  123. *
  124. * if( xQueue2 != 0 )
  125. * {
  126. * // Send a pointer to a struct AMessage object. Don't block if the
  127. * // queue is already full.
  128. * pxMessage = & xMessage;
  129. * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
  130. * }
  131. *
  132. * // ... Rest of task code.
  133. * }
  134. * @endcode
  135. * \defgroup xQueueSend xQueueSend
  136. * \ingroup QueueManagement
  137. */
  138. BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
  139. const void * const pvItemToQueue,
  140. TickType_t xTicksToWait,
  141. const BaseType_t xCopyPosition );
  142. /**
  143. * queue. h
  144. * @code{c}
  145. * void vQueueDelete( QueueHandle_t xQueue );
  146. * @endcode
  147. *
  148. * Delete a queue - freeing all the memory allocated for storing of items
  149. * placed on the queue.
  150. *
  151. * @param xQueue A handle to the queue to be deleted.
  152. *
  153. * \defgroup vQueueDelete vQueueDelete
  154. * \ingroup QueueManagement
  155. */
  156. void vQueueDelete( QueueHandle_t xQueue );
  157. /*
  158. * For internal use only. Use xSemaphoreCreateMutex(),
  159. * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  160. * these functions directly.
  161. */
  162. QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType );
  163. QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
  164. StaticQueue_t * pxStaticQueue );
  165. BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
  166. TickType_t xTicksToWait );
  167. /*
  168. * For internal use only. Use xSemaphoreTakeMutexRecursive() or
  169. * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
  170. */
  171. BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
  172. TickType_t xTicksToWait );
  173. BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex );
  174. /*
  175. * Generic version of the function used to create a queue using dynamic memory
  176. * allocation. This is called by other functions and macros that create other
  177. * RTOS objects that use the queue structure as their base.
  178. */
  179. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  180. QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
  181. const UBaseType_t uxItemSize,
  182. const uint8_t ucQueueType );
  183. #endif
  184. /*
  185. * Generic version of the function used to create a queue using dynamic memory
  186. * allocation. This is called by other functions and macros that create other
  187. * RTOS objects that use the queue structure as their base.
  188. */
  189. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  190. QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
  191. const UBaseType_t uxItemSize,
  192. uint8_t * pucQueueStorage,
  193. StaticQueue_t * pxStaticQueue,
  194. const uint8_t ucQueueType );
  195. #endif
  196. /* *INDENT-OFF* */
  197. #ifdef __cplusplus
  198. }
  199. #endif
  200. /* *INDENT-ON* */
  201. #endif /* QUEUE_H */