queue.h File Reference

#include "mpu_wrappers.h"

Go to the source code of this file.

Defines

#define queueSEND_TO_BACK   ( 0 )
#define queueSEND_TO_FRONT   ( 1 )
#define xQueueAltPeek(xQueue, pvBuffer, xTicksToWait)   xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
#define xQueueAltReceive(xQueue, pvBuffer, xTicksToWait)   xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
#define xQueueAltSendToBack(xQueue, pvItemToQueue, xTicksToWait)   xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
#define xQueueAltSendToFront(xQueue, pvItemToQueue, xTicksToWait)   xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
#define xQueuePeek(xQueue, pvBuffer, xTicksToWait)   xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
#define xQueueReceive(xQueue, pvBuffer, xTicksToWait)   xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
#define xQueueSend(xQueue, pvItemToQueue, xTicksToWait)   xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
#define xQueueSendFromISR(pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken)   xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
#define xQueueSendToBack(xQueue, pvItemToQueue, xTicksToWait)   xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
#define xQueueSendToBackFromISR(pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken)   xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
#define xQueueSendToFront(xQueue, pvItemToQueue, xTicksToWait)   xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
#define xQueueSendToFrontFromISR(pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken)   xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )

Typedefs

typedef void * xQueueHandle

Functions

unsigned portBASE_TYPE uxQueueMessagesWaiting (const xQueueHandle xQueue)
unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR (const xQueueHandle pxQueue)
void vQueueDelete (xQueueHandle xQueue)
signed portBASE_TYPE xQueueAltGenericReceive (xQueueHandle pxQueue, void *const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking)
signed portBASE_TYPE xQueueAltGenericSend (xQueueHandle pxQueue, const void *const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition)
xQueueHandle xQueueCreate (unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize)
xQueueHandle xQueueCreateCountingSemaphore (unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount)
xQueueHandle xQueueCreateMutex (void)
signed portBASE_TYPE xQueueCRReceive (xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait)
signed portBASE_TYPE xQueueCRReceiveFromISR (xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken)
signed portBASE_TYPE xQueueCRSend (xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait)
signed portBASE_TYPE xQueueCRSendFromISR (xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken)
signed portBASE_TYPE xQueueGenericReceive (xQueueHandle xQueue, void *const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek)
signed portBASE_TYPE xQueueGenericSend (xQueueHandle xQueue, const void *const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition)
signed portBASE_TYPE xQueueGenericSendFromISR (xQueueHandle pxQueue, const void *const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition)
portBASE_TYPE xQueueGiveMutexRecursive (xQueueHandle xMutex)
signed portBASE_TYPE xQueueIsQueueEmptyFromISR (const xQueueHandle pxQueue)
signed portBASE_TYPE xQueueIsQueueFullFromISR (const xQueueHandle pxQueue)
signed portBASE_TYPE xQueueReceiveFromISR (xQueueHandle pxQueue, void *const pvBuffer, signed portBASE_TYPE *pxTaskWoken)
portBASE_TYPE xQueueTakeMutexRecursive (xQueueHandle xMutex, portTickType xBlockTime)


Define Documentation

#define queueSEND_TO_BACK   ( 0 )

Definition at line 76 of file queue.h.

Referenced by prvCopyDataToQueue().

#define queueSEND_TO_FRONT   ( 1 )

Definition at line 77 of file queue.h.

#define xQueueAltPeek ( xQueue,
pvBuffer,
xTicksToWait   )     xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )

Definition at line 1199 of file queue.h.

Referenced by prvSendFrontAndBackTest().

#define xQueueAltReceive ( xQueue,
pvBuffer,
xTicksToWait   )     xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )

#define xQueueAltSendToBack ( xQueue,
pvItemToQueue,
xTicksToWait   )     xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )

#define xQueueAltSendToFront ( xQueue,
pvItemToQueue,
xTicksToWait   )     xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )

Definition at line 1196 of file queue.h.

Referenced by prvSendFrontAndBackTest().

#define xQueuePeek ( xQueue,
pvBuffer,
xTicksToWait   )     xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )

#define xQueueReceive ( xQueue,
pvBuffer,
xTicksToWait   )     xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )

