--- /dev/null
+/*\r
+ FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+\r
+ FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT\r
+ 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
+ * *\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
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\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
+\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.\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. See the GNU General Public License for more\r
+ details. You should have received a copy of the GNU General Public License\r
+ and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
+ viewed here: http://www.freertos.org/a00114.html and also obtained by\r
+ writing to Real Time Engineers Ltd., contact details for whom are available\r
+ on the FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Having a problem? Start by reading the FAQ "My application does *\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, 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, and our new\r
+ fully thread aware and reentrant UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems, who sell the code with commercial support,\r
+ indemnification and middleware, under the OpenRTOS brand.\r
+\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
+\r
+/*\r
+ * Basic task to demonstrate the xQueueOverwrite() function. See the comments\r
+ * in the function itself.\r
+ */\r
+\r
+/* Scheduler include files. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+\r
+/* Demo program include files. */\r
+#include "QueueOverwrite.h"\r
+\r
+/* A block time of 0 just means "don't block". */\r
+#define qoDONT_BLOCK 0\r
+\r
+/* Number of times to overwrite the value in the queue. */\r
+#define qoLOOPS 5\r
+\r
+/* The task that uses the queue. */\r
+static void prvQueueOverwriteTask( void *pvParameters );\r
+\r
+/* Variable that is incremented on each loop of prvQueueOverwriteTask() provided\r
+prvQueueOverwriteTask() has not found any errors. */\r
+static unsigned long ulLoopCounter = 0;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vStartQueueOverwriteTask( unsigned portBASE_TYPE uxPriority )\r
+{\r
+ /* Create the test task. */\r
+ xTaskCreate( prvQueueOverwriteTask, ( signed char * ) "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueOverwriteTask( void *pvParameters )\r
+{\r
+xQueueHandle xQueue;\r
+const unsigned portBASE_TYPE uxQueueLength = 1;\r
+unsigned long ulValue, ulStatus = pdPASS, x;\r
+\r
+ /* The parameter is not used. */\r
+ ( void ) pvParameters;\r
+\r
+ /* Create the queue. xQueueOverwrite() should only be used on queues that\r
+ have a length of 1. */\r
+ xQueue = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( unsigned long ) );\r
+ configASSERT( xQueue );\r
+\r
+ for( ;; )\r
+ {\r
+ /* The queue is empty. Writing to the queue then reading from the queue\r
+ should return the item written. */\r
+ ulValue = 10;\r
+ xQueueOverwrite( xQueue, &ulValue );\r
+\r
+ ulValue = 0;\r
+ xQueueReceive( xQueue, &ulValue, qoDONT_BLOCK );\r
+\r
+ if( ulValue != 10 )\r
+ {\r
+ ulStatus = pdFAIL;\r
+ }\r
+\r
+ /* Now try writing to the queue several times. Each time the value\r
+ in the queue should get overwritten. */\r
+ for( x = 0; x < qoLOOPS; x++ )\r
+ {\r
+ /* Write to the queue. */\r
+ xQueueOverwrite( xQueue, &x );\r
+\r
+ /* Check the value in the queue is that written, even though the\r
+ queue was not necessarily empty. */\r
+ xQueuePeek( xQueue, &ulValue, qoDONT_BLOCK );\r
+ if( ulValue != x )\r
+ {\r
+ ulStatus = pdFAIL;\r
+ }\r
+\r
+ /* There should always be one item in the queue. */\r
+ if( uxQueueMessagesWaiting( xQueue ) != uxQueueLength )\r
+ {\r
+ ulStatus = pdFAIL;\r
+ }\r
+ }\r
+\r
+ /* Empty the queue again. */\r
+ xQueueReceive( xQueue, &ulValue, qoDONT_BLOCK );\r
+\r
+ if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
+ {\r
+ ulStatus = pdFAIL;\r
+ }\r
+\r
+ if( ulStatus != pdFAIL )\r
+ {\r
+ /* Increment a counter to show this task is still running without\r
+ error. */\r
+ ulLoopCounter++;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+portBASE_TYPE xIsQueueOverwriteTaskStillRunning( void )\r
+{\r
+portBASE_TYPE xReturn;\r
+\r
+ if( ulLoopCounter > 0 )\r
+ {\r
+ xReturn = pdPASS;\r
+ }\r
+ else\r
+ {\r
+ /* The task has either stalled of discovered an error. */\r
+ xReturn = pdFAIL;\r
+ }\r
+\r
+ ulLoopCounter = 0;\r
+\r
+ return xReturn;\r
+}\r
+\r
--- /dev/null
+/*\r
+ FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+\r
+ FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT\r
+ 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
+ * *\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
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\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
+\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.\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. See the GNU General Public License for more\r
+ details. You should have received a copy of the GNU General Public License\r
+ and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
+ viewed here: http://www.freertos.org/a00114.html and also obtained by\r
+ writing to Real Time Engineers Ltd., contact details for whom are available\r
+ on the FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Having a problem? Start by reading the FAQ "My application does *\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, 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, and our new\r
+ fully thread aware and reentrant UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
+ Integrity Systems, who sell the code with commercial support, \r
+ indemnification and middleware, under the OpenRTOS brand.\r
+ \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
+\r
+#ifndef QUEUE_OVERWRITE_H\r
+#define QUEUE_OVERWRITE_H\r
+\r
+void vStartQueueOverwriteTask( unsigned portBASE_TYPE uxPriority );\r
+portBASE_TYPE xIsQueueOverwriteTaskStillRunning( void );\r
+\r
+#endif /* QUEUE_OVERWRITE_H */\r
+\r
+\r
<ClCompile Include="..\Common\Minimal\integer.c" />\r
<ClCompile Include="..\Common\Minimal\PollQ.c" />\r
<ClCompile Include="..\Common\Minimal\QPeek.c" />\r
+ <ClCompile Include="..\Common\Minimal\QueueOverwrite.c" />\r
<ClCompile Include="..\Common\Minimal\QueueSet.c" />\r
<ClCompile Include="..\Common\Minimal\semtest.c" />\r
<ClCompile Include="..\Common\Minimal\timerdemo.c" />\r
<ClCompile Include="..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-Trace\trcHardwarePort.c">\r
<Filter>Demo App Source\FreeRTOS+Trace Recorder</Filter>\r
</ClCompile>\r
+ <ClCompile Include="..\Common\Minimal\QueueOverwrite.c">\r
+ <Filter>Demo App Source\Common Demo Tasks</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="FreeRTOSConfig.h">\r
#include "death.h"\r
#include "dynamic.h"\r
#include "QueueSet.h"\r
+#include "QueueOverwrite.h"\r
\r
/* Priorities at which the tasks are created. */\r
#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
+#define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )\r
\r
#define mainTIMER_TEST_PERIOD ( 50 )\r
\r
*/\r
static void prvSaveTraceFile( void );\r
\r
+/*\r
+ * Called from the idle task hook function to demonstrate a few utility\r
+ * functions that are not demonstrated by any of the standard demo tasks.\r
+ */\r
+static void prvDemonstrateTaskStateAndHandleGetFunctions( void );\r
+\r
/*-----------------------------------------------------------*/\r
\r
/* The variable into which error messages are latched. */\r
vStartCountingSemaphoreTasks();\r
vStartDynamicPriorityTasks();\r
vStartQueueSetTasks();\r
+ vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );\r
\r
/* The suicide tasks must be created last as they need to know how many\r
tasks were running prior to their creation. This then allows them to \r
{\r
pcStatusMessage = "Error: Queue set\r\n";\r
}\r
+ else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
+ {\r
+ pcStatusMessage = "Error: Queue overwrite\r\n";\r
+ }\r
\r
/* This is the only task that uses stdout so its ok to call printf() \r
directly. */\r
void vApplicationIdleHook( void )\r
{\r
const unsigned long ulMSToSleep = 15;\r
-xTaskHandle xIdleTaskHandle, xTimerTaskHandle, xTestTask;\r
-signed char *pcTaskName;\r
-const unsigned char ucConstQueueNumber = 0xaaU, ucConstTaskNumber = 0x55U;\r
+const unsigned char ucConstQueueNumber = 0xaaU;\r
void *pvAllocated;\r
static portBASE_TYPE xTraceRunning = pdTRUE;\r
\r
tasks waiting to be terminated by the idle task. */\r
Sleep( ulMSToSleep );\r
\r
- /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and \r
- xTaskGetIdleTaskHandle() functions. Also try using the function that sets\r
- the task number. */\r
- xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
- xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();\r
- vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber );\r
- configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber );\r
-\r
- /* This is the idle hook, so the current task handle should equal the \r
- returned idle task handle. */\r
- if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
- {\r
- pcStatusMessage = "Error: Returned idle task handle was incorrect";\r
- }\r
-\r
- /* Check the timer task handle was returned correctly. */\r
- pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );\r
- if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
- {\r
- pcStatusMessage = "Error: Returned timer task handle was incorrect";\r
- }\r
-\r
- /* This task is running, make sure its state is returned as running. */\r
- if( eTaskStateGet( xIdleTaskHandle ) != eRunning )\r
- {\r
- pcStatusMessage = "Error: Returned idle task state was incorrect";\r
- }\r
-\r
- /* If this task is running, then the timer task must be blocked. */\r
- if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )\r
- {\r
- pcStatusMessage = "Error: Returned timer task state was incorrect";\r
- }\r
+ /* Demonstrate a few utility functions that are not demonstrated by any of\r
+ the standard demo tasks. */\r
+ prvDemonstrateTaskStateAndHandleGetFunctions();\r
\r
/* If xMutexToDelete has not already been deleted, then delete it now.\r
This is done purely to demonstrate the use of, and test, the \r
configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );\r
vSemaphoreDelete( xMutexToDelete );\r
xMutexToDelete = NULL;\r
-\r
- /* Other tests that should only be performed once follow. The test task\r
- is not created on each iteration because to do so would cause the death\r
- task to report an error (too many tasks running). */\r
-\r
- /* Create a test task to use to test other eTaskStateGet() return values. */\r
- if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )\r
- {\r
- /* If this task is running, the test task must be in the ready state. */\r
- if( eTaskStateGet( xTestTask ) != eReady )\r
- {\r
- pcStatusMessage = "Error: Returned test task state was incorrect 1";\r
- }\r
-\r
- /* Now suspend the test task and check its state is reported correctly. */\r
- vTaskSuspend( xTestTask );\r
- if( eTaskStateGet( xTestTask ) != eSuspended )\r
- {\r
- pcStatusMessage = "Error: Returned test task state was incorrect 2";\r
- }\r
-\r
- /* Now delete the task and check its state is reported correctly. */\r
- vTaskDelete( xTestTask );\r
- if( eTaskStateGet( xTestTask ) != eDeleted )\r
- {\r
- pcStatusMessage = "Error: Returned test task state was incorrect 3";\r
- }\r
- }\r
}\r
\r
/* Exercise heap_4 a bit. The malloc failed hook will trap failed \r
printf( "\r\nFailed to create trace dump file\r\n" );\r
}\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvDemonstrateTaskStateAndHandleGetFunctions( void )\r
+{\r
+xTaskHandle xIdleTaskHandle, xTimerTaskHandle;\r
+const unsigned char ucConstTaskNumber = 0x55U;\r
+signed char *pcTaskName;\r
+static portBASE_TYPE xPerformedOneShotTests = pdFALSE;\r
+xTaskHandle xTestTask;\r
+\r
+ /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and \r
+ xTaskGetIdleTaskHandle() functions. Also try using the function that sets\r
+ the task number. */\r
+ xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
+ xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();\r
+ vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber );\r
+ configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber );\r
+\r
+ /* This is the idle hook, so the current task handle should equal the \r
+ returned idle task handle. */\r
+ if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
+ {\r
+ pcStatusMessage = "Error: Returned idle task handle was incorrect";\r
+ }\r
+\r
+ /* Check the timer task handle was returned correctly. */\r
+ pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );\r
+ if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
+ {\r
+ pcStatusMessage = "Error: Returned timer task handle was incorrect";\r
+ }\r
+\r
+ /* This task is running, make sure it's state is returned as running. */\r
+ if( eTaskStateGet( xIdleTaskHandle ) != eRunning )\r
+ {\r
+ pcStatusMessage = "Error: Returned idle task state was incorrect";\r
+ }\r
+\r
+ /* If this task is running, then the timer task must be blocked. */\r
+ if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )\r
+ {\r
+ pcStatusMessage = "Error: Returned timer task state was incorrect";\r
+ }\r
+\r
+ /* Other tests that should only be performed once follow. The test task\r
+ is not created on each iteration because to do so would cause the death\r
+ task to report an error (too many tasks running). */\r
+ if( xPerformedOneShotTests == pdFALSE )\r
+ {\r
+ /* Don't run this part of the test again. */\r
+ xPerformedOneShotTests = pdTRUE;\r
+\r
+ /* Create a test task to use to test other eTaskStateGet() return values. */\r
+ if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )\r
+ {\r
+ /* If this task is running, the test task must be in the ready state. */\r
+ if( eTaskStateGet( xTestTask ) != eReady )\r
+ {\r
+ pcStatusMessage = "Error: Returned test task state was incorrect 1";\r
+ }\r
+\r
+ /* Now suspend the test task and check its state is reported correctly. */\r
+ vTaskSuspend( xTestTask );\r
+ if( eTaskStateGet( xTestTask ) != eSuspended )\r
+ {\r
+ pcStatusMessage = "Error: Returned test task state was incorrect 2";\r
+ }\r
+\r
+ /* Now delete the task and check its state is reported correctly. */\r
+ vTaskDelete( xTestTask );\r
+ if( eTaskStateGet( xTestTask ) != eDeleted )\r
+ {\r
+ pcStatusMessage = "Error: Returned test task state was incorrect 3";\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
typedef void * xQueueSetMemberHandle;\r
\r
/* For internal use only. */\r
-#define queueSEND_TO_BACK ( 0 )\r
-#define queueSEND_TO_FRONT ( 1 )\r
+#define queueSEND_TO_BACK ( 0 )\r
+#define queueSEND_TO_FRONT ( 1 )\r
+#define queueOVERWRITE ( 2 )\r
\r
/* For internal use only. These definitions *must* match those in queue.c. */\r
#define queueQUEUE_TYPE_BASE ( 0U )\r
*/\r
#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )\r
\r
+/**\r
+ * queue. h\r
+ * <pre>\r
+ portBASE_TYPE xQueueOverwrite(\r
+ xQueueHandle xQueue,\r
+ const void * pvItemToQueue,\r
+ );\r
+ * </pre>\r
+ *\r
+ * Only for use with queues that can hold a single item - so the queue is either\r
+ * empty or full.\r
+ *\r
+ * Post an item on a queue. If the queue is already full then overwrite the\r
+ * value held in the queue. The item is queued by copy, not by reference.\r
+ * This function must not be called from an interrupt service routine.\r
+ * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.\r
+ *\r
+ * @param xQueue The handle to the queue on which the item is to be posted.\r
+ *\r
+ * @param pvItemToQueue A pointer to the item that is to be placed on the\r
+ * queue. The size of the items the queue will hold was defined when the\r
+ * queue was created, so this many bytes will be copied from pvItemToQueue\r
+ * into the queue storage area.\r
+ *\r
+ * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and\r
+ * therefore has the same return values as xQueueSendToFront(). However, as\r
+ * xQueueOverwrite() will write to the queue even when the queue is full pdPASS\r
+ * will be returned in all cases (errQUEUE_FULL will never be returned).\r
+ *\r
+ * Example usage:\r
+ <pre>\r
+\r
+ void vFunction( void *pvParameters )\r
+ {\r
+ xQueueHandle xQueue;\r
+ unsigned long ulVarToSend, ulValReceived;\r
+\r
+ // Create a queue to hold one unsigned long value. It is strongly\r
+ // recommended *not* to use xQueueOverwrite() on queues that can\r
+ // contain more than one value, and doing so will trigger an assertion\r
+ // if configASSERT() is defined.\r
+ xQueue = xQueueCreate( 1, sizeof( unsigned long ) );\r
+\r
+ // Write the value 10 to the queue using xQueueOverwrite().\r
+ ulVarToSend = 10;\r
+ xQueueOverwrite( xQueue, &ulVarToSend );\r
+\r
+ // Peeking the queue should now return 10, but leave the value 10 in\r
+ // the queue. A block time of zero is used as it is known that the\r
+ // queue holds a value.\r
+ ulValReceived = 0;\r
+ xQueuePeek( xQueue, &ulValReceived, 0 );\r
+\r
+ if( ulValReceived != 10 )\r
+ {\r
+ // Error!\r
+ }\r
+\r
+ // The queue is still full. Use xQueueOverwrite() to overwrite the\r
+ // value held in the queue with 100.\r
+ ulVarToSend = 100;\r
+ xQueueOverwrite( xQueue, &ulVarToSend );\r
+\r
+ // This time read from the queue, leaving the queue empty once more.\r
+ // A block time of 0 is used again.\r
+ xQueueReceive( xQueue, &ulValReceived, 0 );\r
+\r
+ // The value read should be the last value written, even though the\r
+ // queue was already full when the value was written.\r
+ if( ulValReceived != 100 )\r
+ {\r
+ // Error!\r
+ }\r
+\r
+ // ...\r
+}\r
+ </pre>\r
+ * \defgroup xQueueOverwrite xQueueOverwrite\r
+ * \ingroup QueueManagement\r
+ */\r
+#define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )\r
+\r
\r
/**\r
* queue. h\r
pxQueue = ( xQUEUE * ) xQueue;\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
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
+ /* Remember the read position in case the queue is only being \r
+ peeked. */\r
pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
\r
prvCopyDataFromQueue( pxQueue, pvBuffer );\r
pxQueue->pxMutexHolder = NULL;\r
}\r
}\r
- #endif\r
+ #endif /* configUSE_MUTEXES */\r
}\r
else if( xPosition == queueSEND_TO_BACK )\r
{\r
{\r
pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
}\r
+\r
+ if( xPosition == queueOVERWRITE )\r
+ {\r
+ if( pxQueue->uxMessagesWaiting > 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
++( pxQueue->uxMessagesWaiting );\r
xMPU_SETTINGS xMPUSettings; /*< The MPU settings are defined as part of the port layer. THIS MUST BE THE SECOND MEMBER OF THE TCB STRUCT. */\r
#endif\r
\r
- xListItem xGenericListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\r
+ xListItem xGenericListItem; /*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\r
xListItem xEventListItem; /*< Used to reference a task from an event list. */\r
unsigned portBASE_TYPE uxPriority; /*< The priority of the task. 0 is the lowest priority. */\r
portSTACK_TYPE *pxStack; /*< Points to the start of the stack. */\r
#if ( configUSE_NEWLIB_REENTRANT == 1 )\r
/* Allocate a Newlib reent structure that is specific to this task.\r
Note Newlib support has been included by popular demand, but is not\r
- used by the FreeRTOS maintainers themselves, and therefore receives\r
- less rigorous testing than the rest of the FreeRTOS code. */\r
+ used by the FreeRTOS maintainers themselves. FreeRTOS is not\r
+ responsible for resulting newlib operation. User must be familiar with\r
+ newlib and must provide system-wide implementations of the necessary\r
+ stubs. Be warned that (at the time of writing) the current newlib design\r
+ implements a system-wide malloc() that must be provided with locks. */\r
struct _reent xNewLib_reent;\r
#endif\r
\r