2 FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
55 #include "FreeRTOS.h"
\r
57 #include "croutine.h"
\r
59 /*-----------------------------------------------------------
\r
60 * PUBLIC LIST API documented in list.h
\r
61 *----------------------------------------------------------*/
\r
63 /* Constants used with the cRxLock and cTxLock structure members. */
\r
64 #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )
\r
65 #define queueLOCKED_UNMODIFIED ( ( signed portBASE_TYPE ) 0 )
\r
67 #define queueERRONEOUS_UNBLOCK ( -1 )
\r
69 /* For internal use only. */
\r
70 #define queueSEND_TO_BACK ( 0 )
\r
71 #define queueSEND_TO_FRONT ( 1 )
\r
73 /* Effectively make a union out of the xQUEUE structure. */
\r
74 #define pxMutexHolder pcTail
\r
75 #define uxQueueType pcHead
\r
76 #define uxRecursiveCallCount pcReadFrom
\r
77 #define queueQUEUE_IS_MUTEX NULL
\r
79 /* Semaphores do not actually store or copy data, so have an items size of
\r
81 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( 0 )
\r
82 #define queueDONT_BLOCK ( ( portTickType ) 0 )
\r
83 #define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0 )
\r
86 * Definition of the queue used by the scheduler.
\r
87 * Items are queued by copy, not reference.
\r
89 typedef struct QueueDefinition
\r
91 signed portCHAR *pcHead; /*< Points to the beginning of the queue storage area. */
\r
92 signed portCHAR *pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */
\r
94 signed portCHAR *pcWriteTo; /*< Points to the free next place in the storage area. */
\r
95 signed portCHAR *pcReadFrom; /*< Points to the last place that a queued item was read from. */
\r
97 xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
\r
98 xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
\r
100 volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */
\r
101 unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
\r
102 unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */
\r
104 signed portBASE_TYPE xRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
\r
105 signed portBASE_TYPE xTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
\r
108 /*-----------------------------------------------------------*/
\r
111 * Inside this file xQueueHandle is a pointer to a xQUEUE structure.
\r
112 * To keep the definition private the API header file defines it as a
\r
115 typedef xQUEUE * xQueueHandle;
\r
118 * Prototypes for public functions are included here so we don't have to
\r
119 * include the API header file (as it defines xQueueHandle differently). These
\r
120 * functions are documented in the API header file.
\r
122 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
123 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
124 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue );
\r
125 void vQueueDelete( xQueueHandle xQueue );
\r
126 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
127 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
128 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
129 xQueueHandle xQueueCreateMutex( void );
\r
130 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
131 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
132 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
133 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
134 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
135 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
136 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
137 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
140 * Co-routine queue functions differ from task queue functions. Co-routines are
\r
141 * an optional component.
\r
143 #if configUSE_CO_ROUTINES == 1
\r
144 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
145 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
146 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
147 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
151 * The queue registry is just a means for kernel aware debuggers to locate
\r
152 * queue structures. It has no other purpose so is an optional component.
\r
154 #if configQUEUE_REGISTRY_SIZE > 0
\r
156 /* The type stored within the queue registry array. This allows a name
\r
157 to be assigned to each queue making kernel aware debugging a little
\r
158 more user friendly. */
\r
159 typedef struct QUEUE_REGISTRY_ITEM
\r
161 signed portCHAR *pcQueueName;
\r
162 xQueueHandle xHandle;
\r
163 } xQueueRegistryItem;
\r
165 /* The queue registry is simply an array of xQueueRegistryItem structures.
\r
166 The pcQueueName member of a structure being NULL is indicative of the
\r
167 array position being vacant. */
\r
168 xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
\r
170 /* Removes a queue from the registry by simply setting the pcQueueName
\r
172 static void vQueueUnregisterQueue( xQueueHandle xQueue );
\r
173 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcQueueName );
\r
177 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
\r
178 * prevent an ISR from adding or removing items to the queue, but does prevent
\r
179 * an ISR from removing tasks from the queue event lists. If an ISR finds a
\r
180 * queue is locked it will instead increment the appropriate queue lock count
\r
181 * to indicate that a task may require unblocking. When the queue in unlocked
\r
182 * these lock counts are inspected, and the appropriate action taken.
\r
184 static void prvUnlockQueue( xQueueHandle pxQueue );
\r
187 * Uses a critical section to determine if there is any data in a queue.
\r
189 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
\r
191 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue );
\r
194 * Uses a critical section to determine if there is any space in a queue.
\r
196 * @return pdTRUE if there is no space, otherwise pdFALSE;
\r
198 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue );
\r
201 * Copies an item into the queue, either at the front of the queue or the
\r
202 * back of the queue.
\r
204 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition );
\r
207 * Copies an item out of a queue.
\r
209 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer );
\r
210 /*-----------------------------------------------------------*/
\r
213 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
\r
214 * accessing the queue event lists.
\r
216 #define prvLockQueue( pxQueue ) \
\r
218 taskENTER_CRITICAL(); \
\r
220 if( pxQueue->xRxLock == queueUNLOCKED ) \
\r
222 pxQueue->xRxLock = queueLOCKED_UNMODIFIED; \
\r
224 if( pxQueue->xTxLock == queueUNLOCKED ) \
\r
226 pxQueue->xTxLock = queueLOCKED_UNMODIFIED; \
\r
229 taskEXIT_CRITICAL(); \
\r
231 /*-----------------------------------------------------------*/
\r
234 /*-----------------------------------------------------------
\r
235 * PUBLIC QUEUE MANAGEMENT API documented in queue.h
\r
236 *----------------------------------------------------------*/
\r
238 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize )
\r
240 xQUEUE *pxNewQueue;
\r
241 size_t xQueueSizeInBytes;
\r
243 /* Allocate the new queue structure. */
\r
244 if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
\r
246 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
247 if( pxNewQueue != NULL )
\r
249 /* Create the list of pointers to queue items. The queue is one byte
\r
250 longer than asked for to make wrap checking easier/faster. */
\r
251 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;
\r
253 pxNewQueue->pcHead = ( signed portCHAR * ) pvPortMalloc( xQueueSizeInBytes );
\r
254 if( pxNewQueue->pcHead != NULL )
\r
256 /* Initialise the queue members as described above where the
\r
257 queue type is defined. */
\r
258 pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize );
\r
259 pxNewQueue->uxMessagesWaiting = 0;
\r
260 pxNewQueue->pcWriteTo = pxNewQueue->pcHead;
\r
261 pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - 1 ) * uxItemSize );
\r
262 pxNewQueue->uxLength = uxQueueLength;
\r
263 pxNewQueue->uxItemSize = uxItemSize;
\r
264 pxNewQueue->xRxLock = queueUNLOCKED;
\r
265 pxNewQueue->xTxLock = queueUNLOCKED;
\r
267 /* Likewise ensure the event queues start with the correct state. */
\r
268 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
\r
269 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
\r
271 traceQUEUE_CREATE( pxNewQueue );
\r
277 traceQUEUE_CREATE_FAILED();
\r
278 vPortFree( pxNewQueue );
\r
283 /* Will only reach here if we could not allocate enough memory or no memory
\r
287 /*-----------------------------------------------------------*/
\r
289 #if ( configUSE_MUTEXES == 1 )
\r
291 xQueueHandle xQueueCreateMutex( void )
\r
293 xQUEUE *pxNewQueue;
\r
295 /* Allocate the new queue structure. */
\r
296 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
297 if( pxNewQueue != NULL )
\r
299 /* Information required for priority inheritance. */
\r
300 pxNewQueue->pxMutexHolder = NULL;
\r
301 pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
\r
303 /* Queues used as a mutex no data is actually copied into or out
\r
305 pxNewQueue->pcWriteTo = NULL;
\r
306 pxNewQueue->pcReadFrom = NULL;
\r
308 /* Each mutex has a length of 1 (like a binary semaphore) and
\r
309 an item size of 0 as nothing is actually copied into or out
\r
311 pxNewQueue->uxMessagesWaiting = 0;
\r
312 pxNewQueue->uxLength = 1;
\r
313 pxNewQueue->uxItemSize = 0;
\r
314 pxNewQueue->xRxLock = queueUNLOCKED;
\r
315 pxNewQueue->xTxLock = queueUNLOCKED;
\r
317 /* Ensure the event queues start with the correct state. */
\r
318 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
\r
319 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
\r
321 /* Start with the semaphore in the expected state. */
\r
322 xQueueGenericSend( pxNewQueue, NULL, 0, queueSEND_TO_BACK );
\r
324 traceCREATE_MUTEX( pxNewQueue );
\r
328 traceCREATE_MUTEX_FAILED();
\r
334 #endif /* configUSE_MUTEXES */
\r
335 /*-----------------------------------------------------------*/
\r
337 #if configUSE_RECURSIVE_MUTEXES == 1
\r
339 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex )
\r
341 portBASE_TYPE xReturn;
\r
343 /* If this is the task that holds the mutex then pxMutexHolder will not
\r
344 change outside of this task. If this task does not hold the mutex then
\r
345 pxMutexHolder can never coincidentally equal the tasks handle, and as
\r
346 this is the only condition we are interested in it does not matter if
\r
347 pxMutexHolder is accessed simultaneously by another task. Therefore no
\r
348 mutual exclusion is required to test the pxMutexHolder variable. */
\r
349 if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )
\r
351 traceGIVE_MUTEX_RECURSIVE( pxMutex );
\r
353 /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to
\r
354 the task handle, therefore no underflow check is required. Also,
\r
355 uxRecursiveCallCount is only modified by the mutex holder, and as
\r
356 there can only be one, no mutual exclusion is required to modify the
\r
357 uxRecursiveCallCount member. */
\r
358 ( pxMutex->uxRecursiveCallCount )--;
\r
360 /* Have we unwound the call count? */
\r
361 if( pxMutex->uxRecursiveCallCount == 0 )
\r
363 /* Return the mutex. This will automatically unblock any other
\r
364 task that might be waiting to access the mutex. */
\r
365 xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
\r
372 /* We cannot give the mutex because we are not the holder. */
\r
375 traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );
\r
381 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
382 /*-----------------------------------------------------------*/
\r
384 #if configUSE_RECURSIVE_MUTEXES == 1
\r
386 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime )
\r
388 portBASE_TYPE xReturn;
\r
390 /* Comments regarding mutual exclusion as per those within
\r
391 xQueueGiveMutexRecursive(). */
\r
393 traceTAKE_MUTEX_RECURSIVE( pxMutex );
\r
395 if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )
\r
397 ( pxMutex->uxRecursiveCallCount )++;
\r
402 xReturn = xQueueGenericReceive( pxMutex, NULL, xBlockTime, pdFALSE );
\r
404 /* pdPASS will only be returned if we successfully obtained the mutex,
\r
405 we may have blocked to reach here. */
\r
406 if( xReturn == pdPASS )
\r
408 ( pxMutex->uxRecursiveCallCount )++;
\r
415 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
416 /*-----------------------------------------------------------*/
\r
418 #if configUSE_COUNTING_SEMAPHORES == 1
\r
420 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )
\r
422 xQueueHandle pxHandle;
\r
424 pxHandle = xQueueCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH );
\r
426 if( pxHandle != NULL )
\r
428 pxHandle->uxMessagesWaiting = uxInitialCount;
\r
430 traceCREATE_COUNTING_SEMAPHORE();
\r
434 traceCREATE_COUNTING_SEMAPHORE_FAILED();
\r
440 #endif /* configUSE_COUNTING_SEMAPHORES */
\r
441 /*-----------------------------------------------------------*/
\r
443 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
445 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
446 xTimeOutType xTimeOut;
\r
448 /* This function relaxes the coding standard somewhat to allow return
\r
449 statements within the function itself. This is done in the interest
\r
450 of execution time efficiency. */
\r
454 taskENTER_CRITICAL();
\r
456 /* Is there room on the queue now? To be running we must be
\r
457 the highest priority task wanting to access the queue. */
\r
458 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
460 traceQUEUE_SEND( pxQueue );
\r
461 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
463 /* If there was a task waiting for data to arrive on the
\r
464 queue then unblock it now. */
\r
465 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
467 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
469 /* The unblocked task has a priority higher than
\r
470 our own so yield immediately. Yes it is ok to do
\r
471 this from within the critical section - the kernel
\r
472 takes care of that. */
\r
477 taskEXIT_CRITICAL();
\r
482 if( xTicksToWait == ( portTickType ) 0 )
\r
484 /* The queue was full and no block time is specified (or
\r
485 the block time has expired) so leave now. */
\r
486 taskEXIT_CRITICAL();
\r
487 return errQUEUE_FULL;
\r
489 else if( xEntryTimeSet == pdFALSE )
\r
491 /* The queue was full and a block time was specified so
\r
492 configure the timeout structure. */
\r
493 vTaskSetTimeOutState( &xTimeOut );
\r
494 xEntryTimeSet = pdTRUE;
\r
498 taskEXIT_CRITICAL();
\r
500 /* Interrupts and other tasks can send to and receive from the queue
\r
501 now the critical section has been exited. */
\r
504 prvLockQueue( pxQueue );
\r
506 /* Update the timeout state to see if it has expired yet. */
\r
507 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
509 if( prvIsQueueFull( pxQueue ) )
\r
511 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
\r
512 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
514 /* Unlocking the queue means queue events can effect the
\r
515 event list. It is possible that interrupts occurring now
\r
516 remove this task from the event list again - but as the
\r
517 scheduler is suspended the task will go onto the pending
\r
518 ready last instead of the actual ready list. */
\r
519 prvUnlockQueue( pxQueue );
\r
521 /* Resuming the scheduler will move tasks from the pending
\r
522 ready list into the ready list - so it is feasible that this
\r
523 task is already in a ready list before it yields - in which
\r
524 case the yield will not cause a context switch unless there
\r
525 is also a higher priority task in the pending ready list. */
\r
526 if( !xTaskResumeAll() )
\r
534 prvUnlockQueue( pxQueue );
\r
535 ( void ) xTaskResumeAll();
\r
540 /* The timeout has expired. */
\r
541 prvUnlockQueue( pxQueue );
\r
542 ( void ) xTaskResumeAll();
\r
543 return errQUEUE_FULL;
\r
547 /*-----------------------------------------------------------*/
\r
549 #if configUSE_ALTERNATIVE_API == 1
\r
551 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
553 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
554 xTimeOutType xTimeOut;
\r
558 taskENTER_CRITICAL();
\r
560 /* Is there room on the queue now? To be running we must be
\r
561 the highest priority task wanting to access the queue. */
\r
562 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
564 traceQUEUE_SEND( pxQueue );
\r
565 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
567 /* If there was a task waiting for data to arrive on the
\r
568 queue then unblock it now. */
\r
569 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
571 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
573 /* The unblocked task has a priority higher than
\r
574 our own so yield immediately. */
\r
579 taskEXIT_CRITICAL();
\r
584 if( xTicksToWait == ( portTickType ) 0 )
\r
586 taskEXIT_CRITICAL();
\r
587 return errQUEUE_FULL;
\r
589 else if( xEntryTimeSet == pdFALSE )
\r
591 vTaskSetTimeOutState( &xTimeOut );
\r
592 xEntryTimeSet = pdTRUE;
\r
596 taskEXIT_CRITICAL();
\r
598 taskENTER_CRITICAL();
\r
600 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
602 if( prvIsQueueFull( pxQueue ) )
\r
604 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
\r
605 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
611 taskEXIT_CRITICAL();
\r
612 return errQUEUE_FULL;
\r
615 taskEXIT_CRITICAL();
\r
619 #endif /* configUSE_ALTERNATIVE_API */
\r
620 /*-----------------------------------------------------------*/
\r
622 #if configUSE_ALTERNATIVE_API == 1
\r
624 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
626 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
627 xTimeOutType xTimeOut;
\r
628 signed portCHAR *pcOriginalReadPosition;
\r
632 taskENTER_CRITICAL();
\r
634 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
636 /* Remember our read position in case we are just peeking. */
\r
637 pcOriginalReadPosition = pxQueue->pcReadFrom;
\r
639 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
641 if( xJustPeeking == pdFALSE )
\r
643 traceQUEUE_RECEIVE( pxQueue );
\r
645 /* We are actually removing data. */
\r
646 --( pxQueue->uxMessagesWaiting );
\r
648 #if ( configUSE_MUTEXES == 1 )
\r
650 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
652 /* Record the information required to implement
\r
653 priority inheritance should it become necessary. */
\r
654 pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();
\r
659 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
661 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
669 traceQUEUE_PEEK( pxQueue );
\r
671 /* We are not removing the data, so reset our read
\r
673 pxQueue->pcReadFrom = pcOriginalReadPosition;
\r
675 /* The data is being left in the queue, so see if there are
\r
676 any other tasks waiting for the data. */
\r
677 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
679 /* Tasks that are removed from the event list will get added to
\r
680 the pending ready list as the scheduler is still suspended. */
\r
681 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
683 /* The task waiting has a higher priority than this task. */
\r
690 taskEXIT_CRITICAL();
\r
695 if( xTicksToWait == ( portTickType ) 0 )
\r
697 taskEXIT_CRITICAL();
\r
698 return errQUEUE_EMPTY;
\r
700 else if( xEntryTimeSet == pdFALSE )
\r
702 vTaskSetTimeOutState( &xTimeOut );
\r
703 xEntryTimeSet = pdTRUE;
\r
707 taskEXIT_CRITICAL();
\r
709 taskENTER_CRITICAL();
\r
711 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
713 if( prvIsQueueEmpty( pxQueue ) )
\r
715 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
\r
717 #if ( configUSE_MUTEXES == 1 )
\r
719 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
721 portENTER_CRITICAL();
\r
722 vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
\r
723 portEXIT_CRITICAL();
\r
728 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
734 taskEXIT_CRITICAL();
\r
735 return errQUEUE_EMPTY;
\r
738 taskEXIT_CRITICAL();
\r
743 #endif /* configUSE_ALTERNATIVE_API */
\r
744 /*-----------------------------------------------------------*/
\r
746 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )
\r
748 signed portBASE_TYPE xReturn;
\r
749 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
751 /* Similar to xQueueGenericSend, except we don't block if there is no room
\r
752 in the queue. Also we don't directly wake a task that was blocked on a
\r
753 queue read, instead we return a flag to say whether a context switch is
\r
754 required or not (i.e. has a task with a higher priority than us been woken
\r
756 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
758 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
760 traceQUEUE_SEND_FROM_ISR( pxQueue );
\r
762 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
764 /* If the queue is locked we do not alter the event list. This will
\r
765 be done when the queue is unlocked later. */
\r
766 if( pxQueue->xTxLock == queueUNLOCKED )
\r
768 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
770 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
772 /* The task waiting has a higher priority so record that a
\r
773 context switch is required. */
\r
774 *pxHigherPriorityTaskWoken = pdTRUE;
\r
780 /* Increment the lock count so the task that unlocks the queue
\r
781 knows that data was posted while it was locked. */
\r
782 ++( pxQueue->xTxLock );
\r
789 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
\r
790 xReturn = errQUEUE_FULL;
\r
793 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
797 /*-----------------------------------------------------------*/
\r
799 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
801 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
802 xTimeOutType xTimeOut;
\r
803 signed portCHAR *pcOriginalReadPosition;
\r
805 /* This function relaxes the coding standard somewhat to allow return
\r
806 statements within the function itself. This is done in the interest
\r
807 of execution time efficiency. */
\r
811 taskENTER_CRITICAL();
\r
813 /* Is there space on the queue now? To be running we must be
\r
814 the highest priority task wanting to access the queue. */
\r
815 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
817 /* Remember our read position in case we are just peeking. */
\r
818 pcOriginalReadPosition = pxQueue->pcReadFrom;
\r
820 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
822 if( xJustPeeking == pdFALSE )
\r
824 traceQUEUE_RECEIVE( pxQueue );
\r
826 /* We are actually removing data. */
\r
827 --( pxQueue->uxMessagesWaiting );
\r
829 #if ( configUSE_MUTEXES == 1 )
\r
831 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
833 /* Record the information required to implement
\r
834 priority inheritance should it become necessary. */
\r
835 pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();
\r
840 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
842 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
850 traceQUEUE_PEEK( pxQueue );
\r
852 /* We are not removing the data, so reset our read
\r
854 pxQueue->pcReadFrom = pcOriginalReadPosition;
\r
856 /* The data is being left in the queue, so see if there are
\r
857 any other tasks waiting for the data. */
\r
858 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
860 /* Tasks that are removed from the event list will get added to
\r
861 the pending ready list as the scheduler is still suspended. */
\r
862 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
864 /* The task waiting has a higher priority than this task. */
\r
871 taskEXIT_CRITICAL();
\r
876 if( xTicksToWait == ( portTickType ) 0 )
\r
878 /* The queue was empty and no block time is specified (or
\r
879 the block time has expired) so leave now. */
\r
880 taskEXIT_CRITICAL();
\r
881 return errQUEUE_EMPTY;
\r
883 else if( xEntryTimeSet == pdFALSE )
\r
885 /* The queue was empty and a block time was specified so
\r
886 configure the timeout structure. */
\r
887 vTaskSetTimeOutState( &xTimeOut );
\r
888 xEntryTimeSet = pdTRUE;
\r
892 taskEXIT_CRITICAL();
\r
894 /* Interrupts and other tasks can send to and receive from the queue
\r
895 now the critical section has been exited. */
\r
898 prvLockQueue( pxQueue );
\r
900 /* Update the timeout state to see if it has expired yet. */
\r
901 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
903 if( prvIsQueueEmpty( pxQueue ) )
\r
905 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
\r
907 #if ( configUSE_MUTEXES == 1 )
\r
909 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
911 portENTER_CRITICAL();
\r
913 vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
\r
915 portEXIT_CRITICAL();
\r
920 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
921 prvUnlockQueue( pxQueue );
\r
922 if( !xTaskResumeAll() )
\r
930 prvUnlockQueue( pxQueue );
\r
931 ( void ) xTaskResumeAll();
\r
936 prvUnlockQueue( pxQueue );
\r
937 ( void ) xTaskResumeAll();
\r
938 return errQUEUE_EMPTY;
\r
942 /*-----------------------------------------------------------*/
\r
944 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken )
\r
946 signed portBASE_TYPE xReturn;
\r
947 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
949 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
951 /* We cannot block from an ISR, so check there is data available. */
\r
952 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
954 traceQUEUE_RECEIVE_FROM_ISR( pxQueue );
\r
956 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
957 --( pxQueue->uxMessagesWaiting );
\r
959 /* If the queue is locked we will not modify the event list. Instead
\r
960 we update the lock count so the task that unlocks the queue will know
\r
961 that an ISR has removed data while the queue was locked. */
\r
962 if( pxQueue->xRxLock == queueUNLOCKED )
\r
964 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
966 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
968 /* The task waiting has a higher priority than us so
\r
969 force a context switch. */
\r
970 *pxTaskWoken = pdTRUE;
\r
976 /* Increment the lock count so the task that unlocks the queue
\r
977 knows that data was removed while it was locked. */
\r
978 ++( pxQueue->xRxLock );
\r
986 traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
\r
989 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
993 /*-----------------------------------------------------------*/
\r
995 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue )
\r
997 unsigned portBASE_TYPE uxReturn;
\r
999 taskENTER_CRITICAL();
\r
1000 uxReturn = pxQueue->uxMessagesWaiting;
\r
1001 taskEXIT_CRITICAL();
\r
1005 /*-----------------------------------------------------------*/
\r
1007 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue )
\r
1009 unsigned portBASE_TYPE uxReturn;
\r
1011 uxReturn = pxQueue->uxMessagesWaiting;
\r
1015 /*-----------------------------------------------------------*/
\r
1017 void vQueueDelete( xQueueHandle pxQueue )
\r
1019 traceQUEUE_DELETE( pxQueue );
\r
1020 vQueueUnregisterQueue( pxQueue );
\r
1021 vPortFree( pxQueue->pcHead );
\r
1022 vPortFree( pxQueue );
\r
1024 /*-----------------------------------------------------------*/
\r
1026 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )
\r
1028 if( pxQueue->uxItemSize == ( unsigned portBASE_TYPE ) 0 )
\r
1030 #if ( configUSE_MUTEXES == 1 )
\r
1032 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1034 /* The mutex is no longer being held. */
\r
1035 vTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );
\r
1036 pxQueue->pxMutexHolder = NULL;
\r
1041 else if( xPosition == queueSEND_TO_BACK )
\r
1043 memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );
\r
1044 pxQueue->pcWriteTo += pxQueue->uxItemSize;
\r
1045 if( pxQueue->pcWriteTo >= pxQueue->pcTail )
\r
1047 pxQueue->pcWriteTo = pxQueue->pcHead;
\r
1052 memcpy( ( void * ) pxQueue->pcReadFrom, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );
\r
1053 pxQueue->pcReadFrom -= pxQueue->uxItemSize;
\r
1054 if( pxQueue->pcReadFrom < pxQueue->pcHead )
\r
1056 pxQueue->pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );
\r
1060 ++( pxQueue->uxMessagesWaiting );
\r
1062 /*-----------------------------------------------------------*/
\r
1064 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
\r
1066 if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )
\r
1068 pxQueue->pcReadFrom += pxQueue->uxItemSize;
\r
1069 if( pxQueue->pcReadFrom >= pxQueue->pcTail )
\r
1071 pxQueue->pcReadFrom = pxQueue->pcHead;
\r
1073 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1076 /*-----------------------------------------------------------*/
\r
1078 static void prvUnlockQueue( xQueueHandle pxQueue )
\r
1080 /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
\r
1082 /* The lock counts contains the number of extra data items placed or
\r
1083 removed from the queue while the queue was locked. When a queue is
\r
1084 locked items can be added or removed, but the event lists cannot be
\r
1086 taskENTER_CRITICAL();
\r
1088 /* See if data was added to the queue while it was locked. */
\r
1089 while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )
\r
1091 /* Data was posted while the queue was locked. Are any tasks
\r
1092 blocked waiting for data to become available? */
\r
1093 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
1095 /* Tasks that are removed from the event list will get added to
\r
1096 the pending ready list as the scheduler is still suspended. */
\r
1097 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1099 /* The task waiting has a higher priority so record that a
\r
1100 context switch is required. */
\r
1101 vTaskMissedYield();
\r
1104 --( pxQueue->xTxLock );
\r
1112 pxQueue->xTxLock = queueUNLOCKED;
\r
1114 taskEXIT_CRITICAL();
\r
1116 /* Do the same for the Rx lock. */
\r
1117 taskENTER_CRITICAL();
\r
1119 while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )
\r
1121 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
1123 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1125 vTaskMissedYield();
\r
1128 --( pxQueue->xRxLock );
\r
1136 pxQueue->xRxLock = queueUNLOCKED;
\r
1138 taskEXIT_CRITICAL();
\r
1140 /*-----------------------------------------------------------*/
\r
1142 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue )
\r
1144 signed portBASE_TYPE xReturn;
\r
1146 taskENTER_CRITICAL();
\r
1147 xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );
\r
1148 taskEXIT_CRITICAL();
\r
1152 /*-----------------------------------------------------------*/
\r
1154 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue )
\r
1156 signed portBASE_TYPE xReturn;
\r
1158 xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );
\r
1162 /*-----------------------------------------------------------*/
\r
1164 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue )
\r
1166 signed portBASE_TYPE xReturn;
\r
1168 taskENTER_CRITICAL();
\r
1169 xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );
\r
1170 taskEXIT_CRITICAL();
\r
1174 /*-----------------------------------------------------------*/
\r
1176 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue )
\r
1178 signed portBASE_TYPE xReturn;
\r
1180 xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );
\r
1184 /*-----------------------------------------------------------*/
\r
1186 #if configUSE_CO_ROUTINES == 1
\r
1187 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait )
\r
1189 signed portBASE_TYPE xReturn;
\r
1191 /* If the queue is already full we may have to block. A critical section
\r
1192 is required to prevent an interrupt removing something from the queue
\r
1193 between the check to see if the queue is full and blocking on the queue. */
\r
1194 portDISABLE_INTERRUPTS();
\r
1196 if( prvIsQueueFull( pxQueue ) )
\r
1198 /* The queue is full - do we want to block or just leave without
\r
1200 if( xTicksToWait > ( portTickType ) 0 )
\r
1202 /* As this is called from a coroutine we cannot block directly, but
\r
1203 return indicating that we need to block. */
\r
1204 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );
\r
1205 portENABLE_INTERRUPTS();
\r
1206 return errQUEUE_BLOCKED;
\r
1210 portENABLE_INTERRUPTS();
\r
1211 return errQUEUE_FULL;
\r
1215 portENABLE_INTERRUPTS();
\r
1219 portDISABLE_INTERRUPTS();
\r
1221 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1223 /* There is room in the queue, copy the data into the queue. */
\r
1224 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1227 /* Were any co-routines waiting for data to become available? */
\r
1228 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
1230 /* In this instance the co-routine could be placed directly
\r
1231 into the ready list as we are within a critical section.
\r
1232 Instead the same pending ready list mechanism is used as if
\r
1233 the event were caused from within an interrupt. */
\r
1234 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1236 /* The co-routine waiting has a higher priority so record
\r
1237 that a yield might be appropriate. */
\r
1238 xReturn = errQUEUE_YIELD;
\r
1244 xReturn = errQUEUE_FULL;
\r
1247 portENABLE_INTERRUPTS();
\r
1252 /*-----------------------------------------------------------*/
\r
1254 #if configUSE_CO_ROUTINES == 1
\r
1255 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )
\r
1257 signed portBASE_TYPE xReturn;
\r
1259 /* If the queue is already empty we may have to block. A critical section
\r
1260 is required to prevent an interrupt adding something to the queue
\r
1261 between the check to see if the queue is empty and blocking on the queue. */
\r
1262 portDISABLE_INTERRUPTS();
\r
1264 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
1266 /* There are no messages in the queue, do we want to block or just
\r
1267 leave with nothing? */
\r
1268 if( xTicksToWait > ( portTickType ) 0 )
\r
1270 /* As this is a co-routine we cannot block directly, but return
\r
1271 indicating that we need to block. */
\r
1272 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );
\r
1273 portENABLE_INTERRUPTS();
\r
1274 return errQUEUE_BLOCKED;
\r
1278 portENABLE_INTERRUPTS();
\r
1279 return errQUEUE_FULL;
\r
1283 portENABLE_INTERRUPTS();
\r
1287 portDISABLE_INTERRUPTS();
\r
1289 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1291 /* Data is available from the queue. */
\r
1292 pxQueue->pcReadFrom += pxQueue->uxItemSize;
\r
1293 if( pxQueue->pcReadFrom >= pxQueue->pcTail )
\r
1295 pxQueue->pcReadFrom = pxQueue->pcHead;
\r
1297 --( pxQueue->uxMessagesWaiting );
\r
1298 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1302 /* Were any co-routines waiting for space to become available? */
\r
1303 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
1305 /* In this instance the co-routine could be placed directly
\r
1306 into the ready list as we are within a critical section.
\r
1307 Instead the same pending ready list mechanism is used as if
\r
1308 the event were caused from within an interrupt. */
\r
1309 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1311 xReturn = errQUEUE_YIELD;
\r
1320 portENABLE_INTERRUPTS();
\r
1325 /*-----------------------------------------------------------*/
\r
1329 #if configUSE_CO_ROUTINES == 1
\r
1330 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )
\r
1332 /* Cannot block within an ISR so if there is no space on the queue then
\r
1333 exit without doing anything. */
\r
1334 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1336 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1338 /* We only want to wake one co-routine per ISR, so check that a
\r
1339 co-routine has not already been woken. */
\r
1340 if( !xCoRoutinePreviouslyWoken )
\r
1342 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
1344 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1352 return xCoRoutinePreviouslyWoken;
\r
1355 /*-----------------------------------------------------------*/
\r
1357 #if configUSE_CO_ROUTINES == 1
\r
1358 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )
\r
1360 signed portBASE_TYPE xReturn;
\r
1362 /* We cannot block from an ISR, so check there is data available. If
\r
1363 not then just leave without doing anything. */
\r
1364 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1366 /* Copy the data from the queue. */
\r
1367 pxQueue->pcReadFrom += pxQueue->uxItemSize;
\r
1368 if( pxQueue->pcReadFrom >= pxQueue->pcTail )
\r
1370 pxQueue->pcReadFrom = pxQueue->pcHead;
\r
1372 --( pxQueue->uxMessagesWaiting );
\r
1373 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1375 if( !( *pxCoRoutineWoken ) )
\r
1377 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
1379 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1381 *pxCoRoutineWoken = pdTRUE;
\r
1396 /*-----------------------------------------------------------*/
\r
1398 #if configQUEUE_REGISTRY_SIZE > 0
\r
1400 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcQueueName )
\r
1402 unsigned portBASE_TYPE ux;
\r
1404 /* See if there is an empty space in the registry. A NULL name denotes
\r
1406 for( ux = 0; ux < configQUEUE_REGISTRY_SIZE; ux++ )
\r
1408 if( xQueueRegistry[ ux ].pcQueueName == NULL )
\r
1410 /* Store the information on this queue. */
\r
1411 xQueueRegistry[ ux ].pcQueueName = pcQueueName;
\r
1412 xQueueRegistry[ ux ].xHandle = xQueue;
\r
1419 /*-----------------------------------------------------------*/
\r
1421 #if configQUEUE_REGISTRY_SIZE > 0
\r
1423 static void vQueueUnregisterQueue( xQueueHandle xQueue )
\r
1425 unsigned portBASE_TYPE ux;
\r
1427 /* See if the handle of the queue being unregistered in actually in the
\r
1429 for( ux = 0; ux < configQUEUE_REGISTRY_SIZE; ux++ )
\r
1431 if( xQueueRegistry[ ux ].xHandle == xQueue )
\r
1433 /* Set the name to NULL to show that this slot if free again. */
\r
1434 xQueueRegistry[ ux ].pcQueueName = NULL;
\r