#define xQueueSend ( xQueue,
pvItemToQueue,
xTicksToWait   )     xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )

#define xQueueSendFromISR ( pxQueue,
pvItemToQueue,
pxHigherPriorityTaskWoken   )     xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )

Definition at line 1002 of file queue.h.

Referenced by prvUSART_ISR_NonNakedBehaviour().

#define xQueueSendToBack ( xQueue,
pvItemToQueue,
xTicksToWait   )     xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )

Definition at line 300 of file queue.h.

Referenced by prvLowPriorityPeekTask(), and prvSendFrontAndBackTest().

#define xQueueSendToBackFromISR ( pxQueue,
pvItemToQueue,
pxHigherPriorityTaskWoken   )     xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )

Definition at line 928 of file queue.h.

#define xQueueSendToFront ( xQueue,
pvItemToQueue,
xTicksToWait   )     xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )

Definition at line 218 of file queue.h.

Referenced by prvLowPriorityPeekTask(), and prvSendFrontAndBackTest().

#define xQueueSendToFrontFromISR ( pxQueue,
pvItemToQueue,
pxHigherPriorityTaskWoken   )     xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )

Definition at line 857 of file queue.h.


Typedef Documentation

typedef void* xQueueHandle

Definition at line 72 of file queue.h.


Function Documentation

unsigned portBASE_TYPE uxQueueMessagesWaiting ( const xQueueHandle  xQueue  ) 

Definition at line 1019 of file queue.c.

References taskENTER_CRITICAL, and taskEXIT_CRITICAL.

Referenced by portTASK_FUNCTION(), prvHighestPriorityPeekTask(), prvHighPriorityPeekTask(), prvLowPriorityPeekTask(), prvMediumPriorityPeekTask(), and prvSendFrontAndBackTest().

01019 {
01020 unsigned portBASE_TYPE uxReturn;
01021 
01022     taskENTER_CRITICAL();
01023         uxReturn = pxQueue->uxMessagesWaiting;
01024     taskEXIT_CRITICAL();
01025 
01026     return uxReturn;
01027 }
01028 /*-----------------------------------------------------------*/

unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR ( const xQueueHandle  pxQueue  ) 

Definition at line 1031 of file queue.c.

01031 {
01032 unsigned portBASE_TYPE uxReturn;
01033 
01034     uxReturn = pxQueue->uxMessagesWaiting;
01035 
01036     return uxReturn;
01037 }
01038 /*-----------------------------------------------------------*/

void vQueueDelete ( xQueueHandle  xQueue  ) 

Definition at line 1041 of file queue.c.

References traceQUEUE_DELETE, vPortFree(), and vQueueUnregisterQueue.

01041 {
01042     traceQUEUE_DELETE( pxQueue );
01043     vQueueUnregisterQueue( pxQueue );
01044     vPortFree( pxQueue->pcHead );
01045     vPortFree( pxQueue );
01046 }
01047 /*-----------------------------------------------------------*/

signed portBASE_TYPE xQueueAltGenericReceive ( xQueueHandle  pxQueue,
void *const   pvBuffer,
portTickType  xTicksToWait,
portBASE_TYPE  xJustPeeking 
)

signed portBASE_TYPE xQueueAltGenericSend ( xQueueHandle  pxQueue,
const void *const   pvItemToQueue,
portTickType  xTicksToWait,
portBASE_TYPE  xCopyPosition 
)

xQueueHandle xQueueCreate ( unsigned portBASE_TYPE  uxQueueLength,
unsigned portBASE_TYPE  uxItemSize 
)

xQueueHandle xQueueCreateCountingSemaphore ( unsigned portBASE_TYPE  uxCountValue,
unsigned portBASE_TYPE  uxInitialCount 
)

xQueueHandle xQueueCreateMutex ( void   ) 

Definition at line 138 of file queue.c.

