Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_lpc1768_freertos_lib
src/include/queue.h@0:5ff20db10a96, 2017-05-31 (annotated)
- Committer:
- fep
- Date:
- Wed May 31 02:36:43 2017 +0000
- Revision:
- 0:5ff20db10a96
FreeRTOS v9.0.0 for ARM Cortex-M3 based boards.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| fep | 0:5ff20db10a96 | 1 | /* |
| fep | 0:5ff20db10a96 | 2 | FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. |
| fep | 0:5ff20db10a96 | 3 | All rights reserved |
| fep | 0:5ff20db10a96 | 4 | |
| fep | 0:5ff20db10a96 | 5 | VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. |
| fep | 0:5ff20db10a96 | 6 | |
| fep | 0:5ff20db10a96 | 7 | This file is part of the FreeRTOS distribution. |
| fep | 0:5ff20db10a96 | 8 | |
| fep | 0:5ff20db10a96 | 9 | FreeRTOS is free software; you can redistribute it and/or modify it under |
| fep | 0:5ff20db10a96 | 10 | the terms of the GNU General Public License (version 2) as published by the |
| fep | 0:5ff20db10a96 | 11 | Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. |
| fep | 0:5ff20db10a96 | 12 | |
| fep | 0:5ff20db10a96 | 13 | *************************************************************************** |
| fep | 0:5ff20db10a96 | 14 | >>! NOTE: The modification to the GPL is included to allow you to !<< |
| fep | 0:5ff20db10a96 | 15 | >>! distribute a combined work that includes FreeRTOS without being !<< |
| fep | 0:5ff20db10a96 | 16 | >>! obliged to provide the source code for proprietary components !<< |
| fep | 0:5ff20db10a96 | 17 | >>! outside of the FreeRTOS kernel. !<< |
| fep | 0:5ff20db10a96 | 18 | *************************************************************************** |
| fep | 0:5ff20db10a96 | 19 | |
| fep | 0:5ff20db10a96 | 20 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY |
| fep | 0:5ff20db10a96 | 21 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| fep | 0:5ff20db10a96 | 22 | FOR A PARTICULAR PURPOSE. Full license text is available on the following |
| fep | 0:5ff20db10a96 | 23 | link: http://www.freertos.org/a00114.html |
| fep | 0:5ff20db10a96 | 24 | |
| fep | 0:5ff20db10a96 | 25 | *************************************************************************** |
| fep | 0:5ff20db10a96 | 26 | * * |
| fep | 0:5ff20db10a96 | 27 | * FreeRTOS provides completely free yet professionally developed, * |
| fep | 0:5ff20db10a96 | 28 | * robust, strictly quality controlled, supported, and cross * |
| fep | 0:5ff20db10a96 | 29 | * platform software that is more than just the market leader, it * |
| fep | 0:5ff20db10a96 | 30 | * is the industry's de facto standard. * |
| fep | 0:5ff20db10a96 | 31 | * * |
| fep | 0:5ff20db10a96 | 32 | * Help yourself get started quickly while simultaneously helping * |
| fep | 0:5ff20db10a96 | 33 | * to support the FreeRTOS project by purchasing a FreeRTOS * |
| fep | 0:5ff20db10a96 | 34 | * tutorial book, reference manual, or both: * |
| fep | 0:5ff20db10a96 | 35 | * http://www.FreeRTOS.org/Documentation * |
| fep | 0:5ff20db10a96 | 36 | * * |
| fep | 0:5ff20db10a96 | 37 | *************************************************************************** |
| fep | 0:5ff20db10a96 | 38 | |
| fep | 0:5ff20db10a96 | 39 | http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading |
| fep | 0:5ff20db10a96 | 40 | the FAQ page "My application does not run, what could be wrong?". Have you |
| fep | 0:5ff20db10a96 | 41 | defined configASSERT()? |
| fep | 0:5ff20db10a96 | 42 | |
| fep | 0:5ff20db10a96 | 43 | http://www.FreeRTOS.org/support - In return for receiving this top quality |
| fep | 0:5ff20db10a96 | 44 | embedded software for free we request you assist our global community by |
| fep | 0:5ff20db10a96 | 45 | participating in the support forum. |
| fep | 0:5ff20db10a96 | 46 | |
| fep | 0:5ff20db10a96 | 47 | http://www.FreeRTOS.org/training - Investing in training allows your team to |
| fep | 0:5ff20db10a96 | 48 | be as productive as possible as early as possible. Now you can receive |
| fep | 0:5ff20db10a96 | 49 | FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers |
| fep | 0:5ff20db10a96 | 50 | Ltd, and the world's leading authority on the world's leading RTOS. |
| fep | 0:5ff20db10a96 | 51 | |
| fep | 0:5ff20db10a96 | 52 | http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, |
| fep | 0:5ff20db10a96 | 53 | including FreeRTOS+Trace - an indispensable productivity tool, a DOS |
| fep | 0:5ff20db10a96 | 54 | compatible FAT file system, and our tiny thread aware UDP/IP stack. |
| fep | 0:5ff20db10a96 | 55 | |
| fep | 0:5ff20db10a96 | 56 | http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. |
| fep | 0:5ff20db10a96 | 57 | Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. |
| fep | 0:5ff20db10a96 | 58 | |
| fep | 0:5ff20db10a96 | 59 | http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High |
| fep | 0:5ff20db10a96 | 60 | Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS |
| fep | 0:5ff20db10a96 | 61 | licenses offer ticketed support, indemnification and commercial middleware. |
| fep | 0:5ff20db10a96 | 62 | |
| fep | 0:5ff20db10a96 | 63 | http://www.SafeRTOS.com - High Integrity Systems also provide a safety |
| fep | 0:5ff20db10a96 | 64 | engineered and independently SIL3 certified version for use in safety and |
| fep | 0:5ff20db10a96 | 65 | mission critical applications that require provable dependability. |
| fep | 0:5ff20db10a96 | 66 | |
| fep | 0:5ff20db10a96 | 67 | 1 tab == 4 spaces! |
| fep | 0:5ff20db10a96 | 68 | */ |
| fep | 0:5ff20db10a96 | 69 | |
| fep | 0:5ff20db10a96 | 70 | |
| fep | 0:5ff20db10a96 | 71 | #ifndef QUEUE_H |
| fep | 0:5ff20db10a96 | 72 | #define QUEUE_H |
| fep | 0:5ff20db10a96 | 73 | |
| fep | 0:5ff20db10a96 | 74 | #ifndef INC_FREERTOS_H |
| fep | 0:5ff20db10a96 | 75 | #error "include FreeRTOS.h" must appear in source files before "include queue.h" |
| fep | 0:5ff20db10a96 | 76 | #endif |
| fep | 0:5ff20db10a96 | 77 | |
| fep | 0:5ff20db10a96 | 78 | #ifdef __cplusplus |
| fep | 0:5ff20db10a96 | 79 | extern "C" { |
| fep | 0:5ff20db10a96 | 80 | #endif |
| fep | 0:5ff20db10a96 | 81 | |
| fep | 0:5ff20db10a96 | 82 | |
| fep | 0:5ff20db10a96 | 83 | /** |
| fep | 0:5ff20db10a96 | 84 | * Type by which queues are referenced. For example, a call to xQueueCreate() |
| fep | 0:5ff20db10a96 | 85 | * returns an QueueHandle_t variable that can then be used as a parameter to |
| fep | 0:5ff20db10a96 | 86 | * xQueueSend(), xQueueReceive(), etc. |
| fep | 0:5ff20db10a96 | 87 | */ |
| fep | 0:5ff20db10a96 | 88 | typedef void * QueueHandle_t; |
| fep | 0:5ff20db10a96 | 89 | |
| fep | 0:5ff20db10a96 | 90 | /** |
| fep | 0:5ff20db10a96 | 91 | * Type by which queue sets are referenced. For example, a call to |
| fep | 0:5ff20db10a96 | 92 | * xQueueCreateSet() returns an xQueueSet variable that can then be used as a |
| fep | 0:5ff20db10a96 | 93 | * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc. |
| fep | 0:5ff20db10a96 | 94 | */ |
| fep | 0:5ff20db10a96 | 95 | typedef void * QueueSetHandle_t; |
| fep | 0:5ff20db10a96 | 96 | |
| fep | 0:5ff20db10a96 | 97 | /** |
| fep | 0:5ff20db10a96 | 98 | * Queue sets can contain both queues and semaphores, so the |
| fep | 0:5ff20db10a96 | 99 | * QueueSetMemberHandle_t is defined as a type to be used where a parameter or |
| fep | 0:5ff20db10a96 | 100 | * return value can be either an QueueHandle_t or an SemaphoreHandle_t. |
| fep | 0:5ff20db10a96 | 101 | */ |
| fep | 0:5ff20db10a96 | 102 | typedef void * QueueSetMemberHandle_t; |
| fep | 0:5ff20db10a96 | 103 | |
| fep | 0:5ff20db10a96 | 104 | /* For internal use only. */ |
| fep | 0:5ff20db10a96 | 105 | #define queueSEND_TO_BACK ( ( BaseType_t ) 0 ) |
| fep | 0:5ff20db10a96 | 106 | #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 ) |
| fep | 0:5ff20db10a96 | 107 | #define queueOVERWRITE ( ( BaseType_t ) 2 ) |
| fep | 0:5ff20db10a96 | 108 | |
| fep | 0:5ff20db10a96 | 109 | /* For internal use only. These definitions *must* match those in queue.c. */ |
| fep | 0:5ff20db10a96 | 110 | #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U ) |
| fep | 0:5ff20db10a96 | 111 | #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U ) |
| fep | 0:5ff20db10a96 | 112 | #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U ) |
| fep | 0:5ff20db10a96 | 113 | #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U ) |
| fep | 0:5ff20db10a96 | 114 | #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U ) |
| fep | 0:5ff20db10a96 | 115 | #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U ) |
| fep | 0:5ff20db10a96 | 116 | |
| fep | 0:5ff20db10a96 | 117 | /** |
| fep | 0:5ff20db10a96 | 118 | * queue. h |
| fep | 0:5ff20db10a96 | 119 | * <pre> |
| fep | 0:5ff20db10a96 | 120 | QueueHandle_t xQueueCreate( |
| fep | 0:5ff20db10a96 | 121 | UBaseType_t uxQueueLength, |
| fep | 0:5ff20db10a96 | 122 | UBaseType_t uxItemSize |
| fep | 0:5ff20db10a96 | 123 | ); |
| fep | 0:5ff20db10a96 | 124 | * </pre> |
| fep | 0:5ff20db10a96 | 125 | * |
| fep | 0:5ff20db10a96 | 126 | * Creates a new queue instance, and returns a handle by which the new queue |
| fep | 0:5ff20db10a96 | 127 | * can be referenced. |
| fep | 0:5ff20db10a96 | 128 | * |
| fep | 0:5ff20db10a96 | 129 | * Internally, within the FreeRTOS implementation, queues use two blocks of |
| fep | 0:5ff20db10a96 | 130 | * memory. The first block is used to hold the queue's data structures. The |
| fep | 0:5ff20db10a96 | 131 | * second block is used to hold items placed into the queue. If a queue is |
| fep | 0:5ff20db10a96 | 132 | * created using xQueueCreate() then both blocks of memory are automatically |
| fep | 0:5ff20db10a96 | 133 | * dynamically allocated inside the xQueueCreate() function. (see |
| fep | 0:5ff20db10a96 | 134 | * http://www.freertos.org/a00111.html). If a queue is created using |
| fep | 0:5ff20db10a96 | 135 | * xQueueCreateStatic() then the application writer must provide the memory that |
| fep | 0:5ff20db10a96 | 136 | * will get used by the queue. xQueueCreateStatic() therefore allows a queue to |
| fep | 0:5ff20db10a96 | 137 | * be created without using any dynamic memory allocation. |
| fep | 0:5ff20db10a96 | 138 | * |
| fep | 0:5ff20db10a96 | 139 | * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html |
| fep | 0:5ff20db10a96 | 140 | * |
| fep | 0:5ff20db10a96 | 141 | * @param uxQueueLength The maximum number of items that the queue can contain. |
| fep | 0:5ff20db10a96 | 142 | * |
| fep | 0:5ff20db10a96 | 143 | * @param uxItemSize The number of bytes each item in the queue will require. |
| fep | 0:5ff20db10a96 | 144 | * Items are queued by copy, not by reference, so this is the number of bytes |
| fep | 0:5ff20db10a96 | 145 | * that will be copied for each posted item. Each item on the queue must be |
| fep | 0:5ff20db10a96 | 146 | * the same size. |
| fep | 0:5ff20db10a96 | 147 | * |
| fep | 0:5ff20db10a96 | 148 | * @return If the queue is successfully create then a handle to the newly |
| fep | 0:5ff20db10a96 | 149 | * created queue is returned. If the queue cannot be created then 0 is |
| fep | 0:5ff20db10a96 | 150 | * returned. |
| fep | 0:5ff20db10a96 | 151 | * |
| fep | 0:5ff20db10a96 | 152 | * Example usage: |
| fep | 0:5ff20db10a96 | 153 | <pre> |
| fep | 0:5ff20db10a96 | 154 | struct AMessage |
| fep | 0:5ff20db10a96 | 155 | { |
| fep | 0:5ff20db10a96 | 156 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 157 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 158 | }; |
| fep | 0:5ff20db10a96 | 159 | |
| fep | 0:5ff20db10a96 | 160 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 161 | { |
| fep | 0:5ff20db10a96 | 162 | QueueHandle_t xQueue1, xQueue2; |
| fep | 0:5ff20db10a96 | 163 | |
| fep | 0:5ff20db10a96 | 164 | // Create a queue capable of containing 10 uint32_t values. |
| fep | 0:5ff20db10a96 | 165 | xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 166 | if( xQueue1 == 0 ) |
| fep | 0:5ff20db10a96 | 167 | { |
| fep | 0:5ff20db10a96 | 168 | // Queue was not created and must not be used. |
| fep | 0:5ff20db10a96 | 169 | } |
| fep | 0:5ff20db10a96 | 170 | |
| fep | 0:5ff20db10a96 | 171 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 172 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 173 | xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 174 | if( xQueue2 == 0 ) |
| fep | 0:5ff20db10a96 | 175 | { |
| fep | 0:5ff20db10a96 | 176 | // Queue was not created and must not be used. |
| fep | 0:5ff20db10a96 | 177 | } |
| fep | 0:5ff20db10a96 | 178 | |
| fep | 0:5ff20db10a96 | 179 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 180 | } |
| fep | 0:5ff20db10a96 | 181 | </pre> |
| fep | 0:5ff20db10a96 | 182 | * \defgroup xQueueCreate xQueueCreate |
| fep | 0:5ff20db10a96 | 183 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 184 | */ |
| fep | 0:5ff20db10a96 | 185 | #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) |
| fep | 0:5ff20db10a96 | 186 | #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) ) |
| fep | 0:5ff20db10a96 | 187 | #endif |
| fep | 0:5ff20db10a96 | 188 | |
| fep | 0:5ff20db10a96 | 189 | /** |
| fep | 0:5ff20db10a96 | 190 | * queue. h |
| fep | 0:5ff20db10a96 | 191 | * <pre> |
| fep | 0:5ff20db10a96 | 192 | QueueHandle_t xQueueCreateStatic( |
| fep | 0:5ff20db10a96 | 193 | UBaseType_t uxQueueLength, |
| fep | 0:5ff20db10a96 | 194 | UBaseType_t uxItemSize, |
| fep | 0:5ff20db10a96 | 195 | uint8_t *pucQueueStorageBuffer, |
| fep | 0:5ff20db10a96 | 196 | StaticQueue_t *pxQueueBuffer |
| fep | 0:5ff20db10a96 | 197 | ); |
| fep | 0:5ff20db10a96 | 198 | * </pre> |
| fep | 0:5ff20db10a96 | 199 | * |
| fep | 0:5ff20db10a96 | 200 | * Creates a new queue instance, and returns a handle by which the new queue |
| fep | 0:5ff20db10a96 | 201 | * can be referenced. |
| fep | 0:5ff20db10a96 | 202 | * |
| fep | 0:5ff20db10a96 | 203 | * Internally, within the FreeRTOS implementation, queues use two blocks of |
| fep | 0:5ff20db10a96 | 204 | * memory. The first block is used to hold the queue's data structures. The |
| fep | 0:5ff20db10a96 | 205 | * second block is used to hold items placed into the queue. If a queue is |
| fep | 0:5ff20db10a96 | 206 | * created using xQueueCreate() then both blocks of memory are automatically |
| fep | 0:5ff20db10a96 | 207 | * dynamically allocated inside the xQueueCreate() function. (see |
| fep | 0:5ff20db10a96 | 208 | * http://www.freertos.org/a00111.html). If a queue is created using |
| fep | 0:5ff20db10a96 | 209 | * xQueueCreateStatic() then the application writer must provide the memory that |
| fep | 0:5ff20db10a96 | 210 | * will get used by the queue. xQueueCreateStatic() therefore allows a queue to |
| fep | 0:5ff20db10a96 | 211 | * be created without using any dynamic memory allocation. |
| fep | 0:5ff20db10a96 | 212 | * |
| fep | 0:5ff20db10a96 | 213 | * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html |
| fep | 0:5ff20db10a96 | 214 | * |
| fep | 0:5ff20db10a96 | 215 | * @param uxQueueLength The maximum number of items that the queue can contain. |
| fep | 0:5ff20db10a96 | 216 | * |
| fep | 0:5ff20db10a96 | 217 | * @param uxItemSize The number of bytes each item in the queue will require. |
| fep | 0:5ff20db10a96 | 218 | * Items are queued by copy, not by reference, so this is the number of bytes |
| fep | 0:5ff20db10a96 | 219 | * that will be copied for each posted item. Each item on the queue must be |
| fep | 0:5ff20db10a96 | 220 | * the same size. |
| fep | 0:5ff20db10a96 | 221 | * |
| fep | 0:5ff20db10a96 | 222 | * @param pucQueueStorageBuffer If uxItemSize is not zero then |
| fep | 0:5ff20db10a96 | 223 | * pucQueueStorageBuffer must point to a uint8_t array that is at least large |
| fep | 0:5ff20db10a96 | 224 | * enough to hold the maximum number of items that can be in the queue at any |
| fep | 0:5ff20db10a96 | 225 | * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is |
| fep | 0:5ff20db10a96 | 226 | * zero then pucQueueStorageBuffer can be NULL. |
| fep | 0:5ff20db10a96 | 227 | * |
| fep | 0:5ff20db10a96 | 228 | * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which |
| fep | 0:5ff20db10a96 | 229 | * will be used to hold the queue's data structure. |
| fep | 0:5ff20db10a96 | 230 | * |
| fep | 0:5ff20db10a96 | 231 | * @return If the queue is created then a handle to the created queue is |
| fep | 0:5ff20db10a96 | 232 | * returned. If pxQueueBuffer is NULL then NULL is returned. |
| fep | 0:5ff20db10a96 | 233 | * |
| fep | 0:5ff20db10a96 | 234 | * Example usage: |
| fep | 0:5ff20db10a96 | 235 | <pre> |
| fep | 0:5ff20db10a96 | 236 | struct AMessage |
| fep | 0:5ff20db10a96 | 237 | { |
| fep | 0:5ff20db10a96 | 238 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 239 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 240 | }; |
| fep | 0:5ff20db10a96 | 241 | |
| fep | 0:5ff20db10a96 | 242 | #define QUEUE_LENGTH 10 |
| fep | 0:5ff20db10a96 | 243 | #define ITEM_SIZE sizeof( uint32_t ) |
| fep | 0:5ff20db10a96 | 244 | |
| fep | 0:5ff20db10a96 | 245 | // xQueueBuffer will hold the queue structure. |
| fep | 0:5ff20db10a96 | 246 | StaticQueue_t xQueueBuffer; |
| fep | 0:5ff20db10a96 | 247 | |
| fep | 0:5ff20db10a96 | 248 | // ucQueueStorage will hold the items posted to the queue. Must be at least |
| fep | 0:5ff20db10a96 | 249 | // [(queue length) * ( queue item size)] bytes long. |
| fep | 0:5ff20db10a96 | 250 | uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ]; |
| fep | 0:5ff20db10a96 | 251 | |
| fep | 0:5ff20db10a96 | 252 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 253 | { |
| fep | 0:5ff20db10a96 | 254 | QueueHandle_t xQueue1; |
| fep | 0:5ff20db10a96 | 255 | |
| fep | 0:5ff20db10a96 | 256 | // Create a queue capable of containing 10 uint32_t values. |
| fep | 0:5ff20db10a96 | 257 | xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold. |
| fep | 0:5ff20db10a96 | 258 | ITEM_SIZE // The size of each item in the queue |
| fep | 0:5ff20db10a96 | 259 | &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue. |
| fep | 0:5ff20db10a96 | 260 | &xQueueBuffer ); // The buffer that will hold the queue structure. |
| fep | 0:5ff20db10a96 | 261 | |
| fep | 0:5ff20db10a96 | 262 | // The queue is guaranteed to be created successfully as no dynamic memory |
| fep | 0:5ff20db10a96 | 263 | // allocation is used. Therefore xQueue1 is now a handle to a valid queue. |
| fep | 0:5ff20db10a96 | 264 | |
| fep | 0:5ff20db10a96 | 265 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 266 | } |
| fep | 0:5ff20db10a96 | 267 | </pre> |
| fep | 0:5ff20db10a96 | 268 | * \defgroup xQueueCreateStatic xQueueCreateStatic |
| fep | 0:5ff20db10a96 | 269 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 270 | */ |
| fep | 0:5ff20db10a96 | 271 | #if( configSUPPORT_STATIC_ALLOCATION == 1 ) |
| fep | 0:5ff20db10a96 | 272 | #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) ) |
| fep | 0:5ff20db10a96 | 273 | #endif /* configSUPPORT_STATIC_ALLOCATION */ |
| fep | 0:5ff20db10a96 | 274 | |
| fep | 0:5ff20db10a96 | 275 | /** |
| fep | 0:5ff20db10a96 | 276 | * queue. h |
| fep | 0:5ff20db10a96 | 277 | * <pre> |
| fep | 0:5ff20db10a96 | 278 | BaseType_t xQueueSendToToFront( |
| fep | 0:5ff20db10a96 | 279 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 280 | const void *pvItemToQueue, |
| fep | 0:5ff20db10a96 | 281 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 282 | ); |
| fep | 0:5ff20db10a96 | 283 | * </pre> |
| fep | 0:5ff20db10a96 | 284 | * |
| fep | 0:5ff20db10a96 | 285 | * This is a macro that calls xQueueGenericSend(). |
| fep | 0:5ff20db10a96 | 286 | * |
| fep | 0:5ff20db10a96 | 287 | * Post an item to the front of a queue. The item is queued by copy, not by |
| fep | 0:5ff20db10a96 | 288 | * reference. This function must not be called from an interrupt service |
| fep | 0:5ff20db10a96 | 289 | * routine. See xQueueSendFromISR () for an alternative which may be used |
| fep | 0:5ff20db10a96 | 290 | * in an ISR. |
| fep | 0:5ff20db10a96 | 291 | * |
| fep | 0:5ff20db10a96 | 292 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 293 | * |
| fep | 0:5ff20db10a96 | 294 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 295 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 296 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 297 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 298 | * |
| fep | 0:5ff20db10a96 | 299 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 300 | * waiting for space to become available on the queue, should it already |
| fep | 0:5ff20db10a96 | 301 | * be full. The call will return immediately if this is set to 0 and the |
| fep | 0:5ff20db10a96 | 302 | * queue is full. The time is defined in tick periods so the constant |
| fep | 0:5ff20db10a96 | 303 | * portTICK_PERIOD_MS should be used to convert to real time if this is required. |
| fep | 0:5ff20db10a96 | 304 | * |
| fep | 0:5ff20db10a96 | 305 | * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 306 | * |
| fep | 0:5ff20db10a96 | 307 | * Example usage: |
| fep | 0:5ff20db10a96 | 308 | <pre> |
| fep | 0:5ff20db10a96 | 309 | struct AMessage |
| fep | 0:5ff20db10a96 | 310 | { |
| fep | 0:5ff20db10a96 | 311 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 312 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 313 | } xMessage; |
| fep | 0:5ff20db10a96 | 314 | |
| fep | 0:5ff20db10a96 | 315 | uint32_t ulVar = 10UL; |
| fep | 0:5ff20db10a96 | 316 | |
| fep | 0:5ff20db10a96 | 317 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 318 | { |
| fep | 0:5ff20db10a96 | 319 | QueueHandle_t xQueue1, xQueue2; |
| fep | 0:5ff20db10a96 | 320 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 321 | |
| fep | 0:5ff20db10a96 | 322 | // Create a queue capable of containing 10 uint32_t values. |
| fep | 0:5ff20db10a96 | 323 | xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 324 | |
| fep | 0:5ff20db10a96 | 325 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 326 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 327 | xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 328 | |
| fep | 0:5ff20db10a96 | 329 | // ... |
| fep | 0:5ff20db10a96 | 330 | |
| fep | 0:5ff20db10a96 | 331 | if( xQueue1 != 0 ) |
| fep | 0:5ff20db10a96 | 332 | { |
| fep | 0:5ff20db10a96 | 333 | // Send an uint32_t. Wait for 10 ticks for space to become |
| fep | 0:5ff20db10a96 | 334 | // available if necessary. |
| fep | 0:5ff20db10a96 | 335 | if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS ) |
| fep | 0:5ff20db10a96 | 336 | { |
| fep | 0:5ff20db10a96 | 337 | // Failed to post the message, even after 10 ticks. |
| fep | 0:5ff20db10a96 | 338 | } |
| fep | 0:5ff20db10a96 | 339 | } |
| fep | 0:5ff20db10a96 | 340 | |
| fep | 0:5ff20db10a96 | 341 | if( xQueue2 != 0 ) |
| fep | 0:5ff20db10a96 | 342 | { |
| fep | 0:5ff20db10a96 | 343 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 344 | // queue is already full. |
| fep | 0:5ff20db10a96 | 345 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 346 | xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 ); |
| fep | 0:5ff20db10a96 | 347 | } |
| fep | 0:5ff20db10a96 | 348 | |
| fep | 0:5ff20db10a96 | 349 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 350 | } |
| fep | 0:5ff20db10a96 | 351 | </pre> |
| fep | 0:5ff20db10a96 | 352 | * \defgroup xQueueSend xQueueSend |
| fep | 0:5ff20db10a96 | 353 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 354 | */ |
| fep | 0:5ff20db10a96 | 355 | #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT ) |
| fep | 0:5ff20db10a96 | 356 | |
| fep | 0:5ff20db10a96 | 357 | /** |
| fep | 0:5ff20db10a96 | 358 | * queue. h |
| fep | 0:5ff20db10a96 | 359 | * <pre> |
| fep | 0:5ff20db10a96 | 360 | BaseType_t xQueueSendToBack( |
| fep | 0:5ff20db10a96 | 361 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 362 | const void *pvItemToQueue, |
| fep | 0:5ff20db10a96 | 363 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 364 | ); |
| fep | 0:5ff20db10a96 | 365 | * </pre> |
| fep | 0:5ff20db10a96 | 366 | * |
| fep | 0:5ff20db10a96 | 367 | * This is a macro that calls xQueueGenericSend(). |
| fep | 0:5ff20db10a96 | 368 | * |
| fep | 0:5ff20db10a96 | 369 | * Post an item to the back of a queue. The item is queued by copy, not by |
| fep | 0:5ff20db10a96 | 370 | * reference. This function must not be called from an interrupt service |
| fep | 0:5ff20db10a96 | 371 | * routine. See xQueueSendFromISR () for an alternative which may be used |
| fep | 0:5ff20db10a96 | 372 | * in an ISR. |
| fep | 0:5ff20db10a96 | 373 | * |
| fep | 0:5ff20db10a96 | 374 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 375 | * |
| fep | 0:5ff20db10a96 | 376 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 377 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 378 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 379 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 380 | * |
| fep | 0:5ff20db10a96 | 381 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 382 | * waiting for space to become available on the queue, should it already |
| fep | 0:5ff20db10a96 | 383 | * be full. The call will return immediately if this is set to 0 and the queue |
| fep | 0:5ff20db10a96 | 384 | * is full. The time is defined in tick periods so the constant |
| fep | 0:5ff20db10a96 | 385 | * portTICK_PERIOD_MS should be used to convert to real time if this is required. |
| fep | 0:5ff20db10a96 | 386 | * |
| fep | 0:5ff20db10a96 | 387 | * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 388 | * |
| fep | 0:5ff20db10a96 | 389 | * Example usage: |
| fep | 0:5ff20db10a96 | 390 | <pre> |
| fep | 0:5ff20db10a96 | 391 | struct AMessage |
| fep | 0:5ff20db10a96 | 392 | { |
| fep | 0:5ff20db10a96 | 393 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 394 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 395 | } xMessage; |
| fep | 0:5ff20db10a96 | 396 | |
| fep | 0:5ff20db10a96 | 397 | uint32_t ulVar = 10UL; |
| fep | 0:5ff20db10a96 | 398 | |
| fep | 0:5ff20db10a96 | 399 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 400 | { |
| fep | 0:5ff20db10a96 | 401 | QueueHandle_t xQueue1, xQueue2; |
| fep | 0:5ff20db10a96 | 402 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 403 | |
| fep | 0:5ff20db10a96 | 404 | // Create a queue capable of containing 10 uint32_t values. |
| fep | 0:5ff20db10a96 | 405 | xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 406 | |
| fep | 0:5ff20db10a96 | 407 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 408 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 409 | xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 410 | |
| fep | 0:5ff20db10a96 | 411 | // ... |
| fep | 0:5ff20db10a96 | 412 | |
| fep | 0:5ff20db10a96 | 413 | if( xQueue1 != 0 ) |
| fep | 0:5ff20db10a96 | 414 | { |
| fep | 0:5ff20db10a96 | 415 | // Send an uint32_t. Wait for 10 ticks for space to become |
| fep | 0:5ff20db10a96 | 416 | // available if necessary. |
| fep | 0:5ff20db10a96 | 417 | if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS ) |
| fep | 0:5ff20db10a96 | 418 | { |
| fep | 0:5ff20db10a96 | 419 | // Failed to post the message, even after 10 ticks. |
| fep | 0:5ff20db10a96 | 420 | } |
| fep | 0:5ff20db10a96 | 421 | } |
| fep | 0:5ff20db10a96 | 422 | |
| fep | 0:5ff20db10a96 | 423 | if( xQueue2 != 0 ) |
| fep | 0:5ff20db10a96 | 424 | { |
| fep | 0:5ff20db10a96 | 425 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 426 | // queue is already full. |
| fep | 0:5ff20db10a96 | 427 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 428 | xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 ); |
| fep | 0:5ff20db10a96 | 429 | } |
| fep | 0:5ff20db10a96 | 430 | |
| fep | 0:5ff20db10a96 | 431 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 432 | } |
| fep | 0:5ff20db10a96 | 433 | </pre> |
| fep | 0:5ff20db10a96 | 434 | * \defgroup xQueueSend xQueueSend |
| fep | 0:5ff20db10a96 | 435 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 436 | */ |
| fep | 0:5ff20db10a96 | 437 | #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) |
| fep | 0:5ff20db10a96 | 438 | |
| fep | 0:5ff20db10a96 | 439 | /** |
| fep | 0:5ff20db10a96 | 440 | * queue. h |
| fep | 0:5ff20db10a96 | 441 | * <pre> |
| fep | 0:5ff20db10a96 | 442 | BaseType_t xQueueSend( |
| fep | 0:5ff20db10a96 | 443 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 444 | const void * pvItemToQueue, |
| fep | 0:5ff20db10a96 | 445 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 446 | ); |
| fep | 0:5ff20db10a96 | 447 | * </pre> |
| fep | 0:5ff20db10a96 | 448 | * |
| fep | 0:5ff20db10a96 | 449 | * This is a macro that calls xQueueGenericSend(). It is included for |
| fep | 0:5ff20db10a96 | 450 | * backward compatibility with versions of FreeRTOS.org that did not |
| fep | 0:5ff20db10a96 | 451 | * include the xQueueSendToFront() and xQueueSendToBack() macros. It is |
| fep | 0:5ff20db10a96 | 452 | * equivalent to xQueueSendToBack(). |
| fep | 0:5ff20db10a96 | 453 | * |
| fep | 0:5ff20db10a96 | 454 | * Post an item on a queue. The item is queued by copy, not by reference. |
| fep | 0:5ff20db10a96 | 455 | * This function must not be called from an interrupt service routine. |
| fep | 0:5ff20db10a96 | 456 | * See xQueueSendFromISR () for an alternative which may be used in an ISR. |
| fep | 0:5ff20db10a96 | 457 | * |
| fep | 0:5ff20db10a96 | 458 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 459 | * |
| fep | 0:5ff20db10a96 | 460 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 461 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 462 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 463 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 464 | * |
| fep | 0:5ff20db10a96 | 465 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 466 | * waiting for space to become available on the queue, should it already |
| fep | 0:5ff20db10a96 | 467 | * be full. The call will return immediately if this is set to 0 and the |
| fep | 0:5ff20db10a96 | 468 | * queue is full. The time is defined in tick periods so the constant |
| fep | 0:5ff20db10a96 | 469 | * portTICK_PERIOD_MS should be used to convert to real time if this is required. |
| fep | 0:5ff20db10a96 | 470 | * |
| fep | 0:5ff20db10a96 | 471 | * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 472 | * |
| fep | 0:5ff20db10a96 | 473 | * Example usage: |
| fep | 0:5ff20db10a96 | 474 | <pre> |
| fep | 0:5ff20db10a96 | 475 | struct AMessage |
| fep | 0:5ff20db10a96 | 476 | { |
| fep | 0:5ff20db10a96 | 477 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 478 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 479 | } xMessage; |
| fep | 0:5ff20db10a96 | 480 | |
| fep | 0:5ff20db10a96 | 481 | uint32_t ulVar = 10UL; |
| fep | 0:5ff20db10a96 | 482 | |
| fep | 0:5ff20db10a96 | 483 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 484 | { |
| fep | 0:5ff20db10a96 | 485 | QueueHandle_t xQueue1, xQueue2; |
| fep | 0:5ff20db10a96 | 486 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 487 | |
| fep | 0:5ff20db10a96 | 488 | // Create a queue capable of containing 10 uint32_t values. |
| fep | 0:5ff20db10a96 | 489 | xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 490 | |
| fep | 0:5ff20db10a96 | 491 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 492 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 493 | xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 494 | |
| fep | 0:5ff20db10a96 | 495 | // ... |
| fep | 0:5ff20db10a96 | 496 | |
| fep | 0:5ff20db10a96 | 497 | if( xQueue1 != 0 ) |
| fep | 0:5ff20db10a96 | 498 | { |
| fep | 0:5ff20db10a96 | 499 | // Send an uint32_t. Wait for 10 ticks for space to become |
| fep | 0:5ff20db10a96 | 500 | // available if necessary. |
| fep | 0:5ff20db10a96 | 501 | if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS ) |
| fep | 0:5ff20db10a96 | 502 | { |
| fep | 0:5ff20db10a96 | 503 | // Failed to post the message, even after 10 ticks. |
| fep | 0:5ff20db10a96 | 504 | } |
| fep | 0:5ff20db10a96 | 505 | } |
| fep | 0:5ff20db10a96 | 506 | |
| fep | 0:5ff20db10a96 | 507 | if( xQueue2 != 0 ) |
| fep | 0:5ff20db10a96 | 508 | { |
| fep | 0:5ff20db10a96 | 509 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 510 | // queue is already full. |
| fep | 0:5ff20db10a96 | 511 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 512 | xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 ); |
| fep | 0:5ff20db10a96 | 513 | } |
| fep | 0:5ff20db10a96 | 514 | |
| fep | 0:5ff20db10a96 | 515 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 516 | } |
| fep | 0:5ff20db10a96 | 517 | </pre> |
| fep | 0:5ff20db10a96 | 518 | * \defgroup xQueueSend xQueueSend |
| fep | 0:5ff20db10a96 | 519 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 520 | */ |
| fep | 0:5ff20db10a96 | 521 | #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK ) |
| fep | 0:5ff20db10a96 | 522 | |
| fep | 0:5ff20db10a96 | 523 | /** |
| fep | 0:5ff20db10a96 | 524 | * queue. h |
| fep | 0:5ff20db10a96 | 525 | * <pre> |
| fep | 0:5ff20db10a96 | 526 | BaseType_t xQueueOverwrite( |
| fep | 0:5ff20db10a96 | 527 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 528 | const void * pvItemToQueue |
| fep | 0:5ff20db10a96 | 529 | ); |
| fep | 0:5ff20db10a96 | 530 | * </pre> |
| fep | 0:5ff20db10a96 | 531 | * |
| fep | 0:5ff20db10a96 | 532 | * Only for use with queues that have a length of one - so the queue is either |
| fep | 0:5ff20db10a96 | 533 | * empty or full. |
| fep | 0:5ff20db10a96 | 534 | * |
| fep | 0:5ff20db10a96 | 535 | * Post an item on a queue. If the queue is already full then overwrite the |
| fep | 0:5ff20db10a96 | 536 | * value held in the queue. The item is queued by copy, not by reference. |
| fep | 0:5ff20db10a96 | 537 | * |
| fep | 0:5ff20db10a96 | 538 | * This function must not be called from an interrupt service routine. |
| fep | 0:5ff20db10a96 | 539 | * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR. |
| fep | 0:5ff20db10a96 | 540 | * |
| fep | 0:5ff20db10a96 | 541 | * @param xQueue The handle of the queue to which the data is being sent. |
| fep | 0:5ff20db10a96 | 542 | * |
| fep | 0:5ff20db10a96 | 543 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 544 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 545 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 546 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 547 | * |
| fep | 0:5ff20db10a96 | 548 | * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and |
| fep | 0:5ff20db10a96 | 549 | * therefore has the same return values as xQueueSendToFront(). However, pdPASS |
| fep | 0:5ff20db10a96 | 550 | * is the only value that can be returned because xQueueOverwrite() will write |
| fep | 0:5ff20db10a96 | 551 | * to the queue even when the queue is already full. |
| fep | 0:5ff20db10a96 | 552 | * |
| fep | 0:5ff20db10a96 | 553 | * Example usage: |
| fep | 0:5ff20db10a96 | 554 | <pre> |
| fep | 0:5ff20db10a96 | 555 | |
| fep | 0:5ff20db10a96 | 556 | void vFunction( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 557 | { |
| fep | 0:5ff20db10a96 | 558 | QueueHandle_t xQueue; |
| fep | 0:5ff20db10a96 | 559 | uint32_t ulVarToSend, ulValReceived; |
| fep | 0:5ff20db10a96 | 560 | |
| fep | 0:5ff20db10a96 | 561 | // Create a queue to hold one uint32_t value. It is strongly |
| fep | 0:5ff20db10a96 | 562 | // recommended *not* to use xQueueOverwrite() on queues that can |
| fep | 0:5ff20db10a96 | 563 | // contain more than one value, and doing so will trigger an assertion |
| fep | 0:5ff20db10a96 | 564 | // if configASSERT() is defined. |
| fep | 0:5ff20db10a96 | 565 | xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 566 | |
| fep | 0:5ff20db10a96 | 567 | // Write the value 10 to the queue using xQueueOverwrite(). |
| fep | 0:5ff20db10a96 | 568 | ulVarToSend = 10; |
| fep | 0:5ff20db10a96 | 569 | xQueueOverwrite( xQueue, &ulVarToSend ); |
| fep | 0:5ff20db10a96 | 570 | |
| fep | 0:5ff20db10a96 | 571 | // Peeking the queue should now return 10, but leave the value 10 in |
| fep | 0:5ff20db10a96 | 572 | // the queue. A block time of zero is used as it is known that the |
| fep | 0:5ff20db10a96 | 573 | // queue holds a value. |
| fep | 0:5ff20db10a96 | 574 | ulValReceived = 0; |
| fep | 0:5ff20db10a96 | 575 | xQueuePeek( xQueue, &ulValReceived, 0 ); |
| fep | 0:5ff20db10a96 | 576 | |
| fep | 0:5ff20db10a96 | 577 | if( ulValReceived != 10 ) |
| fep | 0:5ff20db10a96 | 578 | { |
| fep | 0:5ff20db10a96 | 579 | // Error unless the item was removed by a different task. |
| fep | 0:5ff20db10a96 | 580 | } |
| fep | 0:5ff20db10a96 | 581 | |
| fep | 0:5ff20db10a96 | 582 | // The queue is still full. Use xQueueOverwrite() to overwrite the |
| fep | 0:5ff20db10a96 | 583 | // value held in the queue with 100. |
| fep | 0:5ff20db10a96 | 584 | ulVarToSend = 100; |
| fep | 0:5ff20db10a96 | 585 | xQueueOverwrite( xQueue, &ulVarToSend ); |
| fep | 0:5ff20db10a96 | 586 | |
| fep | 0:5ff20db10a96 | 587 | // This time read from the queue, leaving the queue empty once more. |
| fep | 0:5ff20db10a96 | 588 | // A block time of 0 is used again. |
| fep | 0:5ff20db10a96 | 589 | xQueueReceive( xQueue, &ulValReceived, 0 ); |
| fep | 0:5ff20db10a96 | 590 | |
| fep | 0:5ff20db10a96 | 591 | // The value read should be the last value written, even though the |
| fep | 0:5ff20db10a96 | 592 | // queue was already full when the value was written. |
| fep | 0:5ff20db10a96 | 593 | if( ulValReceived != 100 ) |
| fep | 0:5ff20db10a96 | 594 | { |
| fep | 0:5ff20db10a96 | 595 | // Error! |
| fep | 0:5ff20db10a96 | 596 | } |
| fep | 0:5ff20db10a96 | 597 | |
| fep | 0:5ff20db10a96 | 598 | // ... |
| fep | 0:5ff20db10a96 | 599 | } |
| fep | 0:5ff20db10a96 | 600 | </pre> |
| fep | 0:5ff20db10a96 | 601 | * \defgroup xQueueOverwrite xQueueOverwrite |
| fep | 0:5ff20db10a96 | 602 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 603 | */ |
| fep | 0:5ff20db10a96 | 604 | #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE ) |
| fep | 0:5ff20db10a96 | 605 | |
| fep | 0:5ff20db10a96 | 606 | |
| fep | 0:5ff20db10a96 | 607 | /** |
| fep | 0:5ff20db10a96 | 608 | * queue. h |
| fep | 0:5ff20db10a96 | 609 | * <pre> |
| fep | 0:5ff20db10a96 | 610 | BaseType_t xQueueGenericSend( |
| fep | 0:5ff20db10a96 | 611 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 612 | const void * pvItemToQueue, |
| fep | 0:5ff20db10a96 | 613 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 614 | BaseType_t xCopyPosition |
| fep | 0:5ff20db10a96 | 615 | ); |
| fep | 0:5ff20db10a96 | 616 | * </pre> |
| fep | 0:5ff20db10a96 | 617 | * |
| fep | 0:5ff20db10a96 | 618 | * It is preferred that the macros xQueueSend(), xQueueSendToFront() and |
| fep | 0:5ff20db10a96 | 619 | * xQueueSendToBack() are used in place of calling this function directly. |
| fep | 0:5ff20db10a96 | 620 | * |
| fep | 0:5ff20db10a96 | 621 | * Post an item on a queue. The item is queued by copy, not by reference. |
| fep | 0:5ff20db10a96 | 622 | * This function must not be called from an interrupt service routine. |
| fep | 0:5ff20db10a96 | 623 | * See xQueueSendFromISR () for an alternative which may be used in an ISR. |
| fep | 0:5ff20db10a96 | 624 | * |
| fep | 0:5ff20db10a96 | 625 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 626 | * |
| fep | 0:5ff20db10a96 | 627 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 628 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 629 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 630 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 631 | * |
| fep | 0:5ff20db10a96 | 632 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 633 | * waiting for space to become available on the queue, should it already |
| fep | 0:5ff20db10a96 | 634 | * be full. The call will return immediately if this is set to 0 and the |
| fep | 0:5ff20db10a96 | 635 | * queue is full. The time is defined in tick periods so the constant |
| fep | 0:5ff20db10a96 | 636 | * portTICK_PERIOD_MS should be used to convert to real time if this is required. |
| fep | 0:5ff20db10a96 | 637 | * |
| fep | 0:5ff20db10a96 | 638 | * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the |
| fep | 0:5ff20db10a96 | 639 | * item at the back of the queue, or queueSEND_TO_FRONT to place the item |
| fep | 0:5ff20db10a96 | 640 | * at the front of the queue (for high priority messages). |
| fep | 0:5ff20db10a96 | 641 | * |
| fep | 0:5ff20db10a96 | 642 | * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 643 | * |
| fep | 0:5ff20db10a96 | 644 | * Example usage: |
| fep | 0:5ff20db10a96 | 645 | <pre> |
| fep | 0:5ff20db10a96 | 646 | struct AMessage |
| fep | 0:5ff20db10a96 | 647 | { |
| fep | 0:5ff20db10a96 | 648 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 649 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 650 | } xMessage; |
| fep | 0:5ff20db10a96 | 651 | |
| fep | 0:5ff20db10a96 | 652 | uint32_t ulVar = 10UL; |
| fep | 0:5ff20db10a96 | 653 | |
| fep | 0:5ff20db10a96 | 654 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 655 | { |
| fep | 0:5ff20db10a96 | 656 | QueueHandle_t xQueue1, xQueue2; |
| fep | 0:5ff20db10a96 | 657 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 658 | |
| fep | 0:5ff20db10a96 | 659 | // Create a queue capable of containing 10 uint32_t values. |
| fep | 0:5ff20db10a96 | 660 | xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 661 | |
| fep | 0:5ff20db10a96 | 662 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 663 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 664 | xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 665 | |
| fep | 0:5ff20db10a96 | 666 | // ... |
| fep | 0:5ff20db10a96 | 667 | |
| fep | 0:5ff20db10a96 | 668 | if( xQueue1 != 0 ) |
| fep | 0:5ff20db10a96 | 669 | { |
| fep | 0:5ff20db10a96 | 670 | // Send an uint32_t. Wait for 10 ticks for space to become |
| fep | 0:5ff20db10a96 | 671 | // available if necessary. |
| fep | 0:5ff20db10a96 | 672 | if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS ) |
| fep | 0:5ff20db10a96 | 673 | { |
| fep | 0:5ff20db10a96 | 674 | // Failed to post the message, even after 10 ticks. |
| fep | 0:5ff20db10a96 | 675 | } |
| fep | 0:5ff20db10a96 | 676 | } |
| fep | 0:5ff20db10a96 | 677 | |
| fep | 0:5ff20db10a96 | 678 | if( xQueue2 != 0 ) |
| fep | 0:5ff20db10a96 | 679 | { |
| fep | 0:5ff20db10a96 | 680 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 681 | // queue is already full. |
| fep | 0:5ff20db10a96 | 682 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 683 | xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK ); |
| fep | 0:5ff20db10a96 | 684 | } |
| fep | 0:5ff20db10a96 | 685 | |
| fep | 0:5ff20db10a96 | 686 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 687 | } |
| fep | 0:5ff20db10a96 | 688 | </pre> |
| fep | 0:5ff20db10a96 | 689 | * \defgroup xQueueSend xQueueSend |
| fep | 0:5ff20db10a96 | 690 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 691 | */ |
| fep | 0:5ff20db10a96 | 692 | BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 693 | |
| fep | 0:5ff20db10a96 | 694 | /** |
| fep | 0:5ff20db10a96 | 695 | * queue. h |
| fep | 0:5ff20db10a96 | 696 | * <pre> |
| fep | 0:5ff20db10a96 | 697 | BaseType_t xQueuePeek( |
| fep | 0:5ff20db10a96 | 698 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 699 | void *pvBuffer, |
| fep | 0:5ff20db10a96 | 700 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 701 | );</pre> |
| fep | 0:5ff20db10a96 | 702 | * |
| fep | 0:5ff20db10a96 | 703 | * This is a macro that calls the xQueueGenericReceive() function. |
| fep | 0:5ff20db10a96 | 704 | * |
| fep | 0:5ff20db10a96 | 705 | * Receive an item from a queue without removing the item from the queue. |
| fep | 0:5ff20db10a96 | 706 | * The item is received by copy so a buffer of adequate size must be |
| fep | 0:5ff20db10a96 | 707 | * provided. The number of bytes copied into the buffer was defined when |
| fep | 0:5ff20db10a96 | 708 | * the queue was created. |
| fep | 0:5ff20db10a96 | 709 | * |
| fep | 0:5ff20db10a96 | 710 | * Successfully received items remain on the queue so will be returned again |
| fep | 0:5ff20db10a96 | 711 | * by the next call, or a call to xQueueReceive(). |
| fep | 0:5ff20db10a96 | 712 | * |
| fep | 0:5ff20db10a96 | 713 | * This macro must not be used in an interrupt service routine. See |
| fep | 0:5ff20db10a96 | 714 | * xQueuePeekFromISR() for an alternative that can be called from an interrupt |
| fep | 0:5ff20db10a96 | 715 | * service routine. |
| fep | 0:5ff20db10a96 | 716 | * |
| fep | 0:5ff20db10a96 | 717 | * @param xQueue The handle to the queue from which the item is to be |
| fep | 0:5ff20db10a96 | 718 | * received. |
| fep | 0:5ff20db10a96 | 719 | * |
| fep | 0:5ff20db10a96 | 720 | * @param pvBuffer Pointer to the buffer into which the received item will |
| fep | 0:5ff20db10a96 | 721 | * be copied. |
| fep | 0:5ff20db10a96 | 722 | * |
| fep | 0:5ff20db10a96 | 723 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 724 | * waiting for an item to receive should the queue be empty at the time |
| fep | 0:5ff20db10a96 | 725 | * of the call. The time is defined in tick periods so the constant |
| fep | 0:5ff20db10a96 | 726 | * portTICK_PERIOD_MS should be used to convert to real time if this is required. |
| fep | 0:5ff20db10a96 | 727 | * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue |
| fep | 0:5ff20db10a96 | 728 | * is empty. |
| fep | 0:5ff20db10a96 | 729 | * |
| fep | 0:5ff20db10a96 | 730 | * @return pdTRUE if an item was successfully received from the queue, |
| fep | 0:5ff20db10a96 | 731 | * otherwise pdFALSE. |
| fep | 0:5ff20db10a96 | 732 | * |
| fep | 0:5ff20db10a96 | 733 | * Example usage: |
| fep | 0:5ff20db10a96 | 734 | <pre> |
| fep | 0:5ff20db10a96 | 735 | struct AMessage |
| fep | 0:5ff20db10a96 | 736 | { |
| fep | 0:5ff20db10a96 | 737 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 738 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 739 | } xMessage; |
| fep | 0:5ff20db10a96 | 740 | |
| fep | 0:5ff20db10a96 | 741 | QueueHandle_t xQueue; |
| fep | 0:5ff20db10a96 | 742 | |
| fep | 0:5ff20db10a96 | 743 | // Task to create a queue and post a value. |
| fep | 0:5ff20db10a96 | 744 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 745 | { |
| fep | 0:5ff20db10a96 | 746 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 747 | |
| fep | 0:5ff20db10a96 | 748 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 749 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 750 | xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 751 | if( xQueue == 0 ) |
| fep | 0:5ff20db10a96 | 752 | { |
| fep | 0:5ff20db10a96 | 753 | // Failed to create the queue. |
| fep | 0:5ff20db10a96 | 754 | } |
| fep | 0:5ff20db10a96 | 755 | |
| fep | 0:5ff20db10a96 | 756 | // ... |
| fep | 0:5ff20db10a96 | 757 | |
| fep | 0:5ff20db10a96 | 758 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 759 | // queue is already full. |
| fep | 0:5ff20db10a96 | 760 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 761 | xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 ); |
| fep | 0:5ff20db10a96 | 762 | |
| fep | 0:5ff20db10a96 | 763 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 764 | } |
| fep | 0:5ff20db10a96 | 765 | |
| fep | 0:5ff20db10a96 | 766 | // Task to peek the data from the queue. |
| fep | 0:5ff20db10a96 | 767 | void vADifferentTask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 768 | { |
| fep | 0:5ff20db10a96 | 769 | struct AMessage *pxRxedMessage; |
| fep | 0:5ff20db10a96 | 770 | |
| fep | 0:5ff20db10a96 | 771 | if( xQueue != 0 ) |
| fep | 0:5ff20db10a96 | 772 | { |
| fep | 0:5ff20db10a96 | 773 | // Peek a message on the created queue. Block for 10 ticks if a |
| fep | 0:5ff20db10a96 | 774 | // message is not immediately available. |
| fep | 0:5ff20db10a96 | 775 | if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) ) |
| fep | 0:5ff20db10a96 | 776 | { |
| fep | 0:5ff20db10a96 | 777 | // pcRxedMessage now points to the struct AMessage variable posted |
| fep | 0:5ff20db10a96 | 778 | // by vATask, but the item still remains on the queue. |
| fep | 0:5ff20db10a96 | 779 | } |
| fep | 0:5ff20db10a96 | 780 | } |
| fep | 0:5ff20db10a96 | 781 | |
| fep | 0:5ff20db10a96 | 782 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 783 | } |
| fep | 0:5ff20db10a96 | 784 | </pre> |
| fep | 0:5ff20db10a96 | 785 | * \defgroup xQueueReceive xQueueReceive |
| fep | 0:5ff20db10a96 | 786 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 787 | */ |
| fep | 0:5ff20db10a96 | 788 | #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE ) |
| fep | 0:5ff20db10a96 | 789 | |
| fep | 0:5ff20db10a96 | 790 | /** |
| fep | 0:5ff20db10a96 | 791 | * queue. h |
| fep | 0:5ff20db10a96 | 792 | * <pre> |
| fep | 0:5ff20db10a96 | 793 | BaseType_t xQueuePeekFromISR( |
| fep | 0:5ff20db10a96 | 794 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 795 | void *pvBuffer, |
| fep | 0:5ff20db10a96 | 796 | );</pre> |
| fep | 0:5ff20db10a96 | 797 | * |
| fep | 0:5ff20db10a96 | 798 | * A version of xQueuePeek() that can be called from an interrupt service |
| fep | 0:5ff20db10a96 | 799 | * routine (ISR). |
| fep | 0:5ff20db10a96 | 800 | * |
| fep | 0:5ff20db10a96 | 801 | * Receive an item from a queue without removing the item from the queue. |
| fep | 0:5ff20db10a96 | 802 | * The item is received by copy so a buffer of adequate size must be |
| fep | 0:5ff20db10a96 | 803 | * provided. The number of bytes copied into the buffer was defined when |
| fep | 0:5ff20db10a96 | 804 | * the queue was created. |
| fep | 0:5ff20db10a96 | 805 | * |
| fep | 0:5ff20db10a96 | 806 | * Successfully received items remain on the queue so will be returned again |
| fep | 0:5ff20db10a96 | 807 | * by the next call, or a call to xQueueReceive(). |
| fep | 0:5ff20db10a96 | 808 | * |
| fep | 0:5ff20db10a96 | 809 | * @param xQueue The handle to the queue from which the item is to be |
| fep | 0:5ff20db10a96 | 810 | * received. |
| fep | 0:5ff20db10a96 | 811 | * |
| fep | 0:5ff20db10a96 | 812 | * @param pvBuffer Pointer to the buffer into which the received item will |
| fep | 0:5ff20db10a96 | 813 | * be copied. |
| fep | 0:5ff20db10a96 | 814 | * |
| fep | 0:5ff20db10a96 | 815 | * @return pdTRUE if an item was successfully received from the queue, |
| fep | 0:5ff20db10a96 | 816 | * otherwise pdFALSE. |
| fep | 0:5ff20db10a96 | 817 | * |
| fep | 0:5ff20db10a96 | 818 | * \defgroup xQueuePeekFromISR xQueuePeekFromISR |
| fep | 0:5ff20db10a96 | 819 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 820 | */ |
| fep | 0:5ff20db10a96 | 821 | BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 822 | |
| fep | 0:5ff20db10a96 | 823 | /** |
| fep | 0:5ff20db10a96 | 824 | * queue. h |
| fep | 0:5ff20db10a96 | 825 | * <pre> |
| fep | 0:5ff20db10a96 | 826 | BaseType_t xQueueReceive( |
| fep | 0:5ff20db10a96 | 827 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 828 | void *pvBuffer, |
| fep | 0:5ff20db10a96 | 829 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 830 | );</pre> |
| fep | 0:5ff20db10a96 | 831 | * |
| fep | 0:5ff20db10a96 | 832 | * This is a macro that calls the xQueueGenericReceive() function. |
| fep | 0:5ff20db10a96 | 833 | * |
| fep | 0:5ff20db10a96 | 834 | * Receive an item from a queue. The item is received by copy so a buffer of |
| fep | 0:5ff20db10a96 | 835 | * adequate size must be provided. The number of bytes copied into the buffer |
| fep | 0:5ff20db10a96 | 836 | * was defined when the queue was created. |
| fep | 0:5ff20db10a96 | 837 | * |
| fep | 0:5ff20db10a96 | 838 | * Successfully received items are removed from the queue. |
| fep | 0:5ff20db10a96 | 839 | * |
| fep | 0:5ff20db10a96 | 840 | * This function must not be used in an interrupt service routine. See |
| fep | 0:5ff20db10a96 | 841 | * xQueueReceiveFromISR for an alternative that can. |
| fep | 0:5ff20db10a96 | 842 | * |
| fep | 0:5ff20db10a96 | 843 | * @param xQueue The handle to the queue from which the item is to be |
| fep | 0:5ff20db10a96 | 844 | * received. |
| fep | 0:5ff20db10a96 | 845 | * |
| fep | 0:5ff20db10a96 | 846 | * @param pvBuffer Pointer to the buffer into which the received item will |
| fep | 0:5ff20db10a96 | 847 | * be copied. |
| fep | 0:5ff20db10a96 | 848 | * |
| fep | 0:5ff20db10a96 | 849 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 850 | * waiting for an item to receive should the queue be empty at the time |
| fep | 0:5ff20db10a96 | 851 | * of the call. xQueueReceive() will return immediately if xTicksToWait |
| fep | 0:5ff20db10a96 | 852 | * is zero and the queue is empty. The time is defined in tick periods so the |
| fep | 0:5ff20db10a96 | 853 | * constant portTICK_PERIOD_MS should be used to convert to real time if this is |
| fep | 0:5ff20db10a96 | 854 | * required. |
| fep | 0:5ff20db10a96 | 855 | * |
| fep | 0:5ff20db10a96 | 856 | * @return pdTRUE if an item was successfully received from the queue, |
| fep | 0:5ff20db10a96 | 857 | * otherwise pdFALSE. |
| fep | 0:5ff20db10a96 | 858 | * |
| fep | 0:5ff20db10a96 | 859 | * Example usage: |
| fep | 0:5ff20db10a96 | 860 | <pre> |
| fep | 0:5ff20db10a96 | 861 | struct AMessage |
| fep | 0:5ff20db10a96 | 862 | { |
| fep | 0:5ff20db10a96 | 863 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 864 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 865 | } xMessage; |
| fep | 0:5ff20db10a96 | 866 | |
| fep | 0:5ff20db10a96 | 867 | QueueHandle_t xQueue; |
| fep | 0:5ff20db10a96 | 868 | |
| fep | 0:5ff20db10a96 | 869 | // Task to create a queue and post a value. |
| fep | 0:5ff20db10a96 | 870 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 871 | { |
| fep | 0:5ff20db10a96 | 872 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 873 | |
| fep | 0:5ff20db10a96 | 874 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 875 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 876 | xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 877 | if( xQueue == 0 ) |
| fep | 0:5ff20db10a96 | 878 | { |
| fep | 0:5ff20db10a96 | 879 | // Failed to create the queue. |
| fep | 0:5ff20db10a96 | 880 | } |
| fep | 0:5ff20db10a96 | 881 | |
| fep | 0:5ff20db10a96 | 882 | // ... |
| fep | 0:5ff20db10a96 | 883 | |
| fep | 0:5ff20db10a96 | 884 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 885 | // queue is already full. |
| fep | 0:5ff20db10a96 | 886 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 887 | xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 ); |
| fep | 0:5ff20db10a96 | 888 | |
| fep | 0:5ff20db10a96 | 889 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 890 | } |
| fep | 0:5ff20db10a96 | 891 | |
| fep | 0:5ff20db10a96 | 892 | // Task to receive from the queue. |
| fep | 0:5ff20db10a96 | 893 | void vADifferentTask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 894 | { |
| fep | 0:5ff20db10a96 | 895 | struct AMessage *pxRxedMessage; |
| fep | 0:5ff20db10a96 | 896 | |
| fep | 0:5ff20db10a96 | 897 | if( xQueue != 0 ) |
| fep | 0:5ff20db10a96 | 898 | { |
| fep | 0:5ff20db10a96 | 899 | // Receive a message on the created queue. Block for 10 ticks if a |
| fep | 0:5ff20db10a96 | 900 | // message is not immediately available. |
| fep | 0:5ff20db10a96 | 901 | if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) ) |
| fep | 0:5ff20db10a96 | 902 | { |
| fep | 0:5ff20db10a96 | 903 | // pcRxedMessage now points to the struct AMessage variable posted |
| fep | 0:5ff20db10a96 | 904 | // by vATask. |
| fep | 0:5ff20db10a96 | 905 | } |
| fep | 0:5ff20db10a96 | 906 | } |
| fep | 0:5ff20db10a96 | 907 | |
| fep | 0:5ff20db10a96 | 908 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 909 | } |
| fep | 0:5ff20db10a96 | 910 | </pre> |
| fep | 0:5ff20db10a96 | 911 | * \defgroup xQueueReceive xQueueReceive |
| fep | 0:5ff20db10a96 | 912 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 913 | */ |
| fep | 0:5ff20db10a96 | 914 | #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE ) |
| fep | 0:5ff20db10a96 | 915 | |
| fep | 0:5ff20db10a96 | 916 | |
| fep | 0:5ff20db10a96 | 917 | /** |
| fep | 0:5ff20db10a96 | 918 | * queue. h |
| fep | 0:5ff20db10a96 | 919 | * <pre> |
| fep | 0:5ff20db10a96 | 920 | BaseType_t xQueueGenericReceive( |
| fep | 0:5ff20db10a96 | 921 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 922 | void *pvBuffer, |
| fep | 0:5ff20db10a96 | 923 | TickType_t xTicksToWait |
| fep | 0:5ff20db10a96 | 924 | BaseType_t xJustPeek |
| fep | 0:5ff20db10a96 | 925 | );</pre> |
| fep | 0:5ff20db10a96 | 926 | * |
| fep | 0:5ff20db10a96 | 927 | * It is preferred that the macro xQueueReceive() be used rather than calling |
| fep | 0:5ff20db10a96 | 928 | * this function directly. |
| fep | 0:5ff20db10a96 | 929 | * |
| fep | 0:5ff20db10a96 | 930 | * Receive an item from a queue. The item is received by copy so a buffer of |
| fep | 0:5ff20db10a96 | 931 | * adequate size must be provided. The number of bytes copied into the buffer |
| fep | 0:5ff20db10a96 | 932 | * was defined when the queue was created. |
| fep | 0:5ff20db10a96 | 933 | * |
| fep | 0:5ff20db10a96 | 934 | * This function must not be used in an interrupt service routine. See |
| fep | 0:5ff20db10a96 | 935 | * xQueueReceiveFromISR for an alternative that can. |
| fep | 0:5ff20db10a96 | 936 | * |
| fep | 0:5ff20db10a96 | 937 | * @param xQueue The handle to the queue from which the item is to be |
| fep | 0:5ff20db10a96 | 938 | * received. |
| fep | 0:5ff20db10a96 | 939 | * |
| fep | 0:5ff20db10a96 | 940 | * @param pvBuffer Pointer to the buffer into which the received item will |
| fep | 0:5ff20db10a96 | 941 | * be copied. |
| fep | 0:5ff20db10a96 | 942 | * |
| fep | 0:5ff20db10a96 | 943 | * @param xTicksToWait The maximum amount of time the task should block |
| fep | 0:5ff20db10a96 | 944 | * waiting for an item to receive should the queue be empty at the time |
| fep | 0:5ff20db10a96 | 945 | * of the call. The time is defined in tick periods so the constant |
| fep | 0:5ff20db10a96 | 946 | * portTICK_PERIOD_MS should be used to convert to real time if this is required. |
| fep | 0:5ff20db10a96 | 947 | * xQueueGenericReceive() will return immediately if the queue is empty and |
| fep | 0:5ff20db10a96 | 948 | * xTicksToWait is 0. |
| fep | 0:5ff20db10a96 | 949 | * |
| fep | 0:5ff20db10a96 | 950 | * @param xJustPeek When set to true, the item received from the queue is not |
| fep | 0:5ff20db10a96 | 951 | * actually removed from the queue - meaning a subsequent call to |
| fep | 0:5ff20db10a96 | 952 | * xQueueReceive() will return the same item. When set to false, the item |
| fep | 0:5ff20db10a96 | 953 | * being received from the queue is also removed from the queue. |
| fep | 0:5ff20db10a96 | 954 | * |
| fep | 0:5ff20db10a96 | 955 | * @return pdTRUE if an item was successfully received from the queue, |
| fep | 0:5ff20db10a96 | 956 | * otherwise pdFALSE. |
| fep | 0:5ff20db10a96 | 957 | * |
| fep | 0:5ff20db10a96 | 958 | * Example usage: |
| fep | 0:5ff20db10a96 | 959 | <pre> |
| fep | 0:5ff20db10a96 | 960 | struct AMessage |
| fep | 0:5ff20db10a96 | 961 | { |
| fep | 0:5ff20db10a96 | 962 | char ucMessageID; |
| fep | 0:5ff20db10a96 | 963 | char ucData[ 20 ]; |
| fep | 0:5ff20db10a96 | 964 | } xMessage; |
| fep | 0:5ff20db10a96 | 965 | |
| fep | 0:5ff20db10a96 | 966 | QueueHandle_t xQueue; |
| fep | 0:5ff20db10a96 | 967 | |
| fep | 0:5ff20db10a96 | 968 | // Task to create a queue and post a value. |
| fep | 0:5ff20db10a96 | 969 | void vATask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 970 | { |
| fep | 0:5ff20db10a96 | 971 | struct AMessage *pxMessage; |
| fep | 0:5ff20db10a96 | 972 | |
| fep | 0:5ff20db10a96 | 973 | // Create a queue capable of containing 10 pointers to AMessage structures. |
| fep | 0:5ff20db10a96 | 974 | // These should be passed by pointer as they contain a lot of data. |
| fep | 0:5ff20db10a96 | 975 | xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) ); |
| fep | 0:5ff20db10a96 | 976 | if( xQueue == 0 ) |
| fep | 0:5ff20db10a96 | 977 | { |
| fep | 0:5ff20db10a96 | 978 | // Failed to create the queue. |
| fep | 0:5ff20db10a96 | 979 | } |
| fep | 0:5ff20db10a96 | 980 | |
| fep | 0:5ff20db10a96 | 981 | // ... |
| fep | 0:5ff20db10a96 | 982 | |
| fep | 0:5ff20db10a96 | 983 | // Send a pointer to a struct AMessage object. Don't block if the |
| fep | 0:5ff20db10a96 | 984 | // queue is already full. |
| fep | 0:5ff20db10a96 | 985 | pxMessage = & xMessage; |
| fep | 0:5ff20db10a96 | 986 | xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 ); |
| fep | 0:5ff20db10a96 | 987 | |
| fep | 0:5ff20db10a96 | 988 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 989 | } |
| fep | 0:5ff20db10a96 | 990 | |
| fep | 0:5ff20db10a96 | 991 | // Task to receive from the queue. |
| fep | 0:5ff20db10a96 | 992 | void vADifferentTask( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 993 | { |
| fep | 0:5ff20db10a96 | 994 | struct AMessage *pxRxedMessage; |
| fep | 0:5ff20db10a96 | 995 | |
| fep | 0:5ff20db10a96 | 996 | if( xQueue != 0 ) |
| fep | 0:5ff20db10a96 | 997 | { |
| fep | 0:5ff20db10a96 | 998 | // Receive a message on the created queue. Block for 10 ticks if a |
| fep | 0:5ff20db10a96 | 999 | // message is not immediately available. |
| fep | 0:5ff20db10a96 | 1000 | if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) ) |
| fep | 0:5ff20db10a96 | 1001 | { |
| fep | 0:5ff20db10a96 | 1002 | // pcRxedMessage now points to the struct AMessage variable posted |
| fep | 0:5ff20db10a96 | 1003 | // by vATask. |
| fep | 0:5ff20db10a96 | 1004 | } |
| fep | 0:5ff20db10a96 | 1005 | } |
| fep | 0:5ff20db10a96 | 1006 | |
| fep | 0:5ff20db10a96 | 1007 | // ... Rest of task code. |
| fep | 0:5ff20db10a96 | 1008 | } |
| fep | 0:5ff20db10a96 | 1009 | </pre> |
| fep | 0:5ff20db10a96 | 1010 | * \defgroup xQueueReceive xQueueReceive |
| fep | 0:5ff20db10a96 | 1011 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1012 | */ |
| fep | 0:5ff20db10a96 | 1013 | BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeek ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1014 | |
| fep | 0:5ff20db10a96 | 1015 | /** |
| fep | 0:5ff20db10a96 | 1016 | * queue. h |
| fep | 0:5ff20db10a96 | 1017 | * <pre>UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );</pre> |
| fep | 0:5ff20db10a96 | 1018 | * |
| fep | 0:5ff20db10a96 | 1019 | * Return the number of messages stored in a queue. |
| fep | 0:5ff20db10a96 | 1020 | * |
| fep | 0:5ff20db10a96 | 1021 | * @param xQueue A handle to the queue being queried. |
| fep | 0:5ff20db10a96 | 1022 | * |
| fep | 0:5ff20db10a96 | 1023 | * @return The number of messages available in the queue. |
| fep | 0:5ff20db10a96 | 1024 | * |
| fep | 0:5ff20db10a96 | 1025 | * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting |
| fep | 0:5ff20db10a96 | 1026 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1027 | */ |
| fep | 0:5ff20db10a96 | 1028 | UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1029 | |
| fep | 0:5ff20db10a96 | 1030 | /** |
| fep | 0:5ff20db10a96 | 1031 | * queue. h |
| fep | 0:5ff20db10a96 | 1032 | * <pre>UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );</pre> |
| fep | 0:5ff20db10a96 | 1033 | * |
| fep | 0:5ff20db10a96 | 1034 | * Return the number of free spaces available in a queue. This is equal to the |
| fep | 0:5ff20db10a96 | 1035 | * number of items that can be sent to the queue before the queue becomes full |
| fep | 0:5ff20db10a96 | 1036 | * if no items are removed. |
| fep | 0:5ff20db10a96 | 1037 | * |
| fep | 0:5ff20db10a96 | 1038 | * @param xQueue A handle to the queue being queried. |
| fep | 0:5ff20db10a96 | 1039 | * |
| fep | 0:5ff20db10a96 | 1040 | * @return The number of spaces available in the queue. |
| fep | 0:5ff20db10a96 | 1041 | * |
| fep | 0:5ff20db10a96 | 1042 | * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting |
| fep | 0:5ff20db10a96 | 1043 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1044 | */ |
| fep | 0:5ff20db10a96 | 1045 | UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1046 | |
| fep | 0:5ff20db10a96 | 1047 | /** |
| fep | 0:5ff20db10a96 | 1048 | * queue. h |
| fep | 0:5ff20db10a96 | 1049 | * <pre>void vQueueDelete( QueueHandle_t xQueue );</pre> |
| fep | 0:5ff20db10a96 | 1050 | * |
| fep | 0:5ff20db10a96 | 1051 | * Delete a queue - freeing all the memory allocated for storing of items |
| fep | 0:5ff20db10a96 | 1052 | * placed on the queue. |
| fep | 0:5ff20db10a96 | 1053 | * |
| fep | 0:5ff20db10a96 | 1054 | * @param xQueue A handle to the queue to be deleted. |
| fep | 0:5ff20db10a96 | 1055 | * |
| fep | 0:5ff20db10a96 | 1056 | * \defgroup vQueueDelete vQueueDelete |
| fep | 0:5ff20db10a96 | 1057 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1058 | */ |
| fep | 0:5ff20db10a96 | 1059 | void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1060 | |
| fep | 0:5ff20db10a96 | 1061 | /** |
| fep | 0:5ff20db10a96 | 1062 | * queue. h |
| fep | 0:5ff20db10a96 | 1063 | * <pre> |
| fep | 0:5ff20db10a96 | 1064 | BaseType_t xQueueSendToFrontFromISR( |
| fep | 0:5ff20db10a96 | 1065 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 1066 | const void *pvItemToQueue, |
| fep | 0:5ff20db10a96 | 1067 | BaseType_t *pxHigherPriorityTaskWoken |
| fep | 0:5ff20db10a96 | 1068 | ); |
| fep | 0:5ff20db10a96 | 1069 | </pre> |
| fep | 0:5ff20db10a96 | 1070 | * |
| fep | 0:5ff20db10a96 | 1071 | * This is a macro that calls xQueueGenericSendFromISR(). |
| fep | 0:5ff20db10a96 | 1072 | * |
| fep | 0:5ff20db10a96 | 1073 | * Post an item to the front of a queue. It is safe to use this macro from |
| fep | 0:5ff20db10a96 | 1074 | * within an interrupt service routine. |
| fep | 0:5ff20db10a96 | 1075 | * |
| fep | 0:5ff20db10a96 | 1076 | * Items are queued by copy not reference so it is preferable to only |
| fep | 0:5ff20db10a96 | 1077 | * queue small items, especially when called from an ISR. In most cases |
| fep | 0:5ff20db10a96 | 1078 | * it would be preferable to store a pointer to the item being queued. |
| fep | 0:5ff20db10a96 | 1079 | * |
| fep | 0:5ff20db10a96 | 1080 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 1081 | * |
| fep | 0:5ff20db10a96 | 1082 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 1083 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 1084 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 1085 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 1086 | * |
| fep | 0:5ff20db10a96 | 1087 | * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set |
| fep | 0:5ff20db10a96 | 1088 | * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task |
| fep | 0:5ff20db10a96 | 1089 | * to unblock, and the unblocked task has a priority higher than the currently |
| fep | 0:5ff20db10a96 | 1090 | * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then |
| fep | 0:5ff20db10a96 | 1091 | * a context switch should be requested before the interrupt is exited. |
| fep | 0:5ff20db10a96 | 1092 | * |
| fep | 0:5ff20db10a96 | 1093 | * @return pdTRUE if the data was successfully sent to the queue, otherwise |
| fep | 0:5ff20db10a96 | 1094 | * errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 1095 | * |
| fep | 0:5ff20db10a96 | 1096 | * Example usage for buffered IO (where the ISR can obtain more than one value |
| fep | 0:5ff20db10a96 | 1097 | * per call): |
| fep | 0:5ff20db10a96 | 1098 | <pre> |
| fep | 0:5ff20db10a96 | 1099 | void vBufferISR( void ) |
| fep | 0:5ff20db10a96 | 1100 | { |
| fep | 0:5ff20db10a96 | 1101 | char cIn; |
| fep | 0:5ff20db10a96 | 1102 | BaseType_t xHigherPrioritTaskWoken; |
| fep | 0:5ff20db10a96 | 1103 | |
| fep | 0:5ff20db10a96 | 1104 | // We have not woken a task at the start of the ISR. |
| fep | 0:5ff20db10a96 | 1105 | xHigherPriorityTaskWoken = pdFALSE; |
| fep | 0:5ff20db10a96 | 1106 | |
| fep | 0:5ff20db10a96 | 1107 | // Loop until the buffer is empty. |
| fep | 0:5ff20db10a96 | 1108 | do |
| fep | 0:5ff20db10a96 | 1109 | { |
| fep | 0:5ff20db10a96 | 1110 | // Obtain a byte from the buffer. |
| fep | 0:5ff20db10a96 | 1111 | cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); |
| fep | 0:5ff20db10a96 | 1112 | |
| fep | 0:5ff20db10a96 | 1113 | // Post the byte. |
| fep | 0:5ff20db10a96 | 1114 | xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); |
| fep | 0:5ff20db10a96 | 1115 | |
| fep | 0:5ff20db10a96 | 1116 | } while( portINPUT_BYTE( BUFFER_COUNT ) ); |
| fep | 0:5ff20db10a96 | 1117 | |
| fep | 0:5ff20db10a96 | 1118 | // Now the buffer is empty we can switch context if necessary. |
| fep | 0:5ff20db10a96 | 1119 | if( xHigherPriorityTaskWoken ) |
| fep | 0:5ff20db10a96 | 1120 | { |
| fep | 0:5ff20db10a96 | 1121 | taskYIELD (); |
| fep | 0:5ff20db10a96 | 1122 | } |
| fep | 0:5ff20db10a96 | 1123 | } |
| fep | 0:5ff20db10a96 | 1124 | </pre> |
| fep | 0:5ff20db10a96 | 1125 | * |
| fep | 0:5ff20db10a96 | 1126 | * \defgroup xQueueSendFromISR xQueueSendFromISR |
| fep | 0:5ff20db10a96 | 1127 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1128 | */ |
| fep | 0:5ff20db10a96 | 1129 | #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT ) |
| fep | 0:5ff20db10a96 | 1130 | |
| fep | 0:5ff20db10a96 | 1131 | |
| fep | 0:5ff20db10a96 | 1132 | /** |
| fep | 0:5ff20db10a96 | 1133 | * queue. h |
| fep | 0:5ff20db10a96 | 1134 | * <pre> |
| fep | 0:5ff20db10a96 | 1135 | BaseType_t xQueueSendToBackFromISR( |
| fep | 0:5ff20db10a96 | 1136 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 1137 | const void *pvItemToQueue, |
| fep | 0:5ff20db10a96 | 1138 | BaseType_t *pxHigherPriorityTaskWoken |
| fep | 0:5ff20db10a96 | 1139 | ); |
| fep | 0:5ff20db10a96 | 1140 | </pre> |
| fep | 0:5ff20db10a96 | 1141 | * |
| fep | 0:5ff20db10a96 | 1142 | * This is a macro that calls xQueueGenericSendFromISR(). |
| fep | 0:5ff20db10a96 | 1143 | * |
| fep | 0:5ff20db10a96 | 1144 | * Post an item to the back of a queue. It is safe to use this macro from |
| fep | 0:5ff20db10a96 | 1145 | * within an interrupt service routine. |
| fep | 0:5ff20db10a96 | 1146 | * |
| fep | 0:5ff20db10a96 | 1147 | * Items are queued by copy not reference so it is preferable to only |
| fep | 0:5ff20db10a96 | 1148 | * queue small items, especially when called from an ISR. In most cases |
| fep | 0:5ff20db10a96 | 1149 | * it would be preferable to store a pointer to the item being queued. |
| fep | 0:5ff20db10a96 | 1150 | * |
| fep | 0:5ff20db10a96 | 1151 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 1152 | * |
| fep | 0:5ff20db10a96 | 1153 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 1154 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 1155 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 1156 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 1157 | * |
| fep | 0:5ff20db10a96 | 1158 | * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set |
| fep | 0:5ff20db10a96 | 1159 | * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task |
| fep | 0:5ff20db10a96 | 1160 | * to unblock, and the unblocked task has a priority higher than the currently |
| fep | 0:5ff20db10a96 | 1161 | * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then |
| fep | 0:5ff20db10a96 | 1162 | * a context switch should be requested before the interrupt is exited. |
| fep | 0:5ff20db10a96 | 1163 | * |
| fep | 0:5ff20db10a96 | 1164 | * @return pdTRUE if the data was successfully sent to the queue, otherwise |
| fep | 0:5ff20db10a96 | 1165 | * errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 1166 | * |
| fep | 0:5ff20db10a96 | 1167 | * Example usage for buffered IO (where the ISR can obtain more than one value |
| fep | 0:5ff20db10a96 | 1168 | * per call): |
| fep | 0:5ff20db10a96 | 1169 | <pre> |
| fep | 0:5ff20db10a96 | 1170 | void vBufferISR( void ) |
| fep | 0:5ff20db10a96 | 1171 | { |
| fep | 0:5ff20db10a96 | 1172 | char cIn; |
| fep | 0:5ff20db10a96 | 1173 | BaseType_t xHigherPriorityTaskWoken; |
| fep | 0:5ff20db10a96 | 1174 | |
| fep | 0:5ff20db10a96 | 1175 | // We have not woken a task at the start of the ISR. |
| fep | 0:5ff20db10a96 | 1176 | xHigherPriorityTaskWoken = pdFALSE; |
| fep | 0:5ff20db10a96 | 1177 | |
| fep | 0:5ff20db10a96 | 1178 | // Loop until the buffer is empty. |
| fep | 0:5ff20db10a96 | 1179 | do |
| fep | 0:5ff20db10a96 | 1180 | { |
| fep | 0:5ff20db10a96 | 1181 | // Obtain a byte from the buffer. |
| fep | 0:5ff20db10a96 | 1182 | cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); |
| fep | 0:5ff20db10a96 | 1183 | |
| fep | 0:5ff20db10a96 | 1184 | // Post the byte. |
| fep | 0:5ff20db10a96 | 1185 | xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); |
| fep | 0:5ff20db10a96 | 1186 | |
| fep | 0:5ff20db10a96 | 1187 | } while( portINPUT_BYTE( BUFFER_COUNT ) ); |
| fep | 0:5ff20db10a96 | 1188 | |
| fep | 0:5ff20db10a96 | 1189 | // Now the buffer is empty we can switch context if necessary. |
| fep | 0:5ff20db10a96 | 1190 | if( xHigherPriorityTaskWoken ) |
| fep | 0:5ff20db10a96 | 1191 | { |
| fep | 0:5ff20db10a96 | 1192 | taskYIELD (); |
| fep | 0:5ff20db10a96 | 1193 | } |
| fep | 0:5ff20db10a96 | 1194 | } |
| fep | 0:5ff20db10a96 | 1195 | </pre> |
| fep | 0:5ff20db10a96 | 1196 | * |
| fep | 0:5ff20db10a96 | 1197 | * \defgroup xQueueSendFromISR xQueueSendFromISR |
| fep | 0:5ff20db10a96 | 1198 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1199 | */ |
| fep | 0:5ff20db10a96 | 1200 | #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) |
| fep | 0:5ff20db10a96 | 1201 | |
| fep | 0:5ff20db10a96 | 1202 | /** |
| fep | 0:5ff20db10a96 | 1203 | * queue. h |
| fep | 0:5ff20db10a96 | 1204 | * <pre> |
| fep | 0:5ff20db10a96 | 1205 | BaseType_t xQueueOverwriteFromISR( |
| fep | 0:5ff20db10a96 | 1206 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 1207 | const void * pvItemToQueue, |
| fep | 0:5ff20db10a96 | 1208 | BaseType_t *pxHigherPriorityTaskWoken |
| fep | 0:5ff20db10a96 | 1209 | ); |
| fep | 0:5ff20db10a96 | 1210 | * </pre> |
| fep | 0:5ff20db10a96 | 1211 | * |
| fep | 0:5ff20db10a96 | 1212 | * A version of xQueueOverwrite() that can be used in an interrupt service |
| fep | 0:5ff20db10a96 | 1213 | * routine (ISR). |
| fep | 0:5ff20db10a96 | 1214 | * |
| fep | 0:5ff20db10a96 | 1215 | * Only for use with queues that can hold a single item - so the queue is either |
| fep | 0:5ff20db10a96 | 1216 | * empty or full. |
| fep | 0:5ff20db10a96 | 1217 | * |
| fep | 0:5ff20db10a96 | 1218 | * Post an item on a queue. If the queue is already full then overwrite the |
| fep | 0:5ff20db10a96 | 1219 | * value held in the queue. The item is queued by copy, not by reference. |
| fep | 0:5ff20db10a96 | 1220 | * |
| fep | 0:5ff20db10a96 | 1221 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 1222 | * |
| fep | 0:5ff20db10a96 | 1223 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 1224 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 1225 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 1226 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 1227 | * |
| fep | 0:5ff20db10a96 | 1228 | * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set |
| fep | 0:5ff20db10a96 | 1229 | * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task |
| fep | 0:5ff20db10a96 | 1230 | * to unblock, and the unblocked task has a priority higher than the currently |
| fep | 0:5ff20db10a96 | 1231 | * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then |
| fep | 0:5ff20db10a96 | 1232 | * a context switch should be requested before the interrupt is exited. |
| fep | 0:5ff20db10a96 | 1233 | * |
| fep | 0:5ff20db10a96 | 1234 | * @return xQueueOverwriteFromISR() is a macro that calls |
| fep | 0:5ff20db10a96 | 1235 | * xQueueGenericSendFromISR(), and therefore has the same return values as |
| fep | 0:5ff20db10a96 | 1236 | * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be |
| fep | 0:5ff20db10a96 | 1237 | * returned because xQueueOverwriteFromISR() will write to the queue even when |
| fep | 0:5ff20db10a96 | 1238 | * the queue is already full. |
| fep | 0:5ff20db10a96 | 1239 | * |
| fep | 0:5ff20db10a96 | 1240 | * Example usage: |
| fep | 0:5ff20db10a96 | 1241 | <pre> |
| fep | 0:5ff20db10a96 | 1242 | |
| fep | 0:5ff20db10a96 | 1243 | QueueHandle_t xQueue; |
| fep | 0:5ff20db10a96 | 1244 | |
| fep | 0:5ff20db10a96 | 1245 | void vFunction( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 1246 | { |
| fep | 0:5ff20db10a96 | 1247 | // Create a queue to hold one uint32_t value. It is strongly |
| fep | 0:5ff20db10a96 | 1248 | // recommended *not* to use xQueueOverwriteFromISR() on queues that can |
| fep | 0:5ff20db10a96 | 1249 | // contain more than one value, and doing so will trigger an assertion |
| fep | 0:5ff20db10a96 | 1250 | // if configASSERT() is defined. |
| fep | 0:5ff20db10a96 | 1251 | xQueue = xQueueCreate( 1, sizeof( uint32_t ) ); |
| fep | 0:5ff20db10a96 | 1252 | } |
| fep | 0:5ff20db10a96 | 1253 | |
| fep | 0:5ff20db10a96 | 1254 | void vAnInterruptHandler( void ) |
| fep | 0:5ff20db10a96 | 1255 | { |
| fep | 0:5ff20db10a96 | 1256 | // xHigherPriorityTaskWoken must be set to pdFALSE before it is used. |
| fep | 0:5ff20db10a96 | 1257 | BaseType_t xHigherPriorityTaskWoken = pdFALSE; |
| fep | 0:5ff20db10a96 | 1258 | uint32_t ulVarToSend, ulValReceived; |
| fep | 0:5ff20db10a96 | 1259 | |
| fep | 0:5ff20db10a96 | 1260 | // Write the value 10 to the queue using xQueueOverwriteFromISR(). |
| fep | 0:5ff20db10a96 | 1261 | ulVarToSend = 10; |
| fep | 0:5ff20db10a96 | 1262 | xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken ); |
| fep | 0:5ff20db10a96 | 1263 | |
| fep | 0:5ff20db10a96 | 1264 | // The queue is full, but calling xQueueOverwriteFromISR() again will still |
| fep | 0:5ff20db10a96 | 1265 | // pass because the value held in the queue will be overwritten with the |
| fep | 0:5ff20db10a96 | 1266 | // new value. |
| fep | 0:5ff20db10a96 | 1267 | ulVarToSend = 100; |
| fep | 0:5ff20db10a96 | 1268 | xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken ); |
| fep | 0:5ff20db10a96 | 1269 | |
| fep | 0:5ff20db10a96 | 1270 | // Reading from the queue will now return 100. |
| fep | 0:5ff20db10a96 | 1271 | |
| fep | 0:5ff20db10a96 | 1272 | // ... |
| fep | 0:5ff20db10a96 | 1273 | |
| fep | 0:5ff20db10a96 | 1274 | if( xHigherPrioritytaskWoken == pdTRUE ) |
| fep | 0:5ff20db10a96 | 1275 | { |
| fep | 0:5ff20db10a96 | 1276 | // Writing to the queue caused a task to unblock and the unblocked task |
| fep | 0:5ff20db10a96 | 1277 | // has a priority higher than or equal to the priority of the currently |
| fep | 0:5ff20db10a96 | 1278 | // executing task (the task this interrupt interrupted). Perform a context |
| fep | 0:5ff20db10a96 | 1279 | // switch so this interrupt returns directly to the unblocked task. |
| fep | 0:5ff20db10a96 | 1280 | portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port. |
| fep | 0:5ff20db10a96 | 1281 | } |
| fep | 0:5ff20db10a96 | 1282 | } |
| fep | 0:5ff20db10a96 | 1283 | </pre> |
| fep | 0:5ff20db10a96 | 1284 | * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR |
| fep | 0:5ff20db10a96 | 1285 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1286 | */ |
| fep | 0:5ff20db10a96 | 1287 | #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE ) |
| fep | 0:5ff20db10a96 | 1288 | |
| fep | 0:5ff20db10a96 | 1289 | /** |
| fep | 0:5ff20db10a96 | 1290 | * queue. h |
| fep | 0:5ff20db10a96 | 1291 | * <pre> |
| fep | 0:5ff20db10a96 | 1292 | BaseType_t xQueueSendFromISR( |
| fep | 0:5ff20db10a96 | 1293 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 1294 | const void *pvItemToQueue, |
| fep | 0:5ff20db10a96 | 1295 | BaseType_t *pxHigherPriorityTaskWoken |
| fep | 0:5ff20db10a96 | 1296 | ); |
| fep | 0:5ff20db10a96 | 1297 | </pre> |
| fep | 0:5ff20db10a96 | 1298 | * |
| fep | 0:5ff20db10a96 | 1299 | * This is a macro that calls xQueueGenericSendFromISR(). It is included |
| fep | 0:5ff20db10a96 | 1300 | * for backward compatibility with versions of FreeRTOS.org that did not |
| fep | 0:5ff20db10a96 | 1301 | * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR() |
| fep | 0:5ff20db10a96 | 1302 | * macros. |
| fep | 0:5ff20db10a96 | 1303 | * |
| fep | 0:5ff20db10a96 | 1304 | * Post an item to the back of a queue. It is safe to use this function from |
| fep | 0:5ff20db10a96 | 1305 | * within an interrupt service routine. |
| fep | 0:5ff20db10a96 | 1306 | * |
| fep | 0:5ff20db10a96 | 1307 | * Items are queued by copy not reference so it is preferable to only |
| fep | 0:5ff20db10a96 | 1308 | * queue small items, especially when called from an ISR. In most cases |
| fep | 0:5ff20db10a96 | 1309 | * it would be preferable to store a pointer to the item being queued. |
| fep | 0:5ff20db10a96 | 1310 | * |
| fep | 0:5ff20db10a96 | 1311 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 1312 | * |
| fep | 0:5ff20db10a96 | 1313 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 1314 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 1315 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 1316 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 1317 | * |
| fep | 0:5ff20db10a96 | 1318 | * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set |
| fep | 0:5ff20db10a96 | 1319 | * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task |
| fep | 0:5ff20db10a96 | 1320 | * to unblock, and the unblocked task has a priority higher than the currently |
| fep | 0:5ff20db10a96 | 1321 | * running task. If xQueueSendFromISR() sets this value to pdTRUE then |
| fep | 0:5ff20db10a96 | 1322 | * a context switch should be requested before the interrupt is exited. |
| fep | 0:5ff20db10a96 | 1323 | * |
| fep | 0:5ff20db10a96 | 1324 | * @return pdTRUE if the data was successfully sent to the queue, otherwise |
| fep | 0:5ff20db10a96 | 1325 | * errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 1326 | * |
| fep | 0:5ff20db10a96 | 1327 | * Example usage for buffered IO (where the ISR can obtain more than one value |
| fep | 0:5ff20db10a96 | 1328 | * per call): |
| fep | 0:5ff20db10a96 | 1329 | <pre> |
| fep | 0:5ff20db10a96 | 1330 | void vBufferISR( void ) |
| fep | 0:5ff20db10a96 | 1331 | { |
| fep | 0:5ff20db10a96 | 1332 | char cIn; |
| fep | 0:5ff20db10a96 | 1333 | BaseType_t xHigherPriorityTaskWoken; |
| fep | 0:5ff20db10a96 | 1334 | |
| fep | 0:5ff20db10a96 | 1335 | // We have not woken a task at the start of the ISR. |
| fep | 0:5ff20db10a96 | 1336 | xHigherPriorityTaskWoken = pdFALSE; |
| fep | 0:5ff20db10a96 | 1337 | |
| fep | 0:5ff20db10a96 | 1338 | // Loop until the buffer is empty. |
| fep | 0:5ff20db10a96 | 1339 | do |
| fep | 0:5ff20db10a96 | 1340 | { |
| fep | 0:5ff20db10a96 | 1341 | // Obtain a byte from the buffer. |
| fep | 0:5ff20db10a96 | 1342 | cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); |
| fep | 0:5ff20db10a96 | 1343 | |
| fep | 0:5ff20db10a96 | 1344 | // Post the byte. |
| fep | 0:5ff20db10a96 | 1345 | xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken ); |
| fep | 0:5ff20db10a96 | 1346 | |
| fep | 0:5ff20db10a96 | 1347 | } while( portINPUT_BYTE( BUFFER_COUNT ) ); |
| fep | 0:5ff20db10a96 | 1348 | |
| fep | 0:5ff20db10a96 | 1349 | // Now the buffer is empty we can switch context if necessary. |
| fep | 0:5ff20db10a96 | 1350 | if( xHigherPriorityTaskWoken ) |
| fep | 0:5ff20db10a96 | 1351 | { |
| fep | 0:5ff20db10a96 | 1352 | // Actual macro used here is port specific. |
| fep | 0:5ff20db10a96 | 1353 | portYIELD_FROM_ISR (); |
| fep | 0:5ff20db10a96 | 1354 | } |
| fep | 0:5ff20db10a96 | 1355 | } |
| fep | 0:5ff20db10a96 | 1356 | </pre> |
| fep | 0:5ff20db10a96 | 1357 | * |
| fep | 0:5ff20db10a96 | 1358 | * \defgroup xQueueSendFromISR xQueueSendFromISR |
| fep | 0:5ff20db10a96 | 1359 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1360 | */ |
| fep | 0:5ff20db10a96 | 1361 | #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK ) |
| fep | 0:5ff20db10a96 | 1362 | |
| fep | 0:5ff20db10a96 | 1363 | /** |
| fep | 0:5ff20db10a96 | 1364 | * queue. h |
| fep | 0:5ff20db10a96 | 1365 | * <pre> |
| fep | 0:5ff20db10a96 | 1366 | BaseType_t xQueueGenericSendFromISR( |
| fep | 0:5ff20db10a96 | 1367 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 1368 | const void *pvItemToQueue, |
| fep | 0:5ff20db10a96 | 1369 | BaseType_t *pxHigherPriorityTaskWoken, |
| fep | 0:5ff20db10a96 | 1370 | BaseType_t xCopyPosition |
| fep | 0:5ff20db10a96 | 1371 | ); |
| fep | 0:5ff20db10a96 | 1372 | </pre> |
| fep | 0:5ff20db10a96 | 1373 | * |
| fep | 0:5ff20db10a96 | 1374 | * It is preferred that the macros xQueueSendFromISR(), |
| fep | 0:5ff20db10a96 | 1375 | * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place |
| fep | 0:5ff20db10a96 | 1376 | * of calling this function directly. xQueueGiveFromISR() is an |
| fep | 0:5ff20db10a96 | 1377 | * equivalent for use by semaphores that don't actually copy any data. |
| fep | 0:5ff20db10a96 | 1378 | * |
| fep | 0:5ff20db10a96 | 1379 | * Post an item on a queue. It is safe to use this function from within an |
| fep | 0:5ff20db10a96 | 1380 | * interrupt service routine. |
| fep | 0:5ff20db10a96 | 1381 | * |
| fep | 0:5ff20db10a96 | 1382 | * Items are queued by copy not reference so it is preferable to only |
| fep | 0:5ff20db10a96 | 1383 | * queue small items, especially when called from an ISR. In most cases |
| fep | 0:5ff20db10a96 | 1384 | * it would be preferable to store a pointer to the item being queued. |
| fep | 0:5ff20db10a96 | 1385 | * |
| fep | 0:5ff20db10a96 | 1386 | * @param xQueue The handle to the queue on which the item is to be posted. |
| fep | 0:5ff20db10a96 | 1387 | * |
| fep | 0:5ff20db10a96 | 1388 | * @param pvItemToQueue A pointer to the item that is to be placed on the |
| fep | 0:5ff20db10a96 | 1389 | * queue. The size of the items the queue will hold was defined when the |
| fep | 0:5ff20db10a96 | 1390 | * queue was created, so this many bytes will be copied from pvItemToQueue |
| fep | 0:5ff20db10a96 | 1391 | * into the queue storage area. |
| fep | 0:5ff20db10a96 | 1392 | * |
| fep | 0:5ff20db10a96 | 1393 | * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set |
| fep | 0:5ff20db10a96 | 1394 | * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task |
| fep | 0:5ff20db10a96 | 1395 | * to unblock, and the unblocked task has a priority higher than the currently |
| fep | 0:5ff20db10a96 | 1396 | * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then |
| fep | 0:5ff20db10a96 | 1397 | * a context switch should be requested before the interrupt is exited. |
| fep | 0:5ff20db10a96 | 1398 | * |
| fep | 0:5ff20db10a96 | 1399 | * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the |
| fep | 0:5ff20db10a96 | 1400 | * item at the back of the queue, or queueSEND_TO_FRONT to place the item |
| fep | 0:5ff20db10a96 | 1401 | * at the front of the queue (for high priority messages). |
| fep | 0:5ff20db10a96 | 1402 | * |
| fep | 0:5ff20db10a96 | 1403 | * @return pdTRUE if the data was successfully sent to the queue, otherwise |
| fep | 0:5ff20db10a96 | 1404 | * errQUEUE_FULL. |
| fep | 0:5ff20db10a96 | 1405 | * |
| fep | 0:5ff20db10a96 | 1406 | * Example usage for buffered IO (where the ISR can obtain more than one value |
| fep | 0:5ff20db10a96 | 1407 | * per call): |
| fep | 0:5ff20db10a96 | 1408 | <pre> |
| fep | 0:5ff20db10a96 | 1409 | void vBufferISR( void ) |
| fep | 0:5ff20db10a96 | 1410 | { |
| fep | 0:5ff20db10a96 | 1411 | char cIn; |
| fep | 0:5ff20db10a96 | 1412 | BaseType_t xHigherPriorityTaskWokenByPost; |
| fep | 0:5ff20db10a96 | 1413 | |
| fep | 0:5ff20db10a96 | 1414 | // We have not woken a task at the start of the ISR. |
| fep | 0:5ff20db10a96 | 1415 | xHigherPriorityTaskWokenByPost = pdFALSE; |
| fep | 0:5ff20db10a96 | 1416 | |
| fep | 0:5ff20db10a96 | 1417 | // Loop until the buffer is empty. |
| fep | 0:5ff20db10a96 | 1418 | do |
| fep | 0:5ff20db10a96 | 1419 | { |
| fep | 0:5ff20db10a96 | 1420 | // Obtain a byte from the buffer. |
| fep | 0:5ff20db10a96 | 1421 | cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS ); |
| fep | 0:5ff20db10a96 | 1422 | |
| fep | 0:5ff20db10a96 | 1423 | // Post each byte. |
| fep | 0:5ff20db10a96 | 1424 | xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK ); |
| fep | 0:5ff20db10a96 | 1425 | |
| fep | 0:5ff20db10a96 | 1426 | } while( portINPUT_BYTE( BUFFER_COUNT ) ); |
| fep | 0:5ff20db10a96 | 1427 | |
| fep | 0:5ff20db10a96 | 1428 | // Now the buffer is empty we can switch context if necessary. Note that the |
| fep | 0:5ff20db10a96 | 1429 | // name of the yield function required is port specific. |
| fep | 0:5ff20db10a96 | 1430 | if( xHigherPriorityTaskWokenByPost ) |
| fep | 0:5ff20db10a96 | 1431 | { |
| fep | 0:5ff20db10a96 | 1432 | taskYIELD_YIELD_FROM_ISR(); |
| fep | 0:5ff20db10a96 | 1433 | } |
| fep | 0:5ff20db10a96 | 1434 | } |
| fep | 0:5ff20db10a96 | 1435 | </pre> |
| fep | 0:5ff20db10a96 | 1436 | * |
| fep | 0:5ff20db10a96 | 1437 | * \defgroup xQueueSendFromISR xQueueSendFromISR |
| fep | 0:5ff20db10a96 | 1438 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1439 | */ |
| fep | 0:5ff20db10a96 | 1440 | BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1441 | BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1442 | |
| fep | 0:5ff20db10a96 | 1443 | /** |
| fep | 0:5ff20db10a96 | 1444 | * queue. h |
| fep | 0:5ff20db10a96 | 1445 | * <pre> |
| fep | 0:5ff20db10a96 | 1446 | BaseType_t xQueueReceiveFromISR( |
| fep | 0:5ff20db10a96 | 1447 | QueueHandle_t xQueue, |
| fep | 0:5ff20db10a96 | 1448 | void *pvBuffer, |
| fep | 0:5ff20db10a96 | 1449 | BaseType_t *pxTaskWoken |
| fep | 0:5ff20db10a96 | 1450 | ); |
| fep | 0:5ff20db10a96 | 1451 | * </pre> |
| fep | 0:5ff20db10a96 | 1452 | * |
| fep | 0:5ff20db10a96 | 1453 | * Receive an item from a queue. It is safe to use this function from within an |
| fep | 0:5ff20db10a96 | 1454 | * interrupt service routine. |
| fep | 0:5ff20db10a96 | 1455 | * |
| fep | 0:5ff20db10a96 | 1456 | * @param xQueue The handle to the queue from which the item is to be |
| fep | 0:5ff20db10a96 | 1457 | * received. |
| fep | 0:5ff20db10a96 | 1458 | * |
| fep | 0:5ff20db10a96 | 1459 | * @param pvBuffer Pointer to the buffer into which the received item will |
| fep | 0:5ff20db10a96 | 1460 | * be copied. |
| fep | 0:5ff20db10a96 | 1461 | * |
| fep | 0:5ff20db10a96 | 1462 | * @param pxTaskWoken A task may be blocked waiting for space to become |
| fep | 0:5ff20db10a96 | 1463 | * available on the queue. If xQueueReceiveFromISR causes such a task to |
| fep | 0:5ff20db10a96 | 1464 | * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will |
| fep | 0:5ff20db10a96 | 1465 | * remain unchanged. |
| fep | 0:5ff20db10a96 | 1466 | * |
| fep | 0:5ff20db10a96 | 1467 | * @return pdTRUE if an item was successfully received from the queue, |
| fep | 0:5ff20db10a96 | 1468 | * otherwise pdFALSE. |
| fep | 0:5ff20db10a96 | 1469 | * |
| fep | 0:5ff20db10a96 | 1470 | * Example usage: |
| fep | 0:5ff20db10a96 | 1471 | <pre> |
| fep | 0:5ff20db10a96 | 1472 | |
| fep | 0:5ff20db10a96 | 1473 | QueueHandle_t xQueue; |
| fep | 0:5ff20db10a96 | 1474 | |
| fep | 0:5ff20db10a96 | 1475 | // Function to create a queue and post some values. |
| fep | 0:5ff20db10a96 | 1476 | void vAFunction( void *pvParameters ) |
| fep | 0:5ff20db10a96 | 1477 | { |
| fep | 0:5ff20db10a96 | 1478 | char cValueToPost; |
| fep | 0:5ff20db10a96 | 1479 | const TickType_t xTicksToWait = ( TickType_t )0xff; |
| fep | 0:5ff20db10a96 | 1480 | |
| fep | 0:5ff20db10a96 | 1481 | // Create a queue capable of containing 10 characters. |
| fep | 0:5ff20db10a96 | 1482 | xQueue = xQueueCreate( 10, sizeof( char ) ); |
| fep | 0:5ff20db10a96 | 1483 | if( xQueue == 0 ) |
| fep | 0:5ff20db10a96 | 1484 | { |
| fep | 0:5ff20db10a96 | 1485 | // Failed to create the queue. |
| fep | 0:5ff20db10a96 | 1486 | } |
| fep | 0:5ff20db10a96 | 1487 | |
| fep | 0:5ff20db10a96 | 1488 | // ... |
| fep | 0:5ff20db10a96 | 1489 | |
| fep | 0:5ff20db10a96 | 1490 | // Post some characters that will be used within an ISR. If the queue |
| fep | 0:5ff20db10a96 | 1491 | // is full then this task will block for xTicksToWait ticks. |
| fep | 0:5ff20db10a96 | 1492 | cValueToPost = 'a'; |
| fep | 0:5ff20db10a96 | 1493 | xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait ); |
| fep | 0:5ff20db10a96 | 1494 | cValueToPost = 'b'; |
| fep | 0:5ff20db10a96 | 1495 | xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait ); |
| fep | 0:5ff20db10a96 | 1496 | |
| fep | 0:5ff20db10a96 | 1497 | // ... keep posting characters ... this task may block when the queue |
| fep | 0:5ff20db10a96 | 1498 | // becomes full. |
| fep | 0:5ff20db10a96 | 1499 | |
| fep | 0:5ff20db10a96 | 1500 | cValueToPost = 'c'; |
| fep | 0:5ff20db10a96 | 1501 | xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait ); |
| fep | 0:5ff20db10a96 | 1502 | } |
| fep | 0:5ff20db10a96 | 1503 | |
| fep | 0:5ff20db10a96 | 1504 | // ISR that outputs all the characters received on the queue. |
| fep | 0:5ff20db10a96 | 1505 | void vISR_Routine( void ) |
| fep | 0:5ff20db10a96 | 1506 | { |
| fep | 0:5ff20db10a96 | 1507 | BaseType_t xTaskWokenByReceive = pdFALSE; |
| fep | 0:5ff20db10a96 | 1508 | char cRxedChar; |
| fep | 0:5ff20db10a96 | 1509 | |
| fep | 0:5ff20db10a96 | 1510 | while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) ) |
| fep | 0:5ff20db10a96 | 1511 | { |
| fep | 0:5ff20db10a96 | 1512 | // A character was received. Output the character now. |
| fep | 0:5ff20db10a96 | 1513 | vOutputCharacter( cRxedChar ); |
| fep | 0:5ff20db10a96 | 1514 | |
| fep | 0:5ff20db10a96 | 1515 | // If removing the character from the queue woke the task that was |
| fep | 0:5ff20db10a96 | 1516 | // posting onto the queue cTaskWokenByReceive will have been set to |
| fep | 0:5ff20db10a96 | 1517 | // pdTRUE. No matter how many times this loop iterates only one |
| fep | 0:5ff20db10a96 | 1518 | // task will be woken. |
| fep | 0:5ff20db10a96 | 1519 | } |
| fep | 0:5ff20db10a96 | 1520 | |
| fep | 0:5ff20db10a96 | 1521 | if( cTaskWokenByPost != ( char ) pdFALSE; |
| fep | 0:5ff20db10a96 | 1522 | { |
| fep | 0:5ff20db10a96 | 1523 | taskYIELD (); |
| fep | 0:5ff20db10a96 | 1524 | } |
| fep | 0:5ff20db10a96 | 1525 | } |
| fep | 0:5ff20db10a96 | 1526 | </pre> |
| fep | 0:5ff20db10a96 | 1527 | * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR |
| fep | 0:5ff20db10a96 | 1528 | * \ingroup QueueManagement |
| fep | 0:5ff20db10a96 | 1529 | */ |
| fep | 0:5ff20db10a96 | 1530 | BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1531 | |
| fep | 0:5ff20db10a96 | 1532 | /* |
| fep | 0:5ff20db10a96 | 1533 | * Utilities to query queues that are safe to use from an ISR. These utilities |
| fep | 0:5ff20db10a96 | 1534 | * should be used only from witin an ISR, or within a critical section. |
| fep | 0:5ff20db10a96 | 1535 | */ |
| fep | 0:5ff20db10a96 | 1536 | BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1537 | BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1538 | UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1539 | |
| fep | 0:5ff20db10a96 | 1540 | /* |
| fep | 0:5ff20db10a96 | 1541 | * The functions defined above are for passing data to and from tasks. The |
| fep | 0:5ff20db10a96 | 1542 | * functions below are the equivalents for passing data to and from |
| fep | 0:5ff20db10a96 | 1543 | * co-routines. |
| fep | 0:5ff20db10a96 | 1544 | * |
| fep | 0:5ff20db10a96 | 1545 | * These functions are called from the co-routine macro implementation and |
| fep | 0:5ff20db10a96 | 1546 | * should not be called directly from application code. Instead use the macro |
| fep | 0:5ff20db10a96 | 1547 | * wrappers defined within croutine.h. |
| fep | 0:5ff20db10a96 | 1548 | */ |
| fep | 0:5ff20db10a96 | 1549 | BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken ); |
| fep | 0:5ff20db10a96 | 1550 | BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken ); |
| fep | 0:5ff20db10a96 | 1551 | BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait ); |
| fep | 0:5ff20db10a96 | 1552 | BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait ); |
| fep | 0:5ff20db10a96 | 1553 | |
| fep | 0:5ff20db10a96 | 1554 | /* |
| fep | 0:5ff20db10a96 | 1555 | * For internal use only. Use xSemaphoreCreateMutex(), |
| fep | 0:5ff20db10a96 | 1556 | * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling |
| fep | 0:5ff20db10a96 | 1557 | * these functions directly. |
| fep | 0:5ff20db10a96 | 1558 | */ |
| fep | 0:5ff20db10a96 | 1559 | QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1560 | QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1561 | QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1562 | QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1563 | void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1564 | |
| fep | 0:5ff20db10a96 | 1565 | /* |
| fep | 0:5ff20db10a96 | 1566 | * For internal use only. Use xSemaphoreTakeMutexRecursive() or |
| fep | 0:5ff20db10a96 | 1567 | * xSemaphoreGiveMutexRecursive() instead of calling these functions directly. |
| fep | 0:5ff20db10a96 | 1568 | */ |
| fep | 0:5ff20db10a96 | 1569 | BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1570 | BaseType_t xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1571 | |
| fep | 0:5ff20db10a96 | 1572 | /* |
| fep | 0:5ff20db10a96 | 1573 | * Reset a queue back to its original empty state. The return value is now |
| fep | 0:5ff20db10a96 | 1574 | * obsolete and is always set to pdPASS. |
| fep | 0:5ff20db10a96 | 1575 | */ |
| fep | 0:5ff20db10a96 | 1576 | #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE ) |
| fep | 0:5ff20db10a96 | 1577 | |
| fep | 0:5ff20db10a96 | 1578 | /* |
| fep | 0:5ff20db10a96 | 1579 | * The registry is provided as a means for kernel aware debuggers to |
| fep | 0:5ff20db10a96 | 1580 | * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add |
| fep | 0:5ff20db10a96 | 1581 | * a queue, semaphore or mutex handle to the registry if you want the handle |
| fep | 0:5ff20db10a96 | 1582 | * to be available to a kernel aware debugger. If you are not using a kernel |
| fep | 0:5ff20db10a96 | 1583 | * aware debugger then this function can be ignored. |
| fep | 0:5ff20db10a96 | 1584 | * |
| fep | 0:5ff20db10a96 | 1585 | * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the |
| fep | 0:5ff20db10a96 | 1586 | * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0 |
| fep | 0:5ff20db10a96 | 1587 | * within FreeRTOSConfig.h for the registry to be available. Its value |
| fep | 0:5ff20db10a96 | 1588 | * does not effect the number of queues, semaphores and mutexes that can be |
| fep | 0:5ff20db10a96 | 1589 | * created - just the number that the registry can hold. |
| fep | 0:5ff20db10a96 | 1590 | * |
| fep | 0:5ff20db10a96 | 1591 | * @param xQueue The handle of the queue being added to the registry. This |
| fep | 0:5ff20db10a96 | 1592 | * is the handle returned by a call to xQueueCreate(). Semaphore and mutex |
| fep | 0:5ff20db10a96 | 1593 | * handles can also be passed in here. |
| fep | 0:5ff20db10a96 | 1594 | * |
| fep | 0:5ff20db10a96 | 1595 | * @param pcName The name to be associated with the handle. This is the |
| fep | 0:5ff20db10a96 | 1596 | * name that the kernel aware debugger will display. The queue registry only |
| fep | 0:5ff20db10a96 | 1597 | * stores a pointer to the string - so the string must be persistent (global or |
| fep | 0:5ff20db10a96 | 1598 | * preferably in ROM/Flash), not on the stack. |
| fep | 0:5ff20db10a96 | 1599 | */ |
| fep | 0:5ff20db10a96 | 1600 | #if( configQUEUE_REGISTRY_SIZE > 0 ) |
| fep | 0:5ff20db10a96 | 1601 | void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ |
| fep | 0:5ff20db10a96 | 1602 | #endif |
| fep | 0:5ff20db10a96 | 1603 | |
| fep | 0:5ff20db10a96 | 1604 | /* |
| fep | 0:5ff20db10a96 | 1605 | * The registry is provided as a means for kernel aware debuggers to |
| fep | 0:5ff20db10a96 | 1606 | * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add |
| fep | 0:5ff20db10a96 | 1607 | * a queue, semaphore or mutex handle to the registry if you want the handle |
| fep | 0:5ff20db10a96 | 1608 | * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to |
| fep | 0:5ff20db10a96 | 1609 | * remove the queue, semaphore or mutex from the register. If you are not using |
| fep | 0:5ff20db10a96 | 1610 | * a kernel aware debugger then this function can be ignored. |
| fep | 0:5ff20db10a96 | 1611 | * |
| fep | 0:5ff20db10a96 | 1612 | * @param xQueue The handle of the queue being removed from the registry. |
| fep | 0:5ff20db10a96 | 1613 | */ |
| fep | 0:5ff20db10a96 | 1614 | #if( configQUEUE_REGISTRY_SIZE > 0 ) |
| fep | 0:5ff20db10a96 | 1615 | void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1616 | #endif |
| fep | 0:5ff20db10a96 | 1617 | |
| fep | 0:5ff20db10a96 | 1618 | /* |
| fep | 0:5ff20db10a96 | 1619 | * The queue registry is provided as a means for kernel aware debuggers to |
| fep | 0:5ff20db10a96 | 1620 | * locate queues, semaphores and mutexes. Call pcQueueGetName() to look |
| fep | 0:5ff20db10a96 | 1621 | * up and return the name of a queue in the queue registry from the queue's |
| fep | 0:5ff20db10a96 | 1622 | * handle. |
| fep | 0:5ff20db10a96 | 1623 | * |
| fep | 0:5ff20db10a96 | 1624 | * @param xQueue The handle of the queue the name of which will be returned. |
| fep | 0:5ff20db10a96 | 1625 | * @return If the queue is in the registry then a pointer to the name of the |
| fep | 0:5ff20db10a96 | 1626 | * queue is returned. If the queue is not in the registry then NULL is |
| fep | 0:5ff20db10a96 | 1627 | * returned. |
| fep | 0:5ff20db10a96 | 1628 | */ |
| fep | 0:5ff20db10a96 | 1629 | #if( configQUEUE_REGISTRY_SIZE > 0 ) |
| fep | 0:5ff20db10a96 | 1630 | const char *pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ |
| fep | 0:5ff20db10a96 | 1631 | #endif |
| fep | 0:5ff20db10a96 | 1632 | |
| fep | 0:5ff20db10a96 | 1633 | /* |
| fep | 0:5ff20db10a96 | 1634 | * Generic version of the function used to creaet a queue using dynamic memory |
| fep | 0:5ff20db10a96 | 1635 | * allocation. This is called by other functions and macros that create other |
| fep | 0:5ff20db10a96 | 1636 | * RTOS objects that use the queue structure as their base. |
| fep | 0:5ff20db10a96 | 1637 | */ |
| fep | 0:5ff20db10a96 | 1638 | #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) |
| fep | 0:5ff20db10a96 | 1639 | QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1640 | #endif |
| fep | 0:5ff20db10a96 | 1641 | |
| fep | 0:5ff20db10a96 | 1642 | /* |
| fep | 0:5ff20db10a96 | 1643 | * Generic version of the function used to creaet a queue using dynamic memory |
| fep | 0:5ff20db10a96 | 1644 | * allocation. This is called by other functions and macros that create other |
| fep | 0:5ff20db10a96 | 1645 | * RTOS objects that use the queue structure as their base. |
| fep | 0:5ff20db10a96 | 1646 | */ |
| fep | 0:5ff20db10a96 | 1647 | #if( configSUPPORT_STATIC_ALLOCATION == 1 ) |
| fep | 0:5ff20db10a96 | 1648 | QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1649 | #endif |
| fep | 0:5ff20db10a96 | 1650 | |
| fep | 0:5ff20db10a96 | 1651 | /* |
| fep | 0:5ff20db10a96 | 1652 | * Queue sets provide a mechanism to allow a task to block (pend) on a read |
| fep | 0:5ff20db10a96 | 1653 | * operation from multiple queues or semaphores simultaneously. |
| fep | 0:5ff20db10a96 | 1654 | * |
| fep | 0:5ff20db10a96 | 1655 | * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this |
| fep | 0:5ff20db10a96 | 1656 | * function. |
| fep | 0:5ff20db10a96 | 1657 | * |
| fep | 0:5ff20db10a96 | 1658 | * A queue set must be explicitly created using a call to xQueueCreateSet() |
| fep | 0:5ff20db10a96 | 1659 | * before it can be used. Once created, standard FreeRTOS queues and semaphores |
| fep | 0:5ff20db10a96 | 1660 | * can be added to the set using calls to xQueueAddToSet(). |
| fep | 0:5ff20db10a96 | 1661 | * xQueueSelectFromSet() is then used to determine which, if any, of the queues |
| fep | 0:5ff20db10a96 | 1662 | * or semaphores contained in the set is in a state where a queue read or |
| fep | 0:5ff20db10a96 | 1663 | * semaphore take operation would be successful. |
| fep | 0:5ff20db10a96 | 1664 | * |
| fep | 0:5ff20db10a96 | 1665 | * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html |
| fep | 0:5ff20db10a96 | 1666 | * for reasons why queue sets are very rarely needed in practice as there are |
| fep | 0:5ff20db10a96 | 1667 | * simpler methods of blocking on multiple objects. |
| fep | 0:5ff20db10a96 | 1668 | * |
| fep | 0:5ff20db10a96 | 1669 | * Note 2: Blocking on a queue set that contains a mutex will not cause the |
| fep | 0:5ff20db10a96 | 1670 | * mutex holder to inherit the priority of the blocked task. |
| fep | 0:5ff20db10a96 | 1671 | * |
| fep | 0:5ff20db10a96 | 1672 | * Note 3: An additional 4 bytes of RAM is required for each space in a every |
| fep | 0:5ff20db10a96 | 1673 | * queue added to a queue set. Therefore counting semaphores that have a high |
| fep | 0:5ff20db10a96 | 1674 | * maximum count value should not be added to a queue set. |
| fep | 0:5ff20db10a96 | 1675 | * |
| fep | 0:5ff20db10a96 | 1676 | * Note 4: A receive (in the case of a queue) or take (in the case of a |
| fep | 0:5ff20db10a96 | 1677 | * semaphore) operation must not be performed on a member of a queue set unless |
| fep | 0:5ff20db10a96 | 1678 | * a call to xQueueSelectFromSet() has first returned a handle to that set member. |
| fep | 0:5ff20db10a96 | 1679 | * |
| fep | 0:5ff20db10a96 | 1680 | * @param uxEventQueueLength Queue sets store events that occur on |
| fep | 0:5ff20db10a96 | 1681 | * the queues and semaphores contained in the set. uxEventQueueLength specifies |
| fep | 0:5ff20db10a96 | 1682 | * the maximum number of events that can be queued at once. To be absolutely |
| fep | 0:5ff20db10a96 | 1683 | * certain that events are not lost uxEventQueueLength should be set to the |
| fep | 0:5ff20db10a96 | 1684 | * total sum of the length of the queues added to the set, where binary |
| fep | 0:5ff20db10a96 | 1685 | * semaphores and mutexes have a length of 1, and counting semaphores have a |
| fep | 0:5ff20db10a96 | 1686 | * length set by their maximum count value. Examples: |
| fep | 0:5ff20db10a96 | 1687 | * + If a queue set is to hold a queue of length 5, another queue of length 12, |
| fep | 0:5ff20db10a96 | 1688 | * and a binary semaphore, then uxEventQueueLength should be set to |
| fep | 0:5ff20db10a96 | 1689 | * (5 + 12 + 1), or 18. |
| fep | 0:5ff20db10a96 | 1690 | * + If a queue set is to hold three binary semaphores then uxEventQueueLength |
| fep | 0:5ff20db10a96 | 1691 | * should be set to (1 + 1 + 1 ), or 3. |
| fep | 0:5ff20db10a96 | 1692 | * + If a queue set is to hold a counting semaphore that has a maximum count of |
| fep | 0:5ff20db10a96 | 1693 | * 5, and a counting semaphore that has a maximum count of 3, then |
| fep | 0:5ff20db10a96 | 1694 | * uxEventQueueLength should be set to (5 + 3), or 8. |
| fep | 0:5ff20db10a96 | 1695 | * |
| fep | 0:5ff20db10a96 | 1696 | * @return If the queue set is created successfully then a handle to the created |
| fep | 0:5ff20db10a96 | 1697 | * queue set is returned. Otherwise NULL is returned. |
| fep | 0:5ff20db10a96 | 1698 | */ |
| fep | 0:5ff20db10a96 | 1699 | QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1700 | |
| fep | 0:5ff20db10a96 | 1701 | /* |
| fep | 0:5ff20db10a96 | 1702 | * Adds a queue or semaphore to a queue set that was previously created by a |
| fep | 0:5ff20db10a96 | 1703 | * call to xQueueCreateSet(). |
| fep | 0:5ff20db10a96 | 1704 | * |
| fep | 0:5ff20db10a96 | 1705 | * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this |
| fep | 0:5ff20db10a96 | 1706 | * function. |
| fep | 0:5ff20db10a96 | 1707 | * |
| fep | 0:5ff20db10a96 | 1708 | * Note 1: A receive (in the case of a queue) or take (in the case of a |
| fep | 0:5ff20db10a96 | 1709 | * semaphore) operation must not be performed on a member of a queue set unless |
| fep | 0:5ff20db10a96 | 1710 | * a call to xQueueSelectFromSet() has first returned a handle to that set member. |
| fep | 0:5ff20db10a96 | 1711 | * |
| fep | 0:5ff20db10a96 | 1712 | * @param xQueueOrSemaphore The handle of the queue or semaphore being added to |
| fep | 0:5ff20db10a96 | 1713 | * the queue set (cast to an QueueSetMemberHandle_t type). |
| fep | 0:5ff20db10a96 | 1714 | * |
| fep | 0:5ff20db10a96 | 1715 | * @param xQueueSet The handle of the queue set to which the queue or semaphore |
| fep | 0:5ff20db10a96 | 1716 | * is being added. |
| fep | 0:5ff20db10a96 | 1717 | * |
| fep | 0:5ff20db10a96 | 1718 | * @return If the queue or semaphore was successfully added to the queue set |
| fep | 0:5ff20db10a96 | 1719 | * then pdPASS is returned. If the queue could not be successfully added to the |
| fep | 0:5ff20db10a96 | 1720 | * queue set because it is already a member of a different queue set then pdFAIL |
| fep | 0:5ff20db10a96 | 1721 | * is returned. |
| fep | 0:5ff20db10a96 | 1722 | */ |
| fep | 0:5ff20db10a96 | 1723 | BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1724 | |
| fep | 0:5ff20db10a96 | 1725 | /* |
| fep | 0:5ff20db10a96 | 1726 | * Removes a queue or semaphore from a queue set. A queue or semaphore can only |
| fep | 0:5ff20db10a96 | 1727 | * be removed from a set if the queue or semaphore is empty. |
| fep | 0:5ff20db10a96 | 1728 | * |
| fep | 0:5ff20db10a96 | 1729 | * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this |
| fep | 0:5ff20db10a96 | 1730 | * function. |
| fep | 0:5ff20db10a96 | 1731 | * |
| fep | 0:5ff20db10a96 | 1732 | * @param xQueueOrSemaphore The handle of the queue or semaphore being removed |
| fep | 0:5ff20db10a96 | 1733 | * from the queue set (cast to an QueueSetMemberHandle_t type). |
| fep | 0:5ff20db10a96 | 1734 | * |
| fep | 0:5ff20db10a96 | 1735 | * @param xQueueSet The handle of the queue set in which the queue or semaphore |
| fep | 0:5ff20db10a96 | 1736 | * is included. |
| fep | 0:5ff20db10a96 | 1737 | * |
| fep | 0:5ff20db10a96 | 1738 | * @return If the queue or semaphore was successfully removed from the queue set |
| fep | 0:5ff20db10a96 | 1739 | * then pdPASS is returned. If the queue was not in the queue set, or the |
| fep | 0:5ff20db10a96 | 1740 | * queue (or semaphore) was not empty, then pdFAIL is returned. |
| fep | 0:5ff20db10a96 | 1741 | */ |
| fep | 0:5ff20db10a96 | 1742 | BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1743 | |
| fep | 0:5ff20db10a96 | 1744 | /* |
| fep | 0:5ff20db10a96 | 1745 | * xQueueSelectFromSet() selects from the members of a queue set a queue or |
| fep | 0:5ff20db10a96 | 1746 | * semaphore that either contains data (in the case of a queue) or is available |
| fep | 0:5ff20db10a96 | 1747 | * to take (in the case of a semaphore). xQueueSelectFromSet() effectively |
| fep | 0:5ff20db10a96 | 1748 | * allows a task to block (pend) on a read operation on all the queues and |
| fep | 0:5ff20db10a96 | 1749 | * semaphores in a queue set simultaneously. |
| fep | 0:5ff20db10a96 | 1750 | * |
| fep | 0:5ff20db10a96 | 1751 | * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this |
| fep | 0:5ff20db10a96 | 1752 | * function. |
| fep | 0:5ff20db10a96 | 1753 | * |
| fep | 0:5ff20db10a96 | 1754 | * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html |
| fep | 0:5ff20db10a96 | 1755 | * for reasons why queue sets are very rarely needed in practice as there are |
| fep | 0:5ff20db10a96 | 1756 | * simpler methods of blocking on multiple objects. |
| fep | 0:5ff20db10a96 | 1757 | * |
| fep | 0:5ff20db10a96 | 1758 | * Note 2: Blocking on a queue set that contains a mutex will not cause the |
| fep | 0:5ff20db10a96 | 1759 | * mutex holder to inherit the priority of the blocked task. |
| fep | 0:5ff20db10a96 | 1760 | * |
| fep | 0:5ff20db10a96 | 1761 | * Note 3: A receive (in the case of a queue) or take (in the case of a |
| fep | 0:5ff20db10a96 | 1762 | * semaphore) operation must not be performed on a member of a queue set unless |
| fep | 0:5ff20db10a96 | 1763 | * a call to xQueueSelectFromSet() has first returned a handle to that set member. |
| fep | 0:5ff20db10a96 | 1764 | * |
| fep | 0:5ff20db10a96 | 1765 | * @param xQueueSet The queue set on which the task will (potentially) block. |
| fep | 0:5ff20db10a96 | 1766 | * |
| fep | 0:5ff20db10a96 | 1767 | * @param xTicksToWait The maximum time, in ticks, that the calling task will |
| fep | 0:5ff20db10a96 | 1768 | * remain in the Blocked state (with other tasks executing) to wait for a member |
| fep | 0:5ff20db10a96 | 1769 | * of the queue set to be ready for a successful queue read or semaphore take |
| fep | 0:5ff20db10a96 | 1770 | * operation. |
| fep | 0:5ff20db10a96 | 1771 | * |
| fep | 0:5ff20db10a96 | 1772 | * @return xQueueSelectFromSet() will return the handle of a queue (cast to |
| fep | 0:5ff20db10a96 | 1773 | * a QueueSetMemberHandle_t type) contained in the queue set that contains data, |
| fep | 0:5ff20db10a96 | 1774 | * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained |
| fep | 0:5ff20db10a96 | 1775 | * in the queue set that is available, or NULL if no such queue or semaphore |
| fep | 0:5ff20db10a96 | 1776 | * exists before before the specified block time expires. |
| fep | 0:5ff20db10a96 | 1777 | */ |
| fep | 0:5ff20db10a96 | 1778 | QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1779 | |
| fep | 0:5ff20db10a96 | 1780 | /* |
| fep | 0:5ff20db10a96 | 1781 | * A version of xQueueSelectFromSet() that can be used from an ISR. |
| fep | 0:5ff20db10a96 | 1782 | */ |
| fep | 0:5ff20db10a96 | 1783 | QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1784 | |
| fep | 0:5ff20db10a96 | 1785 | /* Not public API functions. */ |
| fep | 0:5ff20db10a96 | 1786 | void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1787 | BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1788 | void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1789 | UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1790 | uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; |
| fep | 0:5ff20db10a96 | 1791 | |
| fep | 0:5ff20db10a96 | 1792 | |
| fep | 0:5ff20db10a96 | 1793 | #ifdef __cplusplus |
| fep | 0:5ff20db10a96 | 1794 | } |
| fep | 0:5ff20db10a96 | 1795 | #endif |
| fep | 0:5ff20db10a96 | 1796 | |
| fep | 0:5ff20db10a96 | 1797 | #endif /* QUEUE_H */ |
| fep | 0:5ff20db10a96 | 1798 | |
| fep | 0:5ff20db10a96 | 1799 |