2 FreeRTOS.org V4.7.0 - Copyright (C) 2003-2007 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 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com a version that has been certified for use
\r
32 in safety critical systems, plus commercial licensing, development and
\r
34 ***************************************************************************
\r
39 #include "FreeRTOS.h"
\r
41 #include "croutine.h"
\r
43 /*-----------------------------------------------------------
\r
44 * PUBLIC LIST API documented in list.h
\r
45 *----------------------------------------------------------*/
\r
47 /* Constants used with the cRxLock and cTxLock structure members. */
\r
48 #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )
\r
49 #define queueERRONEOUS_UNBLOCK ( -1 )
\r
51 /* For internal use only. */
\r
52 #define queueSEND_TO_BACK ( 0 )
\r
53 #define queueSEND_TO_FRONT ( 1 )
\r
55 /* Effectively make a union out of the xQUEUE structure. */
\r
56 #define pxMutexHolder pcTail
\r
57 #define uxQueueType pcHead
\r
58 #define uxRecursiveCallCount pcReadFrom
\r
59 #define queueQUEUE_IS_MUTEX NULL
\r
61 /* Semaphores do not actually store or copy data, so have an items size of
\r
63 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( 0 )
\r
64 #define queueDONT_BLOCK ( ( portTickType ) 0 )
\r
65 #define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0 )
\r
67 * Definition of the queue used by the scheduler.
\r
68 * Items are queued by copy, not reference.
\r
70 typedef struct QueueDefinition
\r
72 signed portCHAR *pcHead; /*< Points to the beginning of the queue storage area. */
\r
73 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
75 signed portCHAR *pcWriteTo; /*< Points to the free next place in the storage area. */
\r
76 signed portCHAR *pcReadFrom; /*< Points to the last place that a queued item was read from. */
\r
78 xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
\r
79 xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
\r
81 volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */
\r
82 unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
\r
83 unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */
\r
85 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
86 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
88 /*-----------------------------------------------------------*/
\r
91 * Inside this file xQueueHandle is a pointer to a xQUEUE structure.
\r
92 * To keep the definition private the API header file defines it as a
\r
95 typedef xQUEUE * xQueueHandle;
\r
98 * Prototypes for public functions are included here so we don't have to
\r
99 * include the API header file (as it defines xQueueHandle differently). These
\r
100 * functions are documented in the API header file.
\r
102 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
103 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
104 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue );
\r
105 void vQueueDelete( xQueueHandle xQueue );
\r
106 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken, portBASE_TYPE xCopyPosition );
\r
107 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
108 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
109 xQueueHandle xQueueCreateMutex( void );
\r
110 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
111 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
112 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
113 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
114 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
116 #if configUSE_CO_ROUTINES == 1
\r
117 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
118 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
119 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
120 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
124 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
\r
125 * prevent an ISR from adding or removing items to the queue, but does prevent
\r
126 * an ISR from removing tasks from the queue event lists. If an ISR finds a
\r
127 * queue is locked it will instead increment the appropriate queue lock count
\r
128 * to indicate that a task may require unblocking. When the queue in unlocked
\r
129 * these lock counts are inspected, and the appropriate action taken.
\r
131 static void prvUnlockQueue( xQueueHandle pxQueue );
\r
134 * Uses a critical section to determine if there is any data in a queue.
\r
136 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
\r
138 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue );
\r
141 * Uses a critical section to determine if there is any space in a queue.
\r
143 * @return pdTRUE if there is no space, otherwise pdFALSE;
\r
145 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue );
\r
148 * Copies an item into the queue, either at the front of the queue or the
\r
149 * back of the queue.
\r
151 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition );
\r
154 * Copies an item out of a queue.
\r
156 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer );
\r
157 /*-----------------------------------------------------------*/
\r
160 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
\r
161 * accessing the queue event lists.
\r
163 #define prvLockQueue( pxQueue ) \
\r
165 taskENTER_CRITICAL(); \
\r
166 ++( pxQueue->xRxLock ); \
\r
167 ++( pxQueue->xTxLock ); \
\r
168 taskEXIT_CRITICAL(); \
\r
170 /*-----------------------------------------------------------*/
\r
173 /*-----------------------------------------------------------
\r
174 * PUBLIC QUEUE MANAGEMENT API documented in queue.h
\r
175 *----------------------------------------------------------*/
\r
177 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize )
\r
179 xQUEUE *pxNewQueue;
\r
180 size_t xQueueSizeInBytes;
\r
182 /* Allocate the new queue structure. */
\r
183 if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
\r
185 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
186 if( pxNewQueue != NULL )
\r
188 /* Create the list of pointers to queue items. The queue is one byte
\r
189 longer than asked for to make wrap checking easier/faster. */
\r
190 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;
\r
192 pxNewQueue->pcHead = ( signed portCHAR * ) pvPortMalloc( xQueueSizeInBytes );
\r
193 if( pxNewQueue->pcHead != NULL )
\r
195 /* Initialise the queue members as described above where the
\r
196 queue type is defined. */
\r
197 pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize );
\r
198 pxNewQueue->uxMessagesWaiting = 0;
\r
199 pxNewQueue->pcWriteTo = pxNewQueue->pcHead;
\r
200 pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - 1 ) * uxItemSize );
\r
201 pxNewQueue->uxLength = uxQueueLength;
\r
202 pxNewQueue->uxItemSize = uxItemSize;
\r
203 pxNewQueue->xRxLock = queueUNLOCKED;
\r
204 pxNewQueue->xTxLock = queueUNLOCKED;
\r
206 /* Likewise ensure the event queues start with the correct state. */
\r
207 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
\r
208 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
\r
214 vPortFree( pxNewQueue );
\r
219 /* Will only reach here if we could not allocate enough memory or no memory
\r
223 /*-----------------------------------------------------------*/
\r
225 #if ( configUSE_MUTEXES == 1 )
\r
227 xQueueHandle xQueueCreateMutex( void )
\r
229 xQUEUE *pxNewQueue;
\r
231 /* Allocate the new queue structure. */
\r
232 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
233 if( pxNewQueue != NULL )
\r
235 /* Information required for priority inheritance. */
\r
236 pxNewQueue->pxMutexHolder = NULL;
\r
237 pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
\r
239 /* Queues used as a mutex no data is actually copied into or out
\r
241 pxNewQueue->pcWriteTo = NULL;
\r
242 pxNewQueue->pcReadFrom = NULL;
\r
244 /* Each mutex has a length of 1 (like a binary semaphore) and
\r
245 an item size of 0 as nothing is actually copied into or out
\r
247 pxNewQueue->uxMessagesWaiting = 0;
\r
248 pxNewQueue->uxLength = 1;
\r
249 pxNewQueue->uxItemSize = 0;
\r
250 pxNewQueue->xRxLock = queueUNLOCKED;
\r
251 pxNewQueue->xTxLock = queueUNLOCKED;
\r
253 /* Ensure the event queues start with the correct state. */
\r
254 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
\r
255 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
\r
257 /* Start with the semaphore in the expected state. */
\r
258 xQueueGenericSend( pxNewQueue, NULL, 0, queueSEND_TO_BACK );
\r
264 #endif /* configUSE_MUTEXES */
\r
265 /*-----------------------------------------------------------*/
\r
267 #if configUSE_RECURSIVE_MUTEXES == 1
\r
269 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex )
\r
271 portBASE_TYPE xReturn;
\r
273 /* If this is the task that holds the mutex then pxMutexHolder will not
\r
274 change outside of this task. If this task does not hold the mutex then
\r
275 pxMutexHolder can never coincidentally equal the tasks handle, and as
\r
276 this is the only condition we are interested in it does not matter if
\r
277 pxMutexHolder is accessed simultaneously by another task. Therefore no
\r
278 mutual exclusion is required to test the pxMutexHolder variable. */
\r
279 if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )
\r
281 /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to
\r
282 the task handle, therefore no underflow check is required. Also,
\r
283 uxRecursiveCallCount is only modified by the mutex holder, and as
\r
284 there can only be one, no mutual exclusion is required to modify the
\r
285 uxRecursiveCallCount member. */
\r
286 ( pxMutex->uxRecursiveCallCount )--;
\r
288 /* Have we unwound the call count? */
\r
289 if( pxMutex->uxRecursiveCallCount == 0 )
\r
291 /* Return the mutex. This will automatically unblock any other
\r
292 task that might be waiting to access the mutex. */
\r
293 xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
\r
300 /* We cannot give the mutex because we are not the holder. */
\r
307 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
308 /*-----------------------------------------------------------*/
\r
310 #if configUSE_RECURSIVE_MUTEXES == 1
\r
312 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime )
\r
314 portBASE_TYPE xReturn;
\r
316 /* Comments regarding mutual exclusion as per those within
\r
317 xQueueGiveMutexRecursive(). */
\r
319 if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )
\r
321 ( pxMutex->uxRecursiveCallCount )++;
\r
326 xReturn = xQueueGenericReceive( pxMutex, NULL, xBlockTime, pdFALSE );
\r
328 /* pdPASS will only be returned if we successfully obtained the mutex,
\r
329 we may have blocked to reach here. */
\r
330 if( xReturn == pdPASS )
\r
332 ( pxMutex->uxRecursiveCallCount )++;
\r
339 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
340 /*-----------------------------------------------------------*/
\r
342 #if configUSE_COUNTING_SEMAPHORES == 1
\r
344 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )
\r
346 xQueueHandle pxHandle;
\r
348 pxHandle = xQueueCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH );
\r
350 if( pxHandle != NULL )
\r
352 pxHandle->uxMessagesWaiting = uxInitialCount;
\r
358 #endif /* configUSE_COUNTING_SEMAPHORES */
\r
359 /*-----------------------------------------------------------*/
\r
361 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
363 signed portBASE_TYPE xReturn = pdPASS;
\r
364 xTimeOutType xTimeOut;
\r
366 /* Make sure other tasks do not access the queue. */
\r
369 /* Capture the current time status for future reference. */
\r
370 vTaskSetTimeOutState( &xTimeOut );
\r
372 /* It is important that this is the only thread/ISR that modifies the
\r
373 ready or delayed lists until xTaskResumeAll() is called. Places where
\r
374 the ready/delayed lists are modified include:
\r
376 + vTaskDelay() - Nothing can call vTaskDelay as the scheduler is
\r
377 suspended, vTaskDelay() cannot be called from an ISR.
\r
378 + vTaskPrioritySet() - Has a critical section around the access.
\r
379 + vTaskSwitchContext() - This will not get executed while the scheduler
\r
381 + prvCheckDelayedTasks() - This will not get executed while the
\r
382 scheduler is suspended.
\r
383 + xTaskCreate() - Has a critical section around the access.
\r
384 + vTaskResume() - Has a critical section around the access.
\r
385 + xTaskResumeAll() - Has a critical section around the access.
\r
386 + xTaskRemoveFromEventList - Checks to see if the scheduler is
\r
387 suspended. If so then the TCB being removed from the event is
\r
388 removed from the event and added to the xPendingReadyList.
\r
391 /* Make sure interrupts do not access the queue event list. */
\r
392 prvLockQueue( pxQueue );
\r
394 /* It is important that interrupts to not access the event list of the
\r
395 queue being modified here. Places where the event list is modified
\r
398 + xQueueGenericSendFromISR(). This checks the lock on the queue to see
\r
399 if it has access. If the queue is locked then the Tx lock count is
\r
400 incremented to signify that a task waiting for data can be made ready
\r
401 once the queue lock is removed. If the queue is not locked then
\r
402 a task can be moved from the event list, but will not be removed
\r
403 from the delayed list or placed in the ready list until the scheduler
\r
406 + xQueueReceiveFromISR(). As per xQueueGenericSendFromISR().
\r
409 /* If the queue is already full we may have to block. */
\r
412 if( prvIsQueueFull( pxQueue ) )
\r
414 /* The queue is full - do we want to block or just leave without
\r
416 if( xTicksToWait > ( portTickType ) 0 )
\r
418 /* We are going to place ourselves on the xTasksWaitingToSend event
\r
419 list, and will get woken should the delay expire, or space become
\r
420 available on the queue.
\r
422 As detailed above we do not require mutual exclusion on the event
\r
423 list as nothing else can modify it or the ready lists while we
\r
424 have the scheduler suspended and queue locked.
\r
426 It is possible that an ISR has removed data from the queue since we
\r
427 checked if any was available. If this is the case then the data
\r
428 will have been copied from the queue, and the queue variables
\r
429 updated, but the event list will not yet have been checked to see if
\r
430 anything is waiting as the queue is locked. */
\r
431 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
433 /* Force a context switch now as we are blocked. We can do
\r
434 this from within a critical section as the task we are
\r
435 switching to has its own context. When we return here (i.e. we
\r
436 unblock) we will leave the critical section as normal.
\r
438 It is possible that an ISR has caused an event on an unrelated and
\r
439 unlocked queue. If this was the case then the event list for that
\r
440 queue will have been updated but the ready lists left unchanged -
\r
441 instead the readied task will have been added to the pending ready
\r
443 taskENTER_CRITICAL();
\r
445 /* We can safely unlock the queue and scheduler here as
\r
446 interrupts are disabled. We must not yield with anything
\r
447 locked, but we can yield from within a critical section.
\r
449 Tasks that have been placed on the pending ready list cannot
\r
450 be tasks that are waiting for events on this queue. See
\r
451 in comment xTaskRemoveFromEventList(). */
\r
452 prvUnlockQueue( pxQueue );
\r
454 /* Resuming the scheduler may cause a yield. If so then there
\r
455 is no point yielding again here. */
\r
456 if( !xTaskResumeAll() )
\r
461 /* We want to check to see if the queue is still full
\r
462 before leaving the critical section. This is to prevent
\r
463 this task placing an item into the queue due to an
\r
464 interrupt making space on the queue between critical
\r
465 sections (when there might be a higher priority task
\r
466 blocked on the queue that cannot run yet because the
\r
467 scheduler gets suspended). */
\r
468 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
\r
470 /* We unblocked but there is no space in the queue,
\r
471 we probably timed out. */
\r
472 xReturn = errQUEUE_FULL;
\r
475 /* Before leaving the critical section we have to ensure
\r
476 exclusive access again. */
\r
478 prvLockQueue( pxQueue );
\r
480 taskEXIT_CRITICAL();
\r
484 /* If xReturn is errQUEUE_FULL then we unblocked when the queue
\r
485 was still full. Don't check it again now as it is possible that
\r
486 an interrupt has removed an item from the queue since we left the
\r
487 critical section and we don't want to write to the queue in case
\r
488 there is a task of higher priority blocked waiting for space to
\r
489 be available on the queue. If this is the case the higher priority
\r
490 task will execute when the scheduler is unsupended. */
\r
491 if( xReturn != errQUEUE_FULL )
\r
493 /* When we are here it is possible that we unblocked as space became
\r
494 available on the queue. It is also possible that an ISR posted to the
\r
495 queue since we left the critical section, so it may be that again there
\r
496 is no space. This would only happen if a task and ISR post onto the
\r
498 taskENTER_CRITICAL();
\r
500 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
502 /* There is room in the queue, copy the data into the queue. */
\r
503 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
506 /* Update the TxLock count so prvUnlockQueue knows to check for
\r
507 tasks waiting for data to become available in the queue. */
\r
508 ++( pxQueue->xTxLock );
\r
512 xReturn = errQUEUE_FULL;
\r
515 taskEXIT_CRITICAL();
\r
518 if( xReturn == errQUEUE_FULL )
\r
520 if( xTicksToWait > 0 )
\r
522 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
524 xReturn = queueERRONEOUS_UNBLOCK;
\r
529 while( xReturn == queueERRONEOUS_UNBLOCK );
\r
531 prvUnlockQueue( pxQueue );
\r
536 /*-----------------------------------------------------------*/
\r
538 #if configUSE_ALTERNATIVE_API == 1
\r
540 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
542 signed portBASE_TYPE xReturn;
\r
543 xTimeOutType xTimeOut;
\r
545 /* The source code that implements the alternative (Alt) API is much
\r
546 simpler because it executes everything from within a critical section.
\r
547 This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
548 preferred fully featured API too. The fully featured API has more
\r
549 complex code that takes longer to execute, but makes much less use of
\r
550 critical sections. Therefore the alternative API sacrifices interrupt
\r
551 responsiveness to gain execution speed, whereas the fully featured API
\r
552 sacrifices execution speed to ensure better interrupt responsiveness. */
\r
554 taskENTER_CRITICAL();
\r
556 /* Capture the current time status for future reference. */
\r
557 vTaskSetTimeOutState( &xTimeOut );
\r
559 /* If the queue is already full we may have to block. */
\r
562 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
\r
564 /* The queue is full - do we want to block or just leave without
\r
566 if( xTicksToWait > ( portTickType ) 0 )
\r
568 /* We are going to place ourselves on the xTasksWaitingToSend
\r
569 event list, and will get woken should the delay expire, or
\r
570 space become available on the queue. */
\r
571 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
573 /* Force a context switch now as we are blocked. We can do
\r
574 this from within a critical section as the task we are
\r
575 switching to has its own context. When we return here (i.e.
\r
576 we unblock) we will leave the critical section as normal. */
\r
581 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
583 /* There is room in the queue, copy the data into the queue. */
\r
584 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
587 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
589 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
591 /* The task waiting has a higher priority. */
\r
598 xReturn = errQUEUE_FULL;
\r
600 if( xTicksToWait > 0 )
\r
602 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
604 /* Another task must have accessed the queue between
\r
605 this task unblocking and actually executing. */
\r
606 xReturn = queueERRONEOUS_UNBLOCK;
\r
611 while( xReturn == queueERRONEOUS_UNBLOCK );
\r
613 taskEXIT_CRITICAL();
\r
618 #endif /* configUSE_ALTERNATIVE_API */
\r
619 /*-----------------------------------------------------------*/
\r
621 #if configUSE_ALTERNATIVE_API == 1
\r
623 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
625 signed portBASE_TYPE xReturn = pdTRUE;
\r
626 xTimeOutType xTimeOut;
\r
627 signed portCHAR *pcOriginalReadPosition;
\r
629 /* The source code that implements the alternative (Alt) API is much
\r
630 simpler because it executes everything from within a critical section.
\r
631 This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
632 preferred fully featured API too. The fully featured API has more
\r
633 complex code that takes longer to execute, but makes much less use of
\r
634 critical sections. Therefore the alternative API sacrifices interrupt
\r
635 responsiveness to gain execution speed, whereas the fully featured API
\r
636 sacrifices execution speed to ensure better interrupt responsiveness. */
\r
638 taskENTER_CRITICAL();
\r
640 /* Capture the current time status for future reference. */
\r
641 vTaskSetTimeOutState( &xTimeOut );
\r
645 /* If there are no messages in the queue we may have to block. */
\r
646 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
648 /* There are no messages in the queue, do we want to block or just
\r
649 leave with nothing? */
\r
650 if( xTicksToWait > ( portTickType ) 0 )
\r
652 #if ( configUSE_MUTEXES == 1 )
\r
654 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
656 vTaskPriorityInherit( ( void * const ) pxQueue->pxMutexHolder );
\r
661 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
666 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
668 /* Remember our read position in case we are just peeking. */
\r
669 pcOriginalReadPosition = pxQueue->pcReadFrom;
\r
671 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
673 if( xJustPeeking == pdFALSE )
\r
675 /* We are actually removing data. */
\r
676 --( pxQueue->uxMessagesWaiting );
\r
678 #if ( configUSE_MUTEXES == 1 )
\r
680 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
682 /* Record the information required to implement
\r
683 priority inheritance should it become necessary. */
\r
684 pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();
\r
689 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
691 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
693 /* The task waiting has a higher priority. */
\r
700 /* We are not removing the data, so reset our read
\r
702 pxQueue->pcReadFrom = pcOriginalReadPosition;
\r
709 xReturn = errQUEUE_EMPTY;
\r
711 if( xTicksToWait > 0 )
\r
713 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
715 xReturn = queueERRONEOUS_UNBLOCK;
\r
720 } while( xReturn == queueERRONEOUS_UNBLOCK );
\r
722 taskEXIT_CRITICAL();
\r
727 #endif /* configUSE_ALTERNATIVE_API */
\r
728 /*-----------------------------------------------------------*/
\r
730 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken, portBASE_TYPE xCopyPosition )
\r
732 /* Similar to xQueueGenericSend, except we don't block if there is no room
\r
733 in the queue. Also we don't directly wake a task that was blocked on a
\r
734 queue read, instead we return a flag to say whether a context switch is
\r
735 required or not (i.e. has a task with a higher priority than us been woken
\r
737 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
739 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
741 /* If the queue is locked we do not alter the event list. This will
\r
742 be done when the queue is unlocked later. */
\r
743 if( pxQueue->xTxLock == queueUNLOCKED )
\r
745 /* We only want to wake one task per ISR, so check that a task has
\r
746 not already been woken. */
\r
747 if( !xTaskPreviouslyWoken )
\r
749 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
751 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
753 /* The task waiting has a higher priority so record that a
\r
754 context switch is required. */
\r
762 /* Increment the lock count so the task that unlocks the queue
\r
763 knows that data was posted while it was locked. */
\r
764 ++( pxQueue->xTxLock );
\r
768 return xTaskPreviouslyWoken;
\r
770 /*-----------------------------------------------------------*/
\r
772 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
774 signed portBASE_TYPE xReturn = pdTRUE;
\r
775 xTimeOutType xTimeOut;
\r
776 signed portCHAR *pcOriginalReadPosition;
\r
778 /* This function is very similar to xQueueGenericSend(). See comments
\r
779 within xQueueGenericSend() for a more detailed explanation.
\r
781 Make sure other tasks do not access the queue. */
\r
784 /* Capture the current time status for future reference. */
\r
785 vTaskSetTimeOutState( &xTimeOut );
\r
787 /* Make sure interrupts do not access the queue. */
\r
788 prvLockQueue( pxQueue );
\r
792 /* If there are no messages in the queue we may have to block. */
\r
793 if( prvIsQueueEmpty( pxQueue ) )
\r
795 /* There are no messages in the queue, do we want to block or just
\r
796 leave with nothing? */
\r
797 if( xTicksToWait > ( portTickType ) 0 )
\r
799 #if ( configUSE_MUTEXES == 1 )
\r
801 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
803 portENTER_CRITICAL();
\r
804 vTaskPriorityInherit( ( void * const ) pxQueue->pxMutexHolder );
\r
805 portEXIT_CRITICAL();
\r
810 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
811 taskENTER_CRITICAL();
\r
813 prvUnlockQueue( pxQueue );
\r
814 if( !xTaskResumeAll() )
\r
819 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
821 /* We unblocked but the queue is empty. We probably
\r
823 xReturn = errQUEUE_EMPTY;
\r
827 prvLockQueue( pxQueue );
\r
829 taskEXIT_CRITICAL();
\r
833 if( xReturn != errQUEUE_EMPTY )
\r
835 taskENTER_CRITICAL();
\r
837 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
839 /* Remember our read position in case we are just peeking. */
\r
840 pcOriginalReadPosition = pxQueue->pcReadFrom;
\r
842 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
844 if( xJustPeeking == pdFALSE )
\r
846 /* We are actually removing data. */
\r
847 --( pxQueue->uxMessagesWaiting );
\r
849 /* Increment the lock count so prvUnlockQueue knows to check for
\r
850 tasks waiting for space to become available on the queue. */
\r
851 ++( pxQueue->xRxLock );
\r
853 #if ( configUSE_MUTEXES == 1 )
\r
855 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
857 /* Record the information required to implement
\r
858 priority inheritance should it become necessary. */
\r
859 pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();
\r
866 /* We are not removing the data, so reset our read
\r
868 pxQueue->pcReadFrom = pcOriginalReadPosition;
\r
870 /* The data is being left in the queue, so increment the
\r
871 lock count so prvUnlockQueue knows to check for other
\r
872 tasks waiting for the data to be available. */
\r
873 ++( pxQueue->xTxLock );
\r
880 xReturn = errQUEUE_EMPTY;
\r
883 taskEXIT_CRITICAL();
\r
886 if( xReturn == errQUEUE_EMPTY )
\r
888 if( xTicksToWait > 0 )
\r
890 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
892 xReturn = queueERRONEOUS_UNBLOCK;
\r
896 } while( xReturn == queueERRONEOUS_UNBLOCK );
\r
898 /* We no longer require exclusive access to the queue. */
\r
899 prvUnlockQueue( pxQueue );
\r
904 /*-----------------------------------------------------------*/
\r
906 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken )
\r
908 signed portBASE_TYPE xReturn;
\r
910 /* We cannot block from an ISR, so check there is data available. */
\r
911 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
913 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
914 --( pxQueue->uxMessagesWaiting );
\r
916 /* If the queue is locked we will not modify the event list. Instead
\r
917 we update the lock count so the task that unlocks the queue will know
\r
918 that an ISR has removed data while the queue was locked. */
\r
919 if( pxQueue->xRxLock == queueUNLOCKED )
\r
921 /* We only want to wake one task per ISR, so check that a task has
\r
922 not already been woken. */
\r
923 if( !( *pxTaskWoken ) )
\r
925 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
927 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
929 /* The task waiting has a higher priority than us so
\r
930 force a context switch. */
\r
931 *pxTaskWoken = pdTRUE;
\r
938 /* Increment the lock count so the task that unlocks the queue
\r
939 knows that data was removed while it was locked. */
\r
940 ++( pxQueue->xRxLock );
\r
952 /*-----------------------------------------------------------*/
\r
954 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue )
\r
956 unsigned portBASE_TYPE uxReturn;
\r
958 taskENTER_CRITICAL();
\r
959 uxReturn = pxQueue->uxMessagesWaiting;
\r
960 taskEXIT_CRITICAL();
\r
964 /*-----------------------------------------------------------*/
\r
966 void vQueueDelete( xQueueHandle pxQueue )
\r
968 vPortFree( pxQueue->pcHead );
\r
969 vPortFree( pxQueue );
\r
971 /*-----------------------------------------------------------*/
\r
973 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )
\r
975 if( pxQueue->uxItemSize == 0 )
\r
977 #if ( configUSE_MUTEXES == 1 )
\r
979 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
981 /* The mutex is no longer being held. */
\r
982 vTaskPriorityDisinherit( ( void * const ) pxQueue->pxMutexHolder );
\r
983 pxQueue->pxMutexHolder = NULL;
\r
988 else if( xPosition == queueSEND_TO_BACK )
\r
990 memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );
\r
991 pxQueue->pcWriteTo += pxQueue->uxItemSize;
\r
992 if( pxQueue->pcWriteTo >= pxQueue->pcTail )
\r
994 pxQueue->pcWriteTo = pxQueue->pcHead;
\r
999 memcpy( ( void * ) pxQueue->pcReadFrom, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );
\r
1000 pxQueue->pcReadFrom -= pxQueue->uxItemSize;
\r
1001 if( pxQueue->pcReadFrom < pxQueue->pcHead )
\r
1003 pxQueue->pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );
\r
1007 ++( pxQueue->uxMessagesWaiting );
\r
1009 /*-----------------------------------------------------------*/
\r
1011 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
\r
1013 if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )
\r
1015 pxQueue->pcReadFrom += pxQueue->uxItemSize;
\r
1016 if( pxQueue->pcReadFrom >= pxQueue->pcTail )
\r
1018 pxQueue->pcReadFrom = pxQueue->pcHead;
\r
1020 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1023 /*-----------------------------------------------------------*/
\r
1025 static void prvUnlockQueue( xQueueHandle pxQueue )
\r
1027 /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
\r
1029 /* The lock counts contains the number of extra data items placed or
\r
1030 removed from the queue while the queue was locked. When a queue is
\r
1031 locked items can be added or removed, but the event lists cannot be
\r
1033 taskENTER_CRITICAL();
\r
1035 --( pxQueue->xTxLock );
\r
1037 /* See if data was added to the queue while it was locked. */
\r
1038 if( pxQueue->xTxLock > queueUNLOCKED )
\r
1040 pxQueue->xTxLock = queueUNLOCKED;
\r
1042 /* Data was posted while the queue was locked. Are any tasks
\r
1043 blocked waiting for data to become available? */
\r
1044 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
1046 /* Tasks that are removed from the event list will get added to
\r
1047 the pending ready list as the scheduler is still suspended. */
\r
1048 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1050 /* The task waiting has a higher priority so record that a
\r
1051 context switch is required. */
\r
1052 vTaskMissedYield();
\r
1057 taskEXIT_CRITICAL();
\r
1059 /* Do the same for the Rx lock. */
\r
1060 taskENTER_CRITICAL();
\r
1062 --( pxQueue->xRxLock );
\r
1064 if( pxQueue->xRxLock > queueUNLOCKED )
\r
1066 pxQueue->xRxLock = queueUNLOCKED;
\r
1068 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
1070 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1072 vTaskMissedYield();
\r
1077 taskEXIT_CRITICAL();
\r
1079 /*-----------------------------------------------------------*/
\r
1081 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue )
\r
1083 signed portBASE_TYPE xReturn;
\r
1085 taskENTER_CRITICAL();
\r
1086 xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );
\r
1087 taskEXIT_CRITICAL();
\r
1091 /*-----------------------------------------------------------*/
\r
1093 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue )
\r
1095 signed portBASE_TYPE xReturn;
\r
1097 taskENTER_CRITICAL();
\r
1098 xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );
\r
1099 taskEXIT_CRITICAL();
\r
1103 /*-----------------------------------------------------------*/
\r
1105 #if configUSE_CO_ROUTINES == 1
\r
1106 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait )
\r
1108 signed portBASE_TYPE xReturn;
\r
1110 /* If the queue is already full we may have to block. A critical section
\r
1111 is required to prevent an interrupt removing something from the queue
\r
1112 between the check to see if the queue is full and blocking on the queue. */
\r
1113 portDISABLE_INTERRUPTS();
\r
1115 if( prvIsQueueFull( pxQueue ) )
\r
1117 /* The queue is full - do we want to block or just leave without
\r
1119 if( xTicksToWait > ( portTickType ) 0 )
\r
1121 /* As this is called from a coroutine we cannot block directly, but
\r
1122 return indicating that we need to block. */
\r
1123 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );
\r
1124 portENABLE_INTERRUPTS();
\r
1125 return errQUEUE_BLOCKED;
\r
1129 portENABLE_INTERRUPTS();
\r
1130 return errQUEUE_FULL;
\r
1134 portENABLE_INTERRUPTS();
\r
1138 portDISABLE_INTERRUPTS();
\r
1140 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1142 /* There is room in the queue, copy the data into the queue. */
\r
1143 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1146 /* Were any co-routines waiting for data to become available? */
\r
1147 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
1149 /* In this instance the co-routine could be placed directly
\r
1150 into the ready list as we are within a critical section.
\r
1151 Instead the same pending ready list mechanism is used as if
\r
1152 the event were caused from within an interrupt. */
\r
1153 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1155 /* The co-routine waiting has a higher priority so record
\r
1156 that a yield might be appropriate. */
\r
1157 xReturn = errQUEUE_YIELD;
\r
1163 xReturn = errQUEUE_FULL;
\r
1166 portENABLE_INTERRUPTS();
\r
1171 /*-----------------------------------------------------------*/
\r
1173 #if configUSE_CO_ROUTINES == 1
\r
1174 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )
\r
1176 signed portBASE_TYPE xReturn;
\r
1178 /* If the queue is already empty we may have to block. A critical section
\r
1179 is required to prevent an interrupt adding something to the queue
\r
1180 between the check to see if the queue is empty and blocking on the queue. */
\r
1181 portDISABLE_INTERRUPTS();
\r
1183 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
1185 /* There are no messages in the queue, do we want to block or just
\r
1186 leave with nothing? */
\r
1187 if( xTicksToWait > ( portTickType ) 0 )
\r
1189 /* As this is a co-routine we cannot block directly, but return
\r
1190 indicating that we need to block. */
\r
1191 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );
\r
1192 portENABLE_INTERRUPTS();
\r
1193 return errQUEUE_BLOCKED;
\r
1197 portENABLE_INTERRUPTS();
\r
1198 return errQUEUE_FULL;
\r
1202 portENABLE_INTERRUPTS();
\r
1206 portDISABLE_INTERRUPTS();
\r
1208 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1210 /* Data is available from the queue. */
\r
1211 pxQueue->pcReadFrom += pxQueue->uxItemSize;
\r
1212 if( pxQueue->pcReadFrom >= pxQueue->pcTail )
\r
1214 pxQueue->pcReadFrom = pxQueue->pcHead;
\r
1216 --( pxQueue->uxMessagesWaiting );
\r
1217 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1221 /* Were any co-routines waiting for space to become available? */
\r
1222 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
1224 /* In this instance the co-routine could be placed directly
\r
1225 into the ready list as we are within a critical section.
\r
1226 Instead the same pending ready list mechanism is used as if
\r
1227 the event were caused from within an interrupt. */
\r
1228 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1230 xReturn = errQUEUE_YIELD;
\r
1239 portENABLE_INTERRUPTS();
\r
1244 /*-----------------------------------------------------------*/
\r
1248 #if configUSE_CO_ROUTINES == 1
\r
1249 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )
\r
1251 /* Cannot block within an ISR so if there is no space on the queue then
\r
1252 exit without doing anything. */
\r
1253 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1255 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1257 /* We only want to wake one co-routine per ISR, so check that a
\r
1258 co-routine has not already been woken. */
\r
1259 if( !xCoRoutinePreviouslyWoken )
\r
1261 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
\r
1263 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1271 return xCoRoutinePreviouslyWoken;
\r
1274 /*-----------------------------------------------------------*/
\r
1276 #if configUSE_CO_ROUTINES == 1
\r
1277 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )
\r
1279 signed portBASE_TYPE xReturn;
\r
1281 /* We cannot block from an ISR, so check there is data available. If
\r
1282 not then just leave without doing anything. */
\r
1283 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1285 /* Copy the data from the queue. */
\r
1286 pxQueue->pcReadFrom += pxQueue->uxItemSize;
\r
1287 if( pxQueue->pcReadFrom >= pxQueue->pcTail )
\r
1289 pxQueue->pcReadFrom = pxQueue->pcHead;
\r
1291 --( pxQueue->uxMessagesWaiting );
\r
1292 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1294 if( !( *pxCoRoutineWoken ) )
\r
1296 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
\r
1298 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1300 *pxCoRoutineWoken = pdTRUE;
\r
1315 /*-----------------------------------------------------------*/
\r