00169     {
00170         signed char *pcQueueName;
00171         xQueueHandle xHandle;
00172     } xQueueRegistryItem;
00173 
00174     /* The queue registry is simply an array of xQueueRegistryItem structures.
00175     The pcQueueName member of a structure being NULL is indicative of the
00176     array position being vacant. */
00177     xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
00178 
00179     /* Removes a queue from the registry by simply setting the pcQueueName
00180     member to NULL. */
00181     static void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
00182     void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName ) PRIVILEGED_FUNCTION;
00183 #endif
00184 
00185 /*
00186  * Unlocks a queue locked by a call to prvLockQueue.  Locking a queue does not
00187  * prevent an ISR from adding or removing items to the queue, but does prevent
00188  * an ISR from removing tasks from the queue event lists.  If an ISR finds a
00189  * queue is locked it will instead increment the appropriate queue lock count
00190  * to indicate that a task may require unblocking.  When the queue in unlocked
00191  * these lock counts are inspected, and the appropriate action taken.
00192  */
00193 static void prvUnlockQueue( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
00194 
00195 /*
00196  * Uses a critical section to determine if there is any data in a queue.
00197  *
00198  * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
00199  */
00200 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
00201 
00202 /*
00203  * Uses a critical section to determine if there is any space in a queue.
00204  *
00205  * @return pdTRUE if there is no space, otherwise pdFALSE;
00206  */
00207 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
00208 
00209 /*
00210  * Copies an item into the queue, either at the front of the queue or the
00211  * back of the queue.
00212  */
00213 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition ) PRIVILEGED_FUNCTION;
00214 
00215 /*
00216  * Copies an item out of a queue.
00217  */
00218 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) PRIVILEGED_FUNCTION;
00219 /*-----------------------------------------------------------*/
00220 
00221 /*
00222  * Macro to mark a queue as locked.  Locking a queue prevents an ISR from
00223  * accessing the queue event lists.
00224  */
00225 #define prvLockQueue( pxQueue )                         \
00226 {                                                       \
00227     taskENTER_CRITICAL();                               \
00228     {                                                   \
00229         if( pxQueue->xRxLock == queueUNLOCKED )         \
00230         {                                               \
00231             pxQueue->xRxLock = queueLOCKED_UNMODIFIED;  \
00232         }                                               \
00233         if( pxQueue->xTxLock == queueUNLOCKED )         \
00234         {                                               \
00235             pxQueue->xTxLock = queueLOCKED_UNMODIFIED;  \
00236         }                                               \
00237     }                                                   \
00238     taskEXIT_CRITICAL();                                \
00239 }
00240 /*-----------------------------------------------------------*/
00241 
00242 
00243 /*-----------------------------------------------------------
00244  * PUBLIC QUEUE MANAGEMENT API documented in queue.h
00245  *----------------------------------------------------------*/
00246 
00247 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize )
00248 {
00249 xQUEUE *pxNewQueue;
00250 size_t xQueueSizeInBytes;
00251 
00252     /* Allocate the new queue structure. */
00253     if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
00254     {
00255         pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
00256         if( pxNewQueue != NULL )
00257         {
00258             /* Create the list of pointers to queue items.  The queue is one byte
00259             longer than asked for to make wrap checking easier/faster. */
00260             xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;
00261 
00262             pxNewQueue->pcHead = ( signed char * ) pvPortMalloc( xQueueSizeInBytes );
00263             if( pxNewQueue->pcHead != NULL )
00264             {
00265                 /* Initialise the queue members as described above where the
00266                 queue type is defined. */
00267                 pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize );
00268                 pxNewQueue->uxMessagesWaiting = 0;
00269                 pxNewQueue->pcWriteTo = pxNewQueue->pcHead;
00270                 pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - 1 ) * uxItemSize );
00271                 pxNewQueue->uxLength = uxQueueLength;
00272                 pxNewQueue->uxItemSize = uxItemSize;
00273                 pxNewQueue->xRxLock = queueUNLOCKED;
00274                 pxNewQueue->xTxLock = queueUNLOCKED;
00275 
00276                 /* Likewise ensure the event queues start with the correct state. */
00277                 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
00278                 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
00279 
00280                 traceQUEUE_CREATE( pxNewQueue );
00281                 return  pxNewQueue;
00282             }
00283             else
00284             {
00285                 traceQUEUE_CREATE_FAILED();
00286                 vPortFree( pxNewQueue );
00287             }
00288         }
00289     }
00290 
00291     /* Will only reach here if we could not allocate enough memory or no memory
00292     was required. */
00293     return NULL;
00294 }

