/*\r
- FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
+ FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
\r
+ VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
\r
***************************************************************************\r
* *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
+ * FreeRTOS provides completely free yet professionally developed, *\r
+ * robust, strictly quality controlled, supported, and cross *\r
+ * platform software that has become a de facto standard. *\r
* *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
+ * Help yourself get started quickly and support the FreeRTOS *\r
+ * project by purchasing a FreeRTOS tutorial book, reference *\r
+ * manual, or both from: http://www.FreeRTOS.org/Documentation *\r
* *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * Thank you! *\r
* *\r
***************************************************************************\r
\r
-\r
This file is part of the FreeRTOS distribution.\r
\r
FreeRTOS is free software; you can redistribute it and/or modify it under\r
the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
+ Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
+\r
+ >>! NOTE: The modification to the GPL is included to allow you to distribute\r
+ >>! a combined work that includes FreeRTOS without being obliged to provide\r
+ >>! the source code for proprietary components outside of the FreeRTOS\r
+ >>! kernel.\r
+\r
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ FOR A PARTICULAR PURPOSE. Full license text is available from the following\r
+ link: http://www.freertos.org/a00114.html\r
\r
1 tab == 4 spaces!\r
- \r
+\r
***************************************************************************\r
* *\r
* Having a problem? Start by reading the FAQ "My application does *\r
- * not run, what could be wrong? *\r
+ * not run, what could be wrong?" *\r
* *\r
* http://www.FreeRTOS.org/FAQHelp.html *\r
* *\r
***************************************************************************\r
\r
- \r
- http://www.FreeRTOS.org - Documentation, training, latest information, \r
- license and contact details.\r
- \r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
+ license and Real Time Engineers Ltd. contact details.\r
+\r
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
- including FreeRTOS+Trace - an indispensable productivity tool.\r
+ including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+ compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS\r
+ licenses offer ticketed support, indemnification and middleware.\r
\r
- Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
- the code with commercial support, indemnification, and middleware, under \r
- the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also\r
- provide a safety engineered and independently SIL3 certified version under \r
- the SafeRTOS brand: http://www.SafeRTOS.com.\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
+ mission critical applications that require provable dependability.\r
+\r
+ 1 tab == 4 spaces!\r
*/\r
\r
#include <stdlib.h>\r
\r
#include "FreeRTOS.h"\r
#include "task.h"\r
+#include "queue.h"\r
\r
#if ( configUSE_CO_ROUTINES == 1 )\r
#include "croutine.h"\r
#endif\r
\r
-#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
+/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
+MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
+header files above, but not in this file, in order to generate the correct\r
+privileged Vs unprivileged linkage and placement. */\r
+#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
\r
-/*-----------------------------------------------------------\r
- * PUBLIC LIST API documented in list.h\r
- *----------------------------------------------------------*/\r
\r
/* Constants used with the cRxLock and xTxLock structure members. */\r
#define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )\r
#define queueLOCKED_UNMODIFIED ( ( signed portBASE_TYPE ) 0 )\r
\r
-#define queueERRONEOUS_UNBLOCK ( -1 )\r
-\r
-/* For internal use only. */\r
-#define queueSEND_TO_BACK ( 0 )\r
-#define queueSEND_TO_FRONT ( 1 )\r
-\r
-/* Effectively make a union out of the xQUEUE structure. */\r
+/* When the xQUEUE structure is used to represent a base queue its pcHead and\r
+pcTail members are used as pointers into the queue storage area. When the\r
+xQUEUE structure is used to represent a mutex pcHead and pcTail pointers are\r
+not necessary, and the pcHead pointer is set to NULL to indicate that the\r
+pcTail pointer actually points to the mutex holder (if any). Map alternative\r
+names to the pcHead and pcTail structure members to ensure the readability of\r
+the code is maintained despite this dual use of two structure members. An\r
+alternative implementation would be to use a union, but use of a union is\r
+against the coding standard (although an exception to the standard has been\r
+permitted where the dual use also significantly changes the type of the\r
+structure member). */\r
#define pxMutexHolder pcTail\r
#define uxQueueType pcHead\r
-#define uxRecursiveCallCount pcReadFrom\r
#define queueQUEUE_IS_MUTEX NULL\r
\r
-/* Semaphores do not actually store or copy data, so have an items size of\r
+/* Semaphores do not actually store or copy data, so have an item size of\r
zero. */\r
#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )\r
-#define queueDONT_BLOCK ( ( portTickType ) 0U )\r
#define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0U )\r
\r
-/* These definitions *must* match those in queue.h. */\r
-#define queueQUEUE_TYPE_BASE ( 0U )\r
-#define queueQUEUE_TYPE_MUTEX ( 1U )\r
-#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U )\r
-#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U )\r
-#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( 4U )\r
\r
/*\r
* Definition of the queue used by the scheduler.\r
*/\r
typedef struct QueueDefinition\r
{\r
- signed char *pcHead; /*< Points to the beginning of the queue storage area. */\r
- signed char *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
+ signed char *pcHead; /*< Points to the beginning of the queue storage area. */\r
+ signed char *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
\r
- signed char *pcWriteTo; /*< Points to the free next place in the storage area. */\r
- signed char *pcReadFrom; /*< Points to the last place that a queued item was read from. */\r
+ signed char *pcWriteTo; /*< Points to the free next place in the storage area. */\r
+\r
+ union /* Use of a union is an exception to the coding standard to ensure two mutually exclusive structure members don't appear simultaneously (wasting RAM). */\r
+ {\r
+ signed char *pcReadFrom; /*< Points to the last place that a queued item was read from when the structure is used as a queue. */\r
+ unsigned portBASE_TYPE uxRecursiveCallCount;/*< Maintains a count of the numebr of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */\r
+ } u;\r
\r
xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */\r
xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */\r
\r
volatile 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
volatile 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
- \r
+\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
unsigned char ucQueueNumber;\r
unsigned char ucQueueType;\r
#endif\r
\r
+ #if ( configUSE_QUEUE_SETS == 1 )\r
+ struct QueueDefinition *pxQueueSetContainer;\r
+ #endif\r
+\r
} xQUEUE;\r
/*-----------------------------------------------------------*/\r
\r
-/*\r
- * Inside this file xQueueHandle is a pointer to a xQUEUE structure.\r
- * To keep the definition private the API header file defines it as a\r
- * pointer to void.\r
- */\r
-typedef xQUEUE * xQueueHandle;\r
-\r
-/*\r
- * Prototypes for public functions are included here so we don't have to\r
- * include the API header file (as it defines xQueueHandle differently). These\r
- * functions are documented in the API header file.\r
- */\r
-xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
-unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;\r
-xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION;\r
-xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
-unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;\r
-unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
-portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION;\r
-xTaskHandle xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION;\r
-\r
-/*\r
- * Co-routine queue functions differ from task queue functions. Co-routines are\r
- * an optional component.\r
- */\r
-#if configUSE_CO_ROUTINES == 1\r
- signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ) PRIVILEGED_FUNCTION;\r
- signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION;\r
- signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
- signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
-#endif\r
-\r
/*\r
* The queue registry is just a means for kernel aware debuggers to locate\r
* queue structures. It has no other purpose so is an optional component.\r
*/\r
-#if configQUEUE_REGISTRY_SIZE > 0\r
+#if ( configQUEUE_REGISTRY_SIZE > 0 )\r
\r
/* The type stored within the queue registry array. This allows a name\r
to be assigned to each queue making kernel aware debugging a little\r
array position being vacant. */\r
xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];\r
\r
- /* Removes a queue from the registry by simply setting the pcQueueName\r
- member to NULL. */\r
- static void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
- void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName ) PRIVILEGED_FUNCTION;\r
-#endif\r
+#endif /* configQUEUE_REGISTRY_SIZE */\r
\r
/*\r
* Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not\r
* to indicate that a task may require unblocking. When the queue in unlocked\r
* these lock counts are inspected, and the appropriate action taken.\r
*/\r
-static void prvUnlockQueue( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+static void prvUnlockQueue( xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Uses a critical section to determine if there is any data in a queue.\r
*\r
* @return pdTRUE if the queue contains no items, otherwise pdFALSE.\r
*/\r
-static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Uses a critical section to determine if there is any space in a queue.\r
*\r
* @return pdTRUE if there is no space, otherwise pdFALSE;\r
*/\r
-static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
\r
/*\r
* Copies an item into the queue, either at the front of the queue or the\r
/*\r
* Copies an item out of a queue.\r
*/\r
-static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) PRIVILEGED_FUNCTION;\r
+static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION;\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+ /*\r
+ * Checks to see if a queue is a member of a queue set, and if so, notifies\r
+ * the queue set that the queue contains data.\r
+ */\r
+ static portBASE_TYPE prvNotifyQueueSetContainer( const xQUEUE * const pxQueue, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
+#endif\r
+\r
/*-----------------------------------------------------------*/\r
\r
/*\r
taskEXIT_CRITICAL()\r
/*-----------------------------------------------------------*/\r
\r
-\r
-/*-----------------------------------------------------------\r
- * PUBLIC QUEUE MANAGEMENT API documented in queue.h\r
- *----------------------------------------------------------*/\r
-\r
-portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue )\r
+portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )\r
{\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
+\r
configASSERT( pxQueue );\r
\r
taskENTER_CRITICAL();\r
pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );\r
pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
pxQueue->pcWriteTo = pxQueue->pcHead;\r
- pxQueue->pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );\r
+ pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );\r
pxQueue->xRxLock = queueUNLOCKED;\r
pxQueue->xTxLock = queueUNLOCKED;\r
\r
if( xNewQueue == pdFALSE )\r
{\r
- /* If there are tasks blocked waiting to read from the queue, then \r
- the tasks will remain blocked as after this function exits the queue \r
- will still be empty. If there are tasks blocked waiting to write to \r
- the queue, then one should be unblocked as after this function exits \r
+ /* If there are tasks blocked waiting to read from the queue, then\r
+ the tasks will remain blocked as after this function exits the queue\r
+ will still be empty. If there are tasks blocked waiting to write to\r
+ the queue, then one should be unblocked as after this function exits\r
it will be possible to write to it. */\r
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
{\r
{\r
/* Ensure the event queues start in the correct state. */\r
vListInitialise( &( pxQueue->xTasksWaitingToSend ) );\r
- vListInitialise( &( pxQueue->xTasksWaitingToReceive ) ); \r
+ vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );\r
}\r
}\r
taskEXIT_CRITICAL();\r
{\r
/* Create the list of pointers to queue items. The queue is one byte\r
longer than asked for to make wrap checking easier/faster. */\r
- xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;\r
+ xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
\r
pxNewQueue->pcHead = ( signed char * ) pvPortMalloc( xQueueSizeInBytes );\r
if( pxNewQueue->pcHead != NULL )\r
queue type is defined. */\r
pxNewQueue->uxLength = uxQueueLength;\r
pxNewQueue->uxItemSize = uxItemSize;\r
- xQueueGenericReset( pxNewQueue, pdTRUE );\r
+ ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\r
+\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
{\r
pxNewQueue->ucQueueType = ucQueueType;\r
}\r
#endif /* configUSE_TRACE_FACILITY */\r
\r
+ #if( configUSE_QUEUE_SETS == 1 )\r
+ {\r
+ pxNewQueue->pxQueueSetContainer = NULL;\r
+ }\r
+ #endif /* configUSE_QUEUE_SETS */\r
+\r
traceQUEUE_CREATE( pxNewQueue );\r
xReturn = pxNewQueue;\r
}\r
/* Queues used as a mutex no data is actually copied into or out\r
of the queue. */\r
pxNewQueue->pcWriteTo = NULL;\r
- pxNewQueue->pcReadFrom = NULL;\r
+ pxNewQueue->u.pcReadFrom = NULL;\r
\r
/* Each mutex has a length of 1 (like a binary semaphore) and\r
an item size of 0 as nothing is actually copied into or out\r
}\r
#endif\r
\r
+ #if ( configUSE_QUEUE_SETS == 1 )\r
+ {\r
+ pxNewQueue->pxQueueSetContainer = NULL;\r
+ }\r
+ #endif\r
+\r
/* Ensure the event queues start with the correct state. */\r
vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );\r
vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );\r
traceCREATE_MUTEX( pxNewQueue );\r
\r
/* Start with the semaphore in the expected state. */\r
- xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );\r
+ ( void ) xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );\r
}\r
else\r
{\r
#endif /* configUSE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
-#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xQueueGetMutexHolder == 1 ) )\r
+#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\r
\r
void* xQueueGetMutexHolder( xQueueHandle xSemaphore )\r
{\r
/* This function is called by xSemaphoreGetMutexHolder(), and should not\r
be called directly. Note: This is is a good way of determining if the\r
calling task is the mutex holder, but not a good way of determining the\r
- identity of the mutex holder, as the holder may change between the \r
+ identity of the mutex holder, as the holder may change between the\r
following critical section exiting and the function returning. */\r
taskENTER_CRITICAL();\r
{\r
- if( xSemaphore->uxQueueType == queueQUEUE_IS_MUTEX )\r
+ if( ( ( xQUEUE * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\r
{\r
- pxReturn = ( void * ) xSemaphore->pxMutexHolder;\r
+ pxReturn = ( void * ) ( ( xQUEUE * ) xSemaphore )->pxMutexHolder;\r
}\r
else\r
{\r
}\r
}\r
taskEXIT_CRITICAL();\r
- \r
+\r
return pxReturn;\r
}\r
\r
\r
#if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
\r
- portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex )\r
+ portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )\r
{\r
portBASE_TYPE xReturn;\r
+ xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
\r
configASSERT( pxMutex );\r
\r
this is the only condition we are interested in it does not matter if\r
pxMutexHolder is accessed simultaneously by another task. Therefore no\r
mutual exclusion is required to test the pxMutexHolder variable. */\r
- if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )\r
+ if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Not a redundant cast as xTaskHandle is a typedef. */\r
{\r
traceGIVE_MUTEX_RECURSIVE( pxMutex );\r
\r
uxRecursiveCallCount is only modified by the mutex holder, and as\r
there can only be one, no mutual exclusion is required to modify the\r
uxRecursiveCallCount member. */\r
- ( pxMutex->uxRecursiveCallCount )--;\r
+ ( pxMutex->u.uxRecursiveCallCount )--;\r
\r
/* Have we unwound the call count? */\r
- if( pxMutex->uxRecursiveCallCount == 0 )\r
+ if( pxMutex->u.uxRecursiveCallCount == ( unsigned portBASE_TYPE ) 0 )\r
{\r
/* Return the mutex. This will automatically unblock any other\r
task that might be waiting to access the mutex. */\r
- xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );\r
+ ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );\r
}\r
\r
xReturn = pdPASS;\r
#endif /* configUSE_RECURSIVE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_RECURSIVE_MUTEXES == 1\r
+#if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
\r
- portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime )\r
+ portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime )\r
{\r
portBASE_TYPE xReturn;\r
+ xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
\r
configASSERT( pxMutex );\r
\r
\r
traceTAKE_MUTEX_RECURSIVE( pxMutex );\r
\r
- if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )\r
+ if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */\r
{\r
- ( pxMutex->uxRecursiveCallCount )++;\r
+ ( pxMutex->u.uxRecursiveCallCount )++;\r
xReturn = pdPASS;\r
}\r
else\r
we may have blocked to reach here. */\r
if( xReturn == pdPASS )\r
{\r
- ( pxMutex->uxRecursiveCallCount )++;\r
+ ( pxMutex->u.uxRecursiveCallCount )++;\r
}\r
else\r
{\r
#endif /* configUSE_RECURSIVE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_COUNTING_SEMAPHORES == 1\r
+#if ( configUSE_COUNTING_SEMAPHORES == 1 )\r
\r
xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )\r
{\r
- xQueueHandle pxHandle;\r
+ xQueueHandle xHandle;\r
\r
- pxHandle = xQueueGenericCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
+ xHandle = xQueueGenericCreate( uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
\r
- if( pxHandle != NULL )\r
+ if( xHandle != NULL )\r
{\r
- pxHandle->uxMessagesWaiting = uxInitialCount;\r
+ ( ( xQUEUE * ) xHandle )->uxMessagesWaiting = uxInitialCount;\r
\r
traceCREATE_COUNTING_SEMAPHORE();\r
}\r
traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
}\r
\r
- configASSERT( pxHandle );\r
- return pxHandle;\r
+ configASSERT( xHandle );\r
+ return xHandle;\r
}\r
\r
#endif /* configUSE_COUNTING_SEMAPHORES */\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
+signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
{\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+ configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
\r
/* This function relaxes the coding standard somewhat to allow return\r
statements within the function itself. This is done in the interest\r
{\r
taskENTER_CRITICAL();\r
{\r
- /* Is there room on the queue now? To be running we must be\r
- the highest priority task wanting to access the queue. */\r
- if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+ /* Is there room on the queue now? The running task must be\r
+ the highest priority task wanting to access the queue. If\r
+ the head item in the queue is to be overwritten then it does\r
+ not matter if the queue is full. */\r
+ if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
{\r
traceQUEUE_SEND( pxQueue );\r
prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
\r
- /* If there was a task waiting for data to arrive on the\r
- queue then unblock it now. */\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ #if ( configUSE_QUEUE_SETS == 1 )\r
{\r
- if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
+ if( pxQueue->pxQueueSetContainer != NULL )\r
{\r
- /* The unblocked task has a priority higher than\r
- our own so yield immediately. Yes it is ok to do\r
- this from within the critical section - the kernel\r
- takes care of that. */\r
- portYIELD_WITHIN_API();\r
+ if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
+ {\r
+ /* The queue is a member of a queue set, and posting\r
+ to the queue set caused a higher priority task to\r
+ unblock. A context switch is required. */\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* If there was a task waiting for data to arrive on the\r
+ queue then unblock it now. */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
+ {\r
+ /* The unblocked task has a priority higher than\r
+ our own so yield immediately. Yes it is ok to\r
+ do this from within the critical section - the\r
+ kernel takes care of that. */\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ }\r
}\r
}\r
+ #else /* configUSE_QUEUE_SETS */\r
+ {\r
+ /* If there was a task waiting for data to arrive on the\r
+ queue then unblock it now. */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
+ {\r
+ /* The unblocked task has a priority higher than\r
+ our own so yield immediately. Yes it is ok to do\r
+ this from within the critical section - the kernel\r
+ takes care of that. */\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ }\r
+ }\r
+ #endif /* configUSE_QUEUE_SETS */\r
\r
taskEXIT_CRITICAL();\r
\r
vTaskSetTimeOutState( &xTimeOut );\r
xEntryTimeSet = pdTRUE;\r
}\r
+ else\r
+ {\r
+ /* Entry time was already set. */ \r
+ }\r
}\r
}\r
taskEXIT_CRITICAL();\r
}\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_ALTERNATIVE_API == 1\r
+#if ( configUSE_ALTERNATIVE_API == 1 )\r
\r
- signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
+ signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
{\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
#endif /* configUSE_ALTERNATIVE_API */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_ALTERNATIVE_API == 1\r
+#if ( configUSE_ALTERNATIVE_API == 1 )\r
\r
- signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
+ signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
{\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
signed char *pcOriginalReadPosition;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
{\r
/* Remember our read position in case we are just peeking. */\r
- pcOriginalReadPosition = pxQueue->pcReadFrom;\r
+ pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
\r
prvCopyDataFromQueue( pxQueue, pvBuffer );\r
\r
{\r
traceQUEUE_RECEIVE( pxQueue );\r
\r
- /* We are actually removing data. */\r
+ /* Data is actually being removed (not just peeked). */\r
--( pxQueue->uxMessagesWaiting );\r
\r
#if ( configUSE_MUTEXES == 1 )\r
{\r
/* Record the information required to implement\r
priority inheritance should it become necessary. */\r
- pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();\r
+ pxQueue->pxMutexHolder = ( signed char * ) xTaskGetCurrentTaskHandle();\r
}\r
}\r
#endif\r
\r
/* We are not removing the data, so reset our read\r
pointer. */\r
- pxQueue->pcReadFrom = pcOriginalReadPosition;\r
+ pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
\r
/* The data is being left in the queue, so see if there are\r
any other tasks waiting for the data. */\r
if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
{\r
portENTER_CRITICAL();\r
+ {\r
vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
+ }\r
portEXIT_CRITICAL();\r
}\r
}\r
#endif /* configUSE_ALTERNATIVE_API */\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )\r
+signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )\r
{\r
signed portBASE_TYPE xReturn;\r
unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+ configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
+\r
+ /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+ system call (or maximum API call) interrupt priority. Interrupts that are\r
+ above the maximum system call priority are keep permanently enabled, even\r
+ when the RTOS kernel is in a critical section, but cannot make any calls to\r
+ FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h\r
+ then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has been\r
+ assigned a priority above the configured maximum system call priority.\r
+ Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+ that have been assigned a priority at or (logically) below the maximum\r
+ system call interrupt priority. FreeRTOS maintains a separate interrupt\r
+ safe API to ensure interrupt entry is as fast and as simple as possible.\r
+ More information (albeit Cortex-M specific) is provided on the following\r
+ link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
\r
/* Similar to xQueueGenericSend, except we don't block if there is no room\r
in the queue. Also we don't directly wake a task that was blocked on a\r
by this post). */\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+ if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
{\r
traceQUEUE_SEND_FROM_ISR( pxQueue );\r
\r
be done when the queue is unlocked later. */\r
if( pxQueue->xTxLock == queueUNLOCKED )\r
{\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ #if ( configUSE_QUEUE_SETS == 1 )\r
{\r
- if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ if( pxQueue->pxQueueSetContainer != NULL )\r
{\r
- /* The task waiting has a higher priority so record that a\r
- context switch is required. */\r
- if( pxHigherPriorityTaskWoken != NULL )\r
+ if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
{\r
- *pxHigherPriorityTaskWoken = pdTRUE;\r
+ /* The queue is a member of a queue set, and posting\r
+ to the queue set caused a higher priority task to\r
+ unblock. A context switch is required. */\r
+ if( pxHigherPriorityTaskWoken != NULL )\r
+ {\r
+ *pxHigherPriorityTaskWoken = pdTRUE;\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The task waiting has a higher priority so record that a\r
+ context switch is required. */\r
+ if( pxHigherPriorityTaskWoken != NULL )\r
+ {\r
+ *pxHigherPriorityTaskWoken = pdTRUE;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ #else /* configUSE_QUEUE_SETS */\r
+ {\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The task waiting has a higher priority so record that a\r
+ context switch is required. */\r
+ if( pxHigherPriorityTaskWoken != NULL )\r
+ {\r
+ *pxHigherPriorityTaskWoken = pdTRUE;\r
+ }\r
}\r
}\r
}\r
+ #endif /* configUSE_QUEUE_SETS */\r
}\r
else\r
{\r
}\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
+signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
{\r
signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
xTimeOutType xTimeOut;\r
signed char *pcOriginalReadPosition;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
the highest priority task wanting to access the queue. */\r
if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
{\r
- /* Remember our read position in case we are just peeking. */\r
- pcOriginalReadPosition = pxQueue->pcReadFrom;\r
+ /* Remember the read position in case the queue is only being\r
+ peeked. */\r
+ pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
\r
prvCopyDataFromQueue( pxQueue, pvBuffer );\r
\r
{\r
traceQUEUE_RECEIVE( pxQueue );\r
\r
- /* We are actually removing data. */\r
+ /* Actually removing data, not just peeking. */\r
--( pxQueue->uxMessagesWaiting );\r
\r
#if ( configUSE_MUTEXES == 1 )\r
{\r
/* Record the information required to implement\r
priority inheritance should it become necessary. */\r
- pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();\r
+ pxQueue->pxMutexHolder = ( signed char * ) xTaskGetCurrentTaskHandle(); /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */\r
}\r
}\r
#endif\r
{\r
traceQUEUE_PEEK( pxQueue );\r
\r
- /* We are not removing the data, so reset our read\r
+ /* The data is not being removed, so reset the read\r
pointer. */\r
- pxQueue->pcReadFrom = pcOriginalReadPosition;\r
+ pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
\r
/* The data is being left in the queue, so see if there are\r
any other tasks waiting for the data. */\r
vTaskSetTimeOutState( &xTimeOut );\r
xEntryTimeSet = pdTRUE;\r
}\r
+ else\r
+ {\r
+ /* Entry time was already set. */\r
+ }\r
}\r
}\r
taskEXIT_CRITICAL();\r
}\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
+signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
{\r
signed portBASE_TYPE xReturn;\r
unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
\r
+ /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+ system call (or maximum API call) interrupt priority. Interrupts that are\r
+ above the maximum system call priority are keep permanently enabled, even \r
+ when the RTOS kernel is in a critical section, but cannot make any calls to\r
+ FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h \r
+ then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has been\r
+ assigned a priority above the configured maximum system call priority.\r
+ Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+ that have been assigned a priority at or (logically) below the maximum \r
+ system call interrupt priority. FreeRTOS maintains a separate interrupt \r
+ safe API to ensure interrupt entry is as fast and as simple as possible. \r
+ More information (albeit Cortex-M specific) is provided on the following \r
+ link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
- /* We cannot block from an ISR, so check there is data available. */\r
+ /* Cannot block in an ISR, so check there is data available. */\r
if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
{\r
traceQUEUE_RECEIVE_FROM_ISR( pxQueue );\r
prvCopyDataFromQueue( pxQueue, pvBuffer );\r
--( pxQueue->uxMessagesWaiting );\r
\r
- /* If the queue is locked we will not modify the event list. Instead\r
- we update the lock count so the task that unlocks the queue will know\r
- that an ISR has removed data while the queue was locked. */\r
+ /* If the queue is locked the event list will not be modified.\r
+ Instead update the lock count so the task that unlocks the queue\r
+ will know that an ISR has removed data while the queue was\r
+ locked. */\r
if( pxQueue->xRxLock == queueUNLOCKED )\r
{\r
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
}\r
/*-----------------------------------------------------------*/\r
\r
-unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue )\r
+signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer )\r
{\r
-unsigned portBASE_TYPE uxReturn;\r
+signed portBASE_TYPE xReturn;\r
+unsigned portBASE_TYPE uxSavedInterruptStatus;\r
+signed char *pcOriginalReadPosition;\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
configASSERT( pxQueue );\r
+ configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
+ /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+ system call (or maximum API call) interrupt priority. Interrupts that are\r
+ above the maximum system call priority are keep permanently enabled, even \r
+ when the RTOS kernel is in a critical section, but cannot make any calls to\r
+ FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h \r
+ then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+ failure if a FreeRTOS API function is called from an interrupt that has been\r
+ assigned a priority above the configured maximum system call priority.\r
+ Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+ that have been assigned a priority at or (logically) below the maximum \r
+ system call interrupt priority. FreeRTOS maintains a separate interrupt \r
+ safe API to ensure interrupt entry is as fast and as simple as possible. \r
+ More information (albeit Cortex-M specific) is provided on the following \r
+ link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+ portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ {\r
+ /* Cannot block in an ISR, so check there is data available. */\r
+ if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ traceQUEUE_PEEK_FROM_ISR( pxQueue );\r
+\r
+ /* Remember the read position so it can be reset as nothing is\r
+ actually being removed from the queue. */\r
+ pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
+ prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+ pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
+\r
+ xReturn = pdPASS;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
+ traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );\r
+ }\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue )\r
+{\r
+unsigned portBASE_TYPE uxReturn;\r
+\r
+ configASSERT( xQueue );\r
\r
taskENTER_CRITICAL();\r
- uxReturn = pxQueue->uxMessagesWaiting;\r
+ uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;\r
taskEXIT_CRITICAL();\r
\r
return uxReturn;\r
-}\r
+} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
/*-----------------------------------------------------------*/\r
\r
-unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue )\r
+unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue )\r
{\r
unsigned portBASE_TYPE uxReturn;\r
\r
- configASSERT( pxQueue );\r
+ configASSERT( xQueue );\r
\r
- uxReturn = pxQueue->uxMessagesWaiting;\r
+ uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;\r
\r
return uxReturn;\r
-}\r
+} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
/*-----------------------------------------------------------*/\r
\r
-void vQueueDelete( xQueueHandle pxQueue )\r
+void vQueueDelete( xQueueHandle xQueue )\r
{\r
+xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
+\r
configASSERT( pxQueue );\r
\r
traceQUEUE_DELETE( pxQueue );\r
- vQueueUnregisterQueue( pxQueue );\r
+ #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
+ {\r
+ vQueueUnregisterQueue( pxQueue );\r
+ }\r
+ #endif\r
vPortFree( pxQueue->pcHead );\r
vPortFree( pxQueue );\r
}\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue )\r
+ unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue )\r
{\r
- return pxQueue->ucQueueNumber;\r
+ return ( ( xQUEUE * ) xQueue )->ucQueueNumber;\r
}\r
\r
-#endif\r
+#endif /* configUSE_TRACE_FACILITY */\r
/*-----------------------------------------------------------*/\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber )\r
+ void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber )\r
{\r
- pxQueue->ucQueueNumber = ucQueueNumber;\r
+ ( ( xQUEUE * ) xQueue )->ucQueueNumber = ucQueueNumber;\r
}\r
\r
-#endif\r
+#endif /* configUSE_TRACE_FACILITY */\r
/*-----------------------------------------------------------*/\r
\r
#if ( configUSE_TRACE_FACILITY == 1 )\r
\r
- unsigned char ucQueueGetQueueType( xQueueHandle pxQueue )\r
+ unsigned char ucQueueGetQueueType( xQueueHandle xQueue )\r
{\r
- return pxQueue->ucQueueType;\r
+ return ( ( xQUEUE * ) xQueue )->ucQueueType;\r
}\r
\r
-#endif\r
+#endif /* configUSE_TRACE_FACILITY */\r
/*-----------------------------------------------------------*/\r
\r
static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )\r
pxQueue->pxMutexHolder = NULL;\r
}\r
}\r
- #endif\r
+ #endif /* configUSE_MUTEXES */\r
}\r
else if( xPosition == queueSEND_TO_BACK )\r
{\r
- memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );\r
+ ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. */\r
pxQueue->pcWriteTo += pxQueue->uxItemSize;\r
- if( pxQueue->pcWriteTo >= pxQueue->pcTail )\r
+ if( pxQueue->pcWriteTo >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
{\r
pxQueue->pcWriteTo = pxQueue->pcHead;\r
}\r
}\r
else\r
{\r
- memcpy( ( void * ) pxQueue->pcReadFrom, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );\r
- pxQueue->pcReadFrom -= pxQueue->uxItemSize;\r
- if( pxQueue->pcReadFrom < pxQueue->pcHead )\r
+ ( void ) memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+ pxQueue->u.pcReadFrom -= pxQueue->uxItemSize;\r
+ if( pxQueue->u.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
+ {\r
+ pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
+ }\r
+\r
+ if( xPosition == queueOVERWRITE )\r
{\r
- pxQueue->pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
+ if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ /* An item is not being added but overwritten, so subtract\r
+ one from the recorded number of items in the queue so when\r
+ one is added again below the number of recorded items remains\r
+ correct. */\r
+ --( pxQueue->uxMessagesWaiting );\r
+ }\r
}\r
}\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )\r
+static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer )\r
{\r
if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )\r
{\r
- pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
- if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
+ pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
+ if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */\r
{\r
- pxQueue->pcReadFrom = pxQueue->pcHead;\r
+ pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
}\r
- memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+ ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. */\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvUnlockQueue( xQueueHandle pxQueue )\r
+static void prvUnlockQueue( xQUEUE *pxQueue )\r
{\r
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */\r
\r
{\r
/* Data was posted while the queue was locked. Are any tasks\r
blocked waiting for data to become available? */\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ #if ( configUSE_QUEUE_SETS == 1 )\r
{\r
- /* Tasks that are removed from the event list will get added to\r
- the pending ready list as the scheduler is still suspended. */\r
- if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ if( pxQueue->pxQueueSetContainer != NULL )\r
{\r
- /* The task waiting has a higher priority so record that a\r
- context switch is required. */\r
- vTaskMissedYield();\r
+ if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE )\r
+ {\r
+ /* The queue is a member of a queue set, and posting to\r
+ the queue set caused a higher priority task to unblock.\r
+ A context switch is required. */\r
+ vTaskMissedYield();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Tasks that are removed from the event list will get added to\r
+ the pending ready list as the scheduler is still suspended. */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The task waiting has a higher priority so record that a\r
+ context switch is required. */\r
+ vTaskMissedYield();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ break;\r
+ }\r
}\r
-\r
- --( pxQueue->xTxLock );\r
}\r
- else\r
+ #else /* configUSE_QUEUE_SETS */\r
{\r
- break;\r
+ /* Tasks that are removed from the event list will get added to\r
+ the pending ready list as the scheduler is still suspended. */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The task waiting has a higher priority so record that a\r
+ context switch is required. */\r
+ vTaskMissedYield();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ break;\r
+ }\r
}\r
+ #endif /* configUSE_QUEUE_SETS */\r
+\r
+ --( pxQueue->xTxLock );\r
}\r
\r
pxQueue->xTxLock = queueUNLOCKED;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue )\r
+static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue )\r
{\r
signed portBASE_TYPE xReturn;\r
\r
taskENTER_CRITICAL();\r
- xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
+ {\r
+ if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFALSE;\r
+ }\r
+ }\r
taskEXIT_CRITICAL();\r
\r
return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue )\r
+signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue )\r
{\r
signed portBASE_TYPE xReturn;\r
\r
- configASSERT( pxQueue );\r
- xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
+ configASSERT( xQueue );\r
+ if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFALSE;\r
+ }\r
\r
return xReturn;\r
-}\r
+} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\r
/*-----------------------------------------------------------*/\r
\r
-static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue )\r
+static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue )\r
{\r
signed portBASE_TYPE xReturn;\r
\r
taskENTER_CRITICAL();\r
- xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
+ {\r
+ if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )\r
+ {\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFALSE;\r
+ }\r
+ }\r
taskEXIT_CRITICAL();\r
\r
return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue )\r
+signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue )\r
{\r
signed portBASE_TYPE xReturn;\r
\r
- configASSERT( pxQueue );\r
- xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
+ configASSERT( xQueue );\r
+ if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( ( xQUEUE * ) xQueue )->uxLength )\r
+ {\r
+ xReturn = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFALSE;\r
+ }\r
\r
return xReturn;\r
-}\r
+} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_CO_ROUTINES == 1\r
-signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
-{\r
-signed portBASE_TYPE xReturn;\r
+#if ( configUSE_CO_ROUTINES == 1 )\r
\r
- /* If the queue is already full we may have to block. A critical section\r
- is required to prevent an interrupt removing something from the queue\r
- between the check to see if the queue is full and blocking on the queue. */\r
- portDISABLE_INTERRUPTS();\r
+ signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
{\r
- if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
+ signed portBASE_TYPE xReturn;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
+\r
+ /* If the queue is already full we may have to block. A critical section\r
+ is required to prevent an interrupt removing something from the queue\r
+ between the check to see if the queue is full and blocking on the queue. */\r
+ portDISABLE_INTERRUPTS();\r
{\r
- /* The queue is full - do we want to block or just leave without\r
- posting? */\r
- if( xTicksToWait > ( portTickType ) 0 )\r
- {\r
- /* As this is called from a coroutine we cannot block directly, but\r
- return indicating that we need to block. */\r
- vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );\r
- portENABLE_INTERRUPTS();\r
- return errQUEUE_BLOCKED;\r
- }\r
- else\r
+ if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
{\r
- portENABLE_INTERRUPTS();\r
- return errQUEUE_FULL;\r
+ /* The queue is full - do we want to block or just leave without\r
+ posting? */\r
+ if( xTicksToWait > ( portTickType ) 0 )\r
+ {\r
+ /* As this is called from a coroutine we cannot block directly, but\r
+ return indicating that we need to block. */\r
+ vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );\r
+ portENABLE_INTERRUPTS();\r
+ return errQUEUE_BLOCKED;\r
+ }\r
+ else\r
+ {\r
+ portENABLE_INTERRUPTS();\r
+ return errQUEUE_FULL;\r
+ }\r
}\r
}\r
- }\r
- portENABLE_INTERRUPTS();\r
-\r
- portNOP();\r
+ portENABLE_INTERRUPTS();\r
\r
- portDISABLE_INTERRUPTS();\r
- {\r
- if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+ portDISABLE_INTERRUPTS();\r
{\r
- /* There is room in the queue, copy the data into the queue. */\r
- prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
- xReturn = pdPASS;\r
-\r
- /* Were any co-routines waiting for data to become available? */\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
{\r
- /* In this instance the co-routine could be placed directly\r
- into the ready list as we are within a critical section.\r
- Instead the same pending ready list mechanism is used as if\r
- the event were caused from within an interrupt. */\r
- if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ /* There is room in the queue, copy the data into the queue. */\r
+ prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
+ xReturn = pdPASS;\r
+\r
+ /* Were any co-routines waiting for data to become available? */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
{\r
- /* The co-routine waiting has a higher priority so record\r
- that a yield might be appropriate. */\r
- xReturn = errQUEUE_YIELD;\r
+ /* In this instance the co-routine could be placed directly\r
+ into the ready list as we are within a critical section.\r
+ Instead the same pending ready list mechanism is used as if\r
+ the event were caused from within an interrupt. */\r
+ if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The co-routine waiting has a higher priority so record\r
+ that a yield might be appropriate. */\r
+ xReturn = errQUEUE_YIELD;\r
+ }\r
}\r
}\r
+ else\r
+ {\r
+ xReturn = errQUEUE_FULL;\r
+ }\r
}\r
- else\r
- {\r
- xReturn = errQUEUE_FULL;\r
- }\r
+ portENABLE_INTERRUPTS();\r
+\r
+ return xReturn;\r
}\r
- portENABLE_INTERRUPTS();\r
\r
- return xReturn;\r
-}\r
-#endif\r
+#endif /* configUSE_CO_ROUTINES */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_CO_ROUTINES == 1\r
-signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )\r
-{\r
-signed portBASE_TYPE xReturn;\r
+#if ( configUSE_CO_ROUTINES == 1 )\r
\r
- /* If the queue is already empty we may have to block. A critical section\r
- is required to prevent an interrupt adding something to the queue\r
- between the check to see if the queue is empty and blocking on the queue. */\r
- portDISABLE_INTERRUPTS();\r
+ signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )\r
{\r
- if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
+ signed portBASE_TYPE xReturn;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
+\r
+ /* If the queue is already empty we may have to block. A critical section\r
+ is required to prevent an interrupt adding something to the queue\r
+ between the check to see if the queue is empty and blocking on the queue. */\r
+ portDISABLE_INTERRUPTS();\r
{\r
- /* There are no messages in the queue, do we want to block or just\r
- leave with nothing? */\r
- if( xTicksToWait > ( portTickType ) 0 )\r
- {\r
- /* As this is a co-routine we cannot block directly, but return\r
- indicating that we need to block. */\r
- vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );\r
- portENABLE_INTERRUPTS();\r
- return errQUEUE_BLOCKED;\r
- }\r
- else\r
+ if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
{\r
- portENABLE_INTERRUPTS();\r
- return errQUEUE_FULL;\r
+ /* There are no messages in the queue, do we want to block or just\r
+ leave with nothing? */\r
+ if( xTicksToWait > ( portTickType ) 0 )\r
+ {\r
+ /* As this is a co-routine we cannot block directly, but return\r
+ indicating that we need to block. */\r
+ vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );\r
+ portENABLE_INTERRUPTS();\r
+ return errQUEUE_BLOCKED;\r
+ }\r
+ else\r
+ {\r
+ portENABLE_INTERRUPTS();\r
+ return errQUEUE_FULL;\r
+ }\r
}\r
}\r
- }\r
- portENABLE_INTERRUPTS();\r
-\r
- portNOP();\r
+ portENABLE_INTERRUPTS();\r
\r
- portDISABLE_INTERRUPTS();\r
- {\r
- if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
+ portDISABLE_INTERRUPTS();\r
{\r
- /* Data is available from the queue. */\r
- pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
- if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
+ if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
{\r
- pxQueue->pcReadFrom = pxQueue->pcHead;\r
- }\r
- --( pxQueue->uxMessagesWaiting );\r
- memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+ /* Data is available from the queue. */\r
+ pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
+ if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
+ {\r
+ pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
+ }\r
+ --( pxQueue->uxMessagesWaiting );\r
+ ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
\r
- xReturn = pdPASS;\r
+ xReturn = pdPASS;\r
\r
- /* Were any co-routines waiting for space to become available? */\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
- {\r
- /* In this instance the co-routine could be placed directly\r
- into the ready list as we are within a critical section.\r
- Instead the same pending ready list mechanism is used as if\r
- the event were caused from within an interrupt. */\r
- if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+ /* Were any co-routines waiting for space to become available? */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
{\r
- xReturn = errQUEUE_YIELD;\r
+ /* In this instance the co-routine could be placed directly\r
+ into the ready list as we are within a critical section.\r
+ Instead the same pending ready list mechanism is used as if\r
+ the event were caused from within an interrupt. */\r
+ if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+ {\r
+ xReturn = errQUEUE_YIELD;\r
+ }\r
}\r
}\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
}\r
- else\r
- {\r
- xReturn = pdFAIL;\r
- }\r
+ portENABLE_INTERRUPTS();\r
+\r
+ return xReturn;\r
}\r
- portENABLE_INTERRUPTS();\r
\r
- return xReturn;\r
-}\r
-#endif\r
+#endif /* configUSE_CO_ROUTINES */\r
/*-----------------------------------------------------------*/\r
\r
+#if ( configUSE_CO_ROUTINES == 1 )\r
\r
-\r
-#if configUSE_CO_ROUTINES == 1\r
-signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
-{\r
- /* Cannot block within an ISR so if there is no space on the queue then\r
- exit without doing anything. */\r
- if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+ signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
{\r
- prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- /* We only want to wake one co-routine per ISR, so check that a\r
- co-routine has not already been woken. */\r
- if( xCoRoutinePreviouslyWoken == pdFALSE )\r
+ /* Cannot block within an ISR so if there is no space on the queue then\r
+ exit without doing anything. */\r
+ if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
{\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
+\r
+ /* We only want to wake one co-routine per ISR, so check that a\r
+ co-routine has not already been woken. */\r
+ if( xCoRoutinePreviouslyWoken == pdFALSE )\r
{\r
- if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
{\r
- return pdTRUE;\r
+ if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ return pdTRUE;\r
+ }\r
}\r
}\r
}\r
+\r
+ return xCoRoutinePreviouslyWoken;\r
}\r
\r
- return xCoRoutinePreviouslyWoken;\r
-}\r
-#endif\r
+#endif /* configUSE_CO_ROUTINES */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_CO_ROUTINES == 1\r
-signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
-{\r
-signed portBASE_TYPE xReturn;\r
+#if ( configUSE_CO_ROUTINES == 1 )\r
\r
- /* We cannot block from an ISR, so check there is data available. If\r
- not then just leave without doing anything. */\r
- if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
+ signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
{\r
- /* Copy the data from the queue. */\r
- pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
- if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
- {\r
- pxQueue->pcReadFrom = pxQueue->pcHead;\r
- }\r
- --( pxQueue->uxMessagesWaiting );\r
- memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+ signed portBASE_TYPE xReturn;\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
\r
- if( ( *pxCoRoutineWoken ) == pdFALSE )\r
+ /* We cannot block from an ISR, so check there is data available. If\r
+ not then just leave without doing anything. */\r
+ if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
{\r
- if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+ /* Copy the data from the queue. */\r
+ pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
+ if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
{\r
- if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+ pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
+ }\r
+ --( pxQueue->uxMessagesWaiting );\r
+ ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
+\r
+ if( ( *pxCoRoutineWoken ) == pdFALSE )\r
+ {\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
{\r
- *pxCoRoutineWoken = pdTRUE;\r
+ if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+ {\r
+ *pxCoRoutineWoken = pdTRUE;\r
+ }\r
}\r
}\r
+\r
+ xReturn = pdPASS;\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
}\r
\r
- xReturn = pdPASS;\r
- }\r
- else\r
- {\r
- xReturn = pdFAIL;\r
+ return xReturn;\r
}\r
\r
- return xReturn;\r
-}\r
-#endif\r
+#endif /* configUSE_CO_ROUTINES */\r
/*-----------------------------------------------------------*/\r
\r
-#if configQUEUE_REGISTRY_SIZE > 0\r
+#if ( configQUEUE_REGISTRY_SIZE > 0 )\r
\r
void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName )\r
{\r
}\r
}\r
\r
-#endif\r
+#endif /* configQUEUE_REGISTRY_SIZE */\r
/*-----------------------------------------------------------*/\r
\r
-#if configQUEUE_REGISTRY_SIZE > 0\r
+#if ( configQUEUE_REGISTRY_SIZE > 0 )\r
\r
- static void vQueueUnregisterQueue( xQueueHandle xQueue )\r
+ void vQueueUnregisterQueue( xQueueHandle xQueue )\r
{\r
unsigned portBASE_TYPE ux;\r
\r
}\r
}\r
\r
- }\r
+ } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\r
\r
-#endif\r
+#endif /* configQUEUE_REGISTRY_SIZE */\r
/*-----------------------------------------------------------*/\r
\r
-#if configUSE_TIMERS == 1\r
+#if ( configUSE_TIMERS == 1 )\r
\r
- void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait )\r
+ void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )\r
{\r
+ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
+\r
/* This function should not be called by application code hence the\r
'Restricted' in its name. It is not part of the public API. It is\r
designed for use by kernel code, and has special calling requirements.\r
prvUnlockQueue( pxQueue );\r
}\r
\r
-#endif\r
+#endif /* configUSE_TIMERS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+ xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength )\r
+ {\r
+ xQueueSetHandle pxQueue;\r
+\r
+ pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( xQUEUE * ), queueQUEUE_TYPE_SET );\r
+\r
+ return pxQueue;\r
+ }\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+ portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
+ {\r
+ portBASE_TYPE xReturn;\r
+\r
+ if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )\r
+ {\r
+ /* Cannot add a queue/semaphore to more than one queue set. */\r
+ xReturn = pdFAIL;\r
+ }\r
+ else if( ( ( xQUEUE * ) xQueueOrSemaphore )->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ /* Cannot add a queue/semaphore to a queue set if there are already\r
+ items in the queue/semaphore. */\r
+ xReturn = pdFAIL;\r
+ }\r
+ else\r
+ {\r
+ taskENTER_CRITICAL();\r
+ {\r
+ ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ xReturn = pdPASS;\r
+ }\r
+\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+ portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
+ {\r
+ portBASE_TYPE xReturn;\r
+ xQUEUE * const pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
+\r
+ if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )\r
+ {\r
+ /* The queue was not a member of the set. */\r
+ xReturn = pdFAIL;\r
+ }\r
+ else if( pxQueueOrSemaphore->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )\r
+ {\r
+ /* It is dangerous to remove a queue from a set when the queue is\r
+ not empty because the queue set will still hold pending events for\r
+ the queue. */\r
+ xReturn = pdFAIL;\r
+ }\r
+ else\r
+ {\r
+ taskENTER_CRITICAL();\r
+ {\r
+ /* The queue is no longer contained in the set. */\r
+ pxQueueOrSemaphore->pxQueueSetContainer = NULL;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+ xReturn = pdPASS;\r
+ }\r
+\r
+ return xReturn;\r
+ } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+ xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks )\r
+ {\r
+ xQueueSetMemberHandle xReturn = NULL;\r
+\r
+ ( void ) xQueueGenericReceive( ( xQueueHandle ) xQueueSet, &xReturn, xBlockTimeTicks, pdFALSE ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+ xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet )\r
+ {\r
+ xQueueSetMemberHandle xReturn = NULL;\r
+\r
+ ( void ) xQueueReceiveFromISR( ( xQueueHandle ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_QUEUE_SETS == 1 )\r
+\r
+ static portBASE_TYPE prvNotifyQueueSetContainer( const xQUEUE * const pxQueue, portBASE_TYPE xCopyPosition )\r
+ {\r
+ xQUEUE *pxQueueSetContainer = pxQueue->pxQueueSetContainer;\r
+ portBASE_TYPE xReturn = pdFALSE;\r
+\r
+ configASSERT( pxQueueSetContainer );\r
+ configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );\r
+\r
+ if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\r
+ {\r
+ traceQUEUE_SEND( pxQueueSetContainer );\r
+ /* The data copies is the handle of the queue that contains data. */\r
+ prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\r
+ if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The task waiting has a higher priority */\r
+ xReturn = pdTRUE;\r
+ }\r
+ }\r
+ }\r
+\r
+ return xReturn;\r
+ }\r
+\r
+#endif /* configUSE_QUEUE_SETS */\r
\r