signed portBASE_TYPE xQueueCRReceive ( xQueueHandle  pxQueue,
void *  pvBuffer,
portTickType  xTicksToWait 
)

signed portBASE_TYPE xQueueCRReceiveFromISR ( xQueueHandle  pxQueue,
void *  pvBuffer,
signed portBASE_TYPE *  pxTaskWoken 
)

signed portBASE_TYPE xQueueCRSend ( xQueueHandle  pxQueue,
const void *  pvItemToQueue,
portTickType  xTicksToWait 
)

signed portBASE_TYPE xQueueCRSendFromISR ( xQueueHandle  pxQueue,
const void *  pvItemToQueue,
signed portBASE_TYPE  xCoRoutinePreviouslyWoken 
)

signed portBASE_TYPE xQueueGenericReceive ( xQueueHandle  xQueue,
void *const   pvBuffer,
portTickType  xTicksToWait,
portBASE_TYPE  xJustPeek 
)

Definition at line 821 of file queue.c.

References errQUEUE_EMPTY, listLIST_IS_EMPTY, pdFALSE, pdPASS, pdTRUE, portENTER_CRITICAL, portEXIT_CRITICAL, portYIELD_WITHIN_API, prvCopyDataFromQueue(), prvIsQueueEmpty(), prvLockQueue, prvUnlockQueue(), queueQUEUE_IS_MUTEX, taskENTER_CRITICAL, taskEXIT_CRITICAL, traceBLOCKING_ON_QUEUE_RECEIVE, traceQUEUE_PEEK, traceQUEUE_RECEIVE, traceQUEUE_RECEIVE_FAILED, vTaskPlaceOnEventList(), vTaskPriorityInherit(), vTaskSetTimeOutState(), vTaskSuspendAll(), xTaskCheckForTimeOut(), xTaskGetCurrentTaskHandle(), xTaskRemoveFromEventList(), and xTaskResumeAll().

00821 {
00822 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
00823 xTimeOutType xTimeOut;
00824 signed char *pcOriginalReadPosition;
00825 
00826     /* This function relaxes the coding standard somewhat to allow return
00827     statements within the function itself.  This is done in the interest
00828     of execution time efficiency. */
00829 
00830     for( ;; )
00831     {
00832         taskENTER_CRITICAL();
00833         {
00834             /* Is there data in the queue now?  To be running we must be
00835             the highest priority task wanting to access the queue. */
00836             if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
00837             {
00838                 /* Remember our read position in case we are just peeking. */
00839                 pcOriginalReadPosition = pxQueue->pcReadFrom;
00840 
00841                 prvCopyDataFromQueue( pxQueue, pvBuffer );
00842 
00843                 if( xJustPeeking == pdFALSE )
00844                 {
00845                     traceQUEUE_RECEIVE( pxQueue );
00846 
00847                     /* We are actually removing data. */
00848                     --( pxQueue->uxMessagesWaiting );
00849 
00850                     #if ( configUSE_MUTEXES == 1 )
00851                     {
00852                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
00853                         {
00854                             /* Record the information required to implement
00855                             priority inheritance should it become necessary. */
00856                             pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();
00857                         }
00858                     }
00859                     #endif
00860 
00861                     if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
00862                     {
00863                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
00864                         {
00865                             portYIELD_WITHIN_API();
00866                         }
00867                     }
00868                 }
00869                 else
00870                 {
00871                     traceQUEUE_PEEK( pxQueue );
00872 
00873                     /* We are not removing the data, so reset our read
00874                     pointer. */
00875                     pxQueue->pcReadFrom = pcOriginalReadPosition;
00876 
00877                     /* The data is being left in the queue, so see if there are
00878                     any other tasks waiting for the data. */
00879                     if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
00880                     {
00881                         /* Tasks that are removed from the event list will get added to
00882                         the pending ready list as the scheduler is still suspended. */
00883                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
00884                         {
00885                             /* The task waiting has a higher priority than this task. */
00886                             portYIELD_WITHIN_API();
00887                         }
00888                     }
00889 
00890                 }
00891 
00892                 taskEXIT_CRITICAL();
00893                 return pdPASS;
00894             }
00895             else
00896             {
00897                 if( xTicksToWait == ( portTickType ) 0 )
00898                 {
00899                     /* The queue was empty and no block time is specified (or
00900                     the block time has expired) so leave now. */
00901                     taskEXIT_CRITICAL();
00902                     traceQUEUE_RECEIVE_FAILED( pxQueue );
00903                     return errQUEUE_EMPTY;
00904                 }
00905                 else if( xEntryTimeSet == pdFALSE )
00906                 {
00907                     /* The queue was empty and a block time was specified so
00908                     configure the timeout structure. */
00909                     vTaskSetTimeOutState( &xTimeOut );
00910                     xEntryTimeSet = pdTRUE;
00911                 }
00912             }
00913         }
00914         taskEXIT_CRITICAL();
00915 
00916         /* Interrupts and other tasks can send to and receive from the queue
00917         now the critical section has been exited. */
00918 
00919         vTaskSuspendAll();
00920         prvLockQueue( pxQueue );
00921 
00922         /* Update the timeout state to see if it has expired yet. */
00923         if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
00924         {
00925             if( prvIsQueueEmpty( pxQueue ) )
00926             {
00927                 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
00928 
00929                 #if ( configUSE_MUTEXES == 1 )
00930                 {
00931                     if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
00932                     {
00933                         portENTER_CRITICAL();
00934                         {
00935                             vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
00936                         }
00937                         portEXIT_CRITICAL();
00938                     }
00939                 }
00940                 #endif
00941 
00942                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
00943                 prvUnlockQueue( pxQueue );
00944                 if( !xTaskResumeAll() )
00945                 {
00946                     portYIELD_WITHIN_API();
00947                 }
00948             }
00949             else
00950             {
00951                 /* Try again. */
00952                 prvUnlockQueue( pxQueue );
00953                 ( void ) xTaskResumeAll();
00954             }
00955         }
00956         else
00957         {
00958             prvUnlockQueue( pxQueue );
00959             ( void ) xTaskResumeAll();
00960             traceQUEUE_RECEIVE_FAILED( pxQueue );
00961             return errQUEUE_EMPTY;
00962         }
00963     }
00964 }
00965 /*-----------------------------------------------------------*/

signed portBASE_TYPE xQueueGenericSend ( xQueueHandle  xQueue,
const void *const   pvItemToQueue,
portTickType  xTicksToWait,
portBASE_TYPE  xCopyPosition 
)

Definition at line 452 of file queue.c.

References errQUEUE_FULL, listLIST_IS_EMPTY, pdFALSE, pdPASS, pdTRUE, portYIELD_WITHIN_API, prvCopyDataToQueue(), prvIsQueueFull(), prvLockQueue, prvUnlockQueue(), taskENTER_CRITICAL, taskEXIT_CRITICAL, traceBLOCKING_ON_QUEUE_SEND, traceQUEUE_SEND, traceQUEUE_SEND_FAILED, vTaskPlaceOnEventList(), vTaskSetTimeOutState(), vTaskSuspendAll(), xTaskCheckForTimeOut(), xTaskRemoveFromEventList(), and xTaskResumeAll().

00452 {
00453 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
00454 xTimeOutType xTimeOut;
00455 
00456     /* This function relaxes the coding standard somewhat to allow return
00457     statements within the function itself.  This is done in the interest
00458     of execution time efficiency. */
00459     for( ;; )
00460     {
00461         taskENTER_CRITICAL();
00462         {
00463             /* Is there room on the queue now?  To be running we must be
00464             the highest priority task wanting to access the queue. */
00465             if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
00466             {
00467                 traceQUEUE_SEND( pxQueue );
00468                 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
00469 
00470                 /* If there was a task waiting for data to arrive on the
00471                 queue then unblock it now. */
00472                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
00473                 {
00474                     if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
00475                     {
00476                         /* The unblocked task has a priority higher than
00477                         our own so yield immediately.  Yes it is ok to do
00478                         this from within the critical section - the kernel
00479                         takes care of that. */
00480                         portYIELD_WITHIN_API();
00481                     }
00482                 }
00483 
00484                 taskEXIT_CRITICAL();
00485 
00486                 /* Return to the original privilege level before exiting the
00487                 function. */
00488                 return pdPASS;
00489             }
00490             else
00491             {
00492                 if( xTicksToWait == ( portTickType ) 0 )
00493                 {
00494                     /* The queue was full and no block time is specified (or
00495                     the block time has expired) so leave now. */
00496                     taskEXIT_CRITICAL();
00497 
00498                     /* Return to the original privilege level before exiting
00499                     the function. */
00500                     traceQUEUE_SEND_FAILED( pxQueue );
00501                     return errQUEUE_FULL;
00502                 }
00503                 else if( xEntryTimeSet == pdFALSE )
00504                 {
00505                     /* The queue was full and a block time was specified so
00506                     configure the timeout structure. */
00507                     vTaskSetTimeOutState( &xTimeOut );
00508                     xEntryTimeSet = pdTRUE;
00509                 }
00510             }
00511         }
00512         taskEXIT_CRITICAL();
00513 
00514         /* Interrupts and other tasks can send to and receive from the queue
00515         now the critical section has been exited. */
00516 
00517         vTaskSuspendAll();
00518         prvLockQueue( pxQueue );
00519 
00520         /* Update the timeout state to see if it has expired yet. */
00521         if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
00522         {
00523             if( prvIsQueueFull( pxQueue ) )
00524             {
00525                 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
00526                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
00527 
00528                 /* Unlocking the queue means queue events can effect the
00529                 event list.  It is possible that interrupts occurring now
00530                 remove this task from the event list again - but as the
00531                 scheduler is suspended the task will go onto the pending
00532                 ready last instead of the actual ready list. */
00533                 prvUnlockQueue( pxQueue );
00534 
00535                 /* Resuming the scheduler will move tasks from the pending
00536                 ready list into the ready list - so it is feasible that this
00537                 task is already in a ready list before it yields - in which
00538                 case the yield will not cause a context switch unless there
00539                 is also a higher priority task in the pending ready list. */
00540                 if( !xTaskResumeAll() )
00541                 {
00542                     portYIELD_WITHIN_API();
00543                 }
00544             }
00545             else
00546             {
00547                 /* Try again. */
00548                 prvUnlockQueue( pxQueue );
00549                 ( void ) xTaskResumeAll();
00550             }
00551         }
00552         else
00553         {
00554             /* The timeout has expired. */
00555             prvUnlockQueue( pxQueue );
00556             ( void ) xTaskResumeAll();
00557 
00558             /* Return to the original privilege level before exiting the
00559             function. */
00560             traceQUEUE_SEND_FAILED( pxQueue );
00561             return errQUEUE_FULL;
00562         }
00563     }
00564 }
00565 /*-----------------------------------------------------------*/

signed portBASE_TYPE xQueueGenericSendFromISR ( xQueueHandle  pxQueue,
const void *const   pvItemToQueue,
signed portBASE_TYPE *  pxHigherPriorityTaskWoken,
portBASE_TYPE  xCopyPosition 
)

Definition at line 768 of file queue.c.

References errQUEUE_FULL, listLIST_IS_EMPTY, pdFALSE, pdPASS, pdTRUE, portCLEAR_INTERRUPT_MASK_FROM_ISR, portSET_INTERRUPT_MASK_FROM_ISR, prvCopyDataToQueue(), queueUNLOCKED, traceQUEUE_SEND_FROM_ISR, traceQUEUE_SEND_FROM_ISR_FAILED, and xTaskRemoveFromEventList().

00768 {
00769 signed portBASE_TYPE xReturn;
00770 unsigned portBASE_TYPE uxSavedInterruptStatus;
00771 
00772     /* Similar to xQueueGenericSend, except we don't block if there is no room
00773     in the queue.  Also we don't directly wake a task that was blocked on a
00774     queue read, instead we return a flag to say whether a context switch is
00775     required or not (i.e. has a task with a higher priority than us been woken
00776     by this post). */
00777     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
00778     {
00779         if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
00780         {
00781             traceQUEUE_SEND_FROM_ISR( pxQueue );
00782 
00783             prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
00784 
00785             /* If the queue is locked we do not alter the event list.  This will
00786             be done when the queue is unlocked later. */
00787             if( pxQueue->xTxLock == queueUNLOCKED )
00788             {
00789                 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )
00790                 {
00791                     if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
00792                     {
00793                         /* The task waiting has a higher priority so record that a
00794                         context switch is required. */
00795                         *pxHigherPriorityTaskWoken = pdTRUE;
00796                     }
00797                 }
00798             }
00799             else
00800             {
00801                 /* Increment the lock count so the task that unlocks the queue
00802                 knows that data was posted while it was locked. */
00803                 ++( pxQueue->xTxLock );
00804             }
00805 
00806             xReturn = pdPASS;
00807         }
00808         else
00809         {
00810             traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
00811             xReturn = errQUEUE_FULL;
00812         }
00813     }
00814     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
00815 
00816     return xReturn;
00817 }
00818 /*-----------------------------------------------------------*/

portBASE_TYPE xQueueGiveMutexRecursive ( xQueueHandle  xMutex  ) 

signed portBASE_TYPE xQueueIsQueueEmptyFromISR ( const xQueueHandle  pxQueue  ) 

Definition at line 1178 of file queue.c.

01178 {
01179 signed portBASE_TYPE xReturn;
01180 
01181     xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );
01182 
01183     return xReturn;
01184 }
01185 /*-----------------------------------------------------------*/

signed portBASE_TYPE xQueueIsQueueFullFromISR ( const xQueueHandle  pxQueue  ) 

Definition at line 1200 of file queue.c.

01200 {
01201 signed portBASE_TYPE xReturn;
01202 
01203     xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );
01204 
01205     return xReturn;
01206 }
01207 /*-----------------------------------------------------------*/

signed portBASE_TYPE xQueueReceiveFromISR ( xQueueHandle  pxQueue,
void *const   pvBuffer,
signed portBASE_TYPE *  pxTaskWoken 
)

Definition at line 968 of file queue.c.

References listLIST_IS_EMPTY, pdFAIL, pdFALSE, pdPASS, pdTRUE, portCLEAR_INTERRUPT_MASK_FROM_ISR, portSET_INTERRUPT_MASK_FROM_ISR, prvCopyDataFromQueue(), queueUNLOCKED, traceQUEUE_RECEIVE_FROM_ISR, traceQUEUE_RECEIVE_FROM_ISR_FAILED, and xTaskRemoveFromEventList().

Referenced by prvUSART_ISR_NonNakedBehaviour().

00968 {
00969 signed portBASE_TYPE xReturn;
00970 unsigned portBASE_TYPE uxSavedInterruptStatus;
00971 
00972     uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
00973     {
00974         /* We cannot block from an ISR, so check there is data available. */
00975         if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
00976         {
00977             traceQUEUE_RECEIVE_FROM_ISR( pxQueue );
00978 
00979             prvCopyDataFromQueue( pxQueue, pvBuffer );
00980             --( pxQueue->uxMessagesWaiting );
00981 
00982             /* If the queue is locked we will not modify the event list.  Instead
00983             we update the lock count so the task that unlocks the queue will know
00984             that an ISR has removed data while the queue was locked. */
00985             if( pxQueue->xRxLock == queueUNLOCKED )
00986             {
00987                 if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )
00988                 {
00989                     if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
00990                     {
00991                         /* The task waiting has a higher priority than us so
00992                         force a context switch. */
00993                         *pxTaskWoken = pdTRUE;
00994                     }
00995                 }
00996             }
00997             else
00998             {
00999                 /* Increment the lock count so the task that unlocks the queue
01000                 knows that data was removed while it was locked. */
01001                 ++( pxQueue->xRxLock );
01002             }
01003 
01004             xReturn = pdPASS;
01005         }
01006         else
01007         {
01008             xReturn = pdFAIL;
01009             traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
01010         }
01011     }
01012     portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
01013 
01014     return xReturn;
01015 }
01016 /*-----------------------------------------------------------*/

portBASE_TYPE xQueueTakeMutexRecursive ( xQueueHandle  xMutex,
portTickType  xBlockTime 
)


Generated on Thu Dec 17 20:02:01 2009 for AVR32 UC3 - FreeRTOS Real Time Kernel by  doxygen 1.5.5