]> git.sur5r.net Git - freertos/commitdiff
Fix buffer clean up in \FreeRTOS_Plus_TCP_Minimal_Windows_Simulator\demo_logging.c.
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 26 Feb 2018 21:22:44 +0000 (21:22 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 26 Feb 2018 21:22:44 +0000 (21:22 +0000)
Update queue code to allow an overwrite operation on a queue that is in a queue set, and add prvTestQueueOverwriteWithQueueSet() to test function.
Update Eclipse Win32 project to bring it closer the the Visual Studio equivalent.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2530 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator/demo_logging.c
FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/History.txt
FreeRTOS/Demo/Common/Minimal/QueueSet.c
FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c
FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo
FreeRTOS/Demo/WIN32-MSVC/main_full.c
FreeRTOS/Demo/WIN32-MingW/.project
FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h
FreeRTOS/Demo/WIN32-MingW/main_blinky.c
FreeRTOS/Demo/WIN32-MingW/main_full.c
FreeRTOS/Source/queue.c

index 447aeef36cc1baa26bf6e87c586b4b77a5c11398..41cd548ea2596a55d6a52be54adf71869ea20582 100644 (file)
@@ -296,8 +296,8 @@ HANDLE xCurrentTask;
                if( xLength2 <  0 )\r
                {\r
                        /* Clean up. */\r
-                       xLength2 = sizeof( cPrintString ) - 1 - xLength;\r
-                       cPrintString[ sizeof( cPrintString ) - 1 ] = '\0';\r
+                       xLength2 = dlMAX_PRINT_STRING_LENGTH - 1 - xLength;\r
+                       cPrintString[ dlMAX_PRINT_STRING_LENGTH - 1 ] = '\0';\r
                }\r
 \r
                xLength += xLength2;\r
index 727bf3c844d088d28e7dba8e8f2ea1fc5d274b3c..fd3ba86faa43e97435c42aee3268687c8f1981c5 100644 (file)
@@ -1,9 +1,14 @@
 Changes since V2.0.0 release\r
 \r
-       + Added FREERTOS_SO_WAKEUP_CALLBACK option so a callback can be executed\r
-         when data arrives.\r
-       + Improve print output when using WinPCap to assist in selecting the\r
-         correct network interface.\r
+       + Update FreeRTOS_gethostbyname() to allow an IP address to be passed in -\r
+         in which case it is just returned as a uint32_t.\r
+       + Introduce ipconfigSOCKET_HAS_USER_WAKE_CALLBACK to FreeRTOS_Sockets.c to\r
+         allow a user supposed callback function to be executed when socket events\r
+         occur in the same way that the socket semaphore is currently used.\r
+       + Update xNetworkBuffersInitialise() to ensure the semaphore created by the\r
+         function is not accessed until after the NULL check.\r
+       + Improve print messages output by the Win32 port layer version of\r
+         prvPrintAvailableNetworkInterfaces().\r
 \r
 Changes between 160908 and 160919 releases:\r
 \r
index 9f346bb5a7f3d483ef832ed6f95db3a64a8c25f1..528ec06c08c2932c5e9965dee417387a4e5b80ad 100644 (file)
@@ -138,9 +138,17 @@ static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived,
 \r
 /*\r
  * Increase test coverage by occasionally change the priorities of the two tasks\r
- * relative to each other. */\r
+ * relative to each other.\r
+ */\r
 static void prvChangeRelativePriorities( void );\r
 \r
+/*\r
+ * Queue overwrites can only be performed on queues of length of one, requiring\r
+ * a special test function so a queue of length 1 can temporarily be added to a\r
+ * set.\r
+ */\r
+static void prvTestQueueOverwriteWithQueueSet( void );\r
+\r
 /*\r
  * Local pseudo random number seed and return functions.  Used to avoid calls\r
  * to the standard library.\r
@@ -599,6 +607,71 @@ uint32_t ulTxValueSnapshot = ulISRTxValue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvTestQueueOverwriteWithQueueSet( void )\r
+{\r
+uint32_t ulValueToSend = 0, ulValueReceived = 0;\r
+QueueHandle_t xQueueHandle = NULL, xReceivedHandle = NULL;\r
+const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;\r
+\r
+       /* Create a queue that has a length of one - a requirement in order to call\r
+       xQueueOverwrite.  This will get deleted again when this test completes. */\r
+       xQueueHandle = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );\r
+\r
+       if( xQueueHandle != NULL )\r
+       {\r
+               xQueueAddToSet( xQueueHandle, xQueueSet );\r
+\r
+               /* Add an item to the queue then ensure the queue set correctly\r
+               indicates that one item is available, and that that item is indeed the\r
+               queue written to. */\r
+               xQueueSend( xQueueHandle, ( void * ) &ulValueToSend, 0 );\r
+               if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
+               {\r
+                       /* Expected one item in the queue set. */\r
+                       xQueueSetTasksStatus = pdFAIL;\r
+               }\r
+               xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );\r
+               if( xReceivedHandle != xQueueHandle )\r
+               {\r
+                       /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
+                       held in the queue set. */\r
+                       xQueueSetTasksStatus = pdFAIL;\r
+               }\r
+\r
+               /* Now overwrite the value in the queue and ensure the queue set state\r
+               doesn't change as the number of items in the queues within the set have\r
+               not changed. */\r
+               ulValueToSend++;\r
+               xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );\r
+               if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )\r
+               {\r
+                       /* Still expected one item in the queue set. */\r
+                       xQueueSetTasksStatus = pdFAIL;\r
+               }\r
+               xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );\r
+               if( xReceivedHandle != xQueueHandle )\r
+               {\r
+                       /* Wrote to xQueueHandle so expected xQueueHandle to be the handle\r
+                       held in the queue set. */\r
+                       xQueueSetTasksStatus = pdFAIL;\r
+               }\r
+\r
+               /* Also ensure the value received from the queue is the overwritten\r
+               value, not the value originally written. */\r
+               xQueueReceive( xQueueHandle, &ulValueReceived, queuesetDONT_BLOCK );\r
+               if( ulValueReceived != ulValueToSend )\r
+               {\r
+                       /* Unexpected value recevied from the queue. */\r
+                       xQueueSetTasksStatus = pdFAIL;\r
+               }\r
+\r
+               /* Clean up. */\r
+               xQueueRemoveFromSet( xQueueHandle, xQueueSet );\r
+               vQueueDelete( xQueueHandle );\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvSetupTest( void )\r
 {\r
 BaseType_t x;\r
@@ -675,6 +748,11 @@ uint32_t ulValueToSend = 0;
                xQueueSetTasksStatus = pdFAIL;\r
        }\r
 \r
+       /* Testing the behaviour of queue sets when a queue overwrite operation is\r
+       performed on a set member requires a special test as overwrites can only\r
+       be performed on queues that have a length of 1. */\r
+       prvTestQueueOverwriteWithQueueSet();\r
+\r
        /* Resume the task that writes to the queues. */\r
        vTaskResume( xQueueSetSendingTask );\r
 \r
index 772d5b4c60ada6c3189b1402a295d3a574874ce6..112dbf30c057e2bbbd8367156f0bfddadca38d48 100644 (file)
@@ -172,7 +172,7 @@ BaseType_t xNextByte = 0;
                                continuing to look for the end of the string. */\r
                                xNextByte++;\r
 \r
-                               configASSERT( xNextByte < sizeof( cRxBuffer ) );\r
+                               configASSERT( ( size_t ) xNextByte < sizeof( cRxBuffer ) );\r
                        }\r
                }\r
        }\r
@@ -193,7 +193,7 @@ static BaseType_t xCallCount = 0;
 \r
                /* Send the next four bytes to the stream buffer. */\r
                xStreamBufferSendFromISR( xStreamBuffer,\r
-                                                                 ( void * ) ( pcStringToSend + xNextByteToSend ),\r
+                                                                 ( const void * ) ( pcStringToSend + xNextByteToSend ),\r
                                                                  xBytesToSend,\r
                                                                  NULL );\r
 \r
index e28c889a4361b37bc393c0bd7bcd6217117df43c..87d803022f5336a90ac661e095bfa862fae8593d 100644 (file)
Binary files a/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo and b/FreeRTOS/Demo/WIN32-MSVC/.vs/WIN32/v14/.suo differ
index b99ff8b8d433862f1af0f80b4b6c0dc342541e50..68488eb371169e8ee0661f801b22460474522f76 100644 (file)
@@ -141,8 +141,8 @@ static void prvDemonstrateTaskStateAndHandleGetFunctions( void );
 static void prvDemonstratePendingFunctionCall( void );\r
 \r
 /*\r
-* The function that is pended by prvDemonstratePendingFunctionCall().\r
-*/\r
+ * The function that is pended by prvDemonstratePendingFunctionCall().\r
+ */\r
 static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );\r
 \r
 /*\r
index 3d2741c3bb7aefe9802db4247af642ae52d4c95a..07f94ab4e0f324f8ffca58f596f4ed7fcb8090f1 100644 (file)
@@ -56,7 +56,7 @@
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156304</id>\r
+                       <id>1519407948166</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
@@ -65,7 +65,7 @@
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156307</id>\r
+                       <id>1519407948169</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
@@ -74,7 +74,7 @@
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156310</id>\r
+                       <id>1519407948172</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
@@ -83,7 +83,7 @@
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156313</id>\r
+                       <id>1519407948176</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
@@ -92,7 +92,7 @@
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156316</id>\r
+                       <id>1519407948179</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156319</id>\r
+                       <id>1519407948183</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156323</id>\r
+                       <id>1519407948186</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156327</id>\r
+                       <id>1519407948190</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156330</id>\r
+                       <id>1519407948195</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156333</id>\r
+                       <id>1519407948199</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156337</id>\r
+                       <id>1519407948202</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156340</id>\r
+                       <id>1519407948213</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156343</id>\r
+                       <id>1519407948216</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156347</id>\r
+                       <id>1519407948224</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156350</id>\r
+                       <id>1519407948228</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156353</id>\r
+                       <id>1519407948231</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156356</id>\r
+                       <id>1519407948235</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156359</id>\r
+                       <id>1519407948237</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156362</id>\r
+                       <id>1519407948240</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156366</id>\r
+                       <id>1519407948242</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                        </matcher>\r
                </filter>\r
                <filter>\r
-                       <id>1507735156369</id>\r
+                       <id>1519407948269</id>\r
                        <name>Standard_Demo_Tasks</name>\r
                        <type>5</type>\r
                        <matcher>\r
                                <arguments>1.0-name-matches-false-false-MessageBufferDemo.c</arguments>\r
                        </matcher>\r
                </filter>\r
+               <filter>\r
+                       <id>1519407948274</id>\r
+                       <name>Standard_Demo_Tasks</name>\r
+                       <type>5</type>\r
+                       <matcher>\r
+                               <id>org.eclipse.ui.ide.multiFilter</id>\r
+                               <arguments>1.0-name-matches-false-false-StreamBufferDemo.c</arguments>\r
+                       </matcher>\r
+               </filter>\r
+               <filter>\r
+                       <id>1519407948277</id>\r
+                       <name>Standard_Demo_Tasks</name>\r
+                       <type>5</type>\r
+                       <matcher>\r
+                               <id>org.eclipse.ui.ide.multiFilter</id>\r
+                               <arguments>1.0-name-matches-false-false-StreamBufferInterrupt.c</arguments>\r
+                       </matcher>\r
+               </filter>\r
+               <filter>\r
+                       <id>1519407948281</id>\r
+                       <name>Standard_Demo_Tasks</name>\r
+                       <type>5</type>\r
+                       <matcher>\r
+                               <id>org.eclipse.ui.ide.multiFilter</id>\r
+                               <arguments>1.0-name-matches-false-false-MessageBufferDemo.c</arguments>\r
+                       </matcher>\r
+               </filter>\r
+               <filter>\r
+                       <id>1519407948286</id>\r
+                       <name>Standard_Demo_Tasks</name>\r
+                       <type>5</type>\r
+                       <matcher>\r
+                               <id>org.eclipse.ui.ide.multiFilter</id>\r
+                               <arguments>1.0-name-matches-false-false-MessageBufferAMP.c</arguments>\r
+                       </matcher>\r
+               </filter>\r
                <filter>\r
                        <id>0</id>\r
                        <name>FreeRTOS_Source/portable</name>\r
index 89331b274f0e582444f91b880c8748651c5f8690..f25119d49ae9d5b72ab6778d2e75c13c5a891d1c 100644 (file)
@@ -114,6 +114,12 @@ uses the same semantics as the standard C assert() macro. */
 extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName );\r
 #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __LINE__, __FILE__ )\r
 \r
+#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO  1\r
+#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )\r
+       extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );\r
+       #define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )\r
+#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */\r
+\r
 /* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */\r
 #include "trcRecorder.h"\r
 \r
index d0465828990c1003543797aa3c030145ea4146b0..822cbd424c2aad9157ee203bd744993646efd1c6 100644 (file)
  */\r
 \r
 /******************************************************************************\r
- * NOTE 1: The Win32 port is a simulation (or is that emulation?) only!  Do not\r
- * expect to get real time behaviour from the Win32 port or this demo\r
- * application.  It is provided as a convenient development and demonstration\r
- * test bed only.  This was tested using Windows XP on a dual core laptop.\r
- *\r
- * Windows will not be running the FreeRTOS simulator threads continuously, so\r
- * the timing information in the FreeRTOS+Trace logs have no meaningful units.\r
- * See the documentation page for the Windows simulator for an explanation of\r
- * the slow timing:\r
+ * NOTE 1: Windows will not be running the FreeRTOS demo threads continuously, so\r
+ * do not expect to get real time behaviour from the FreeRTOS Windows port, or\r
+ * this demo application.  Also, the timing information in the FreeRTOS+Trace\r
+ * logs have no meaningful units.  See the documentation page for the Windows\r
+ * port for further information:\r
  * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
- * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
  *\r
  * NOTE 2:  This project provides two demo applications.  A simple blinky style\r
  * project, and a more comprehensive test and demo application.  The\r
  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
- * in main.c.  This file implements the simply blinky style version.\r
+ * in main.c.  This file implements the simply blinky version.  Console output\r
+ * is used in place of the normal LED toggling.\r
  *\r
  * NOTE 3:  This file only contains the source code that is specific to the\r
  * basic demo.  Generic functions, such FreeRTOS hook functions, are defined\r
  * in main.c.\r
  ******************************************************************************\r
  *\r
- * main_blinky() creates one queue, and two tasks.  It then starts the\r
- * scheduler.\r
+ * main_blinky() creates one queue, one software timer, and two tasks.  It then\r
+ * starts the scheduler.\r
  *\r
  * The Queue Send Task:\r
  * The queue send task is implemented by the prvQueueSendTask() function in\r
- * this file.  prvQueueSendTask() sits in a loop that causes it to repeatedly\r
- * block for 200 (simulated as far as the scheduler is concerned, but in\r
- * reality much longer - see notes above) milliseconds, before sending the\r
- * value 100 to the queue that was created within main_blinky().  Once the\r
- * value is sent, the task loops back around to block for another 200\r
- * (simulated) milliseconds.\r
+ * this file.  It uses vTaskDelayUntil() to create a periodic task that sends\r
+ * the value 100 to the queue every 200 milliseconds (please read the notes\r
+ * above regarding the accuracy of timing under Windows).\r
+ *\r
+ * The Queue Send Software Timer:\r
+ * The timer is an auto-reload timer with a period of two seconds.  The timer's\r
+ * callback function writes the value 200 to the queue.  The callback function\r
+ * is implemented by prvQueueSendTimerCallback() within this file.\r
  *\r
  * The Queue Receive Task:\r
  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
- * in this file.  prvQueueReceiveTask() sits in a loop where it repeatedly\r
- * blocks on attempts to read data from the queue that was created within\r
- * main_blinky().  When data is received, the task checks the value of the\r
- * data, and if the value equals the expected 100, outputs a message.  The\r
- * 'block time' parameter passed to the queue receive function specifies that\r
- * the task should be held in the Blocked state indefinitely to wait for data\r
- * to be available on the queue.  The queue receive task will only leave the\r
- * Blocked state when the queue send task writes to the queue.  As the queue\r
- * send task writes to the queue every 200 (simulated - see notes above)\r
- * milliseconds, the queue receive task leaves the Blocked state every 200\r
- * milliseconds, and therefore outputs a message every 200 milliseconds.\r
+ * in this file.  prvQueueReceiveTask() waits for data to arrive on the queue.\r
+ * When data is received, the task checks the value of the data, then outputs a\r
+ * message to indicate if the data came from the queue send task or the queue\r
+ * send software timer.\r
+ *\r
+ * Expected Behaviour:\r
+ * - The queue send task writes to the queue every 200ms, so every 200ms the\r
+ *   queue receive task will output a message indicating that data was received\r
+ *   on the queue from the queue send task.\r
+ * - The queue send software timer has a period of two seconds, and is reset\r
+ *   each time a key is pressed.  So if two seconds expire without a key being\r
+ *   pressed then the queue receive task will output a message indicating that\r
+ *   data was received on the queue from the queue send software timer.\r
+ *\r
+ * NOTE:  Console input and output relies on Windows system calls, which can\r
+ * interfere with the execution of the FreeRTOS Windows port.  This demo only\r
+ * uses Windows system call occasionally.  Heavier use of Windows system calls\r
+ * can crash the port.\r
  */\r
 \r
 /* Standard includes. */\r
 #include <stdio.h>\r
+#include <conio.h>\r
 \r
 /* Kernel includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
+#include "timers.h"\r
 #include "semphr.h"\r
 \r
 /* Priorities at which the tasks are created. */\r
 #define mainQUEUE_RECEIVE_TASK_PRIORITY                ( tskIDLE_PRIORITY + 2 )\r
 #define        mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
 \r
-/* The rate at which data is sent to the queue.  The 200ms value is converted\r
-to ticks using the portTICK_PERIOD_MS constant. */\r
-#define mainQUEUE_SEND_FREQUENCY_MS                    ( 200 / portTICK_PERIOD_MS )\r
+/* The rate at which data is sent to the queue.  The times are converted from\r
+milliseconds to ticks using the pdMS_TO_TICKS() macro. */\r
+#define mainTASK_SEND_FREQUENCY_MS                     pdMS_TO_TICKS( 200UL )\r
+#define mainTIMER_SEND_FREQUENCY_MS                    pdMS_TO_TICKS( 2000UL )\r
 \r
-/* The number of items the queue can hold.  This is 1 as the receive task\r
-will remove items as they are added, meaning the send task should always find\r
-the queue empty. */\r
-#define mainQUEUE_LENGTH                                       ( 1 )\r
+/* The number of items the queue can hold at once. */\r
+#define mainQUEUE_LENGTH                                       ( 2 )\r
 \r
-/* Values passed to the two tasks just to check the task parameter\r
-functionality. */\r
-#define mainQUEUE_SEND_PARAMETER                       ( 0x1111UL )\r
-#define mainQUEUE_RECEIVE_PARAMETER                    ( 0x22UL )\r
+/* The values sent to the queue receive task from the queue send task and the\r
+queue send software timer respectively. */\r
+#define mainVALUE_SENT_FROM_TASK                       ( 100UL )\r
+#define mainVALUE_SENT_FROM_TIMER                      ( 200UL )\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -110,30 +116,53 @@ functionality. */
 static void prvQueueReceiveTask( void *pvParameters );\r
 static void prvQueueSendTask( void *pvParameters );\r
 \r
+/*\r
+ * The callback function executed when the software timer expires.\r
+ */\r
+static void prvQueueSendTimerCallback( TimerHandle_t xTimerHandle );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /* The queue used by both tasks. */\r
 static QueueHandle_t xQueue = NULL;\r
 \r
+/* A software timer that is started from the tick hook. */\r
+static TimerHandle_t xTimer = NULL;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
+/*** SEE THE COMMENTS AT THE TOP OF THIS FILE ***/\r
 void main_blinky( void )\r
 {\r
+const TickType_t xTimerPeriod = mainTIMER_SEND_FREQUENCY_MS;\r
+\r
        /* Create the queue. */\r
-       xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
+       xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( uint32_t ) );\r
 \r
        if( xQueue != NULL )\r
        {\r
                /* Start the two tasks as described in the comments at the top of this\r
                file. */\r
-               xTaskCreate( prvQueueReceiveTask,                                       /* The function that implements the task. */\r
-                                       "Rx",                                                                   /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
-                                       configMINIMAL_STACK_SIZE,                               /* The size of the stack to allocate to the task. */\r
-                                       ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */\r
-                                       mainQUEUE_RECEIVE_TASK_PRIORITY,                /* The priority assigned to the task. */\r
-                                       NULL );                                                                 /* The task handle is not required, so NULL is passed. */\r
+               xTaskCreate( prvQueueReceiveTask,                       /* The function that implements the task. */\r
+                                       "Rx",                                                   /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
+                                       configMINIMAL_STACK_SIZE,               /* The size of the stack to allocate to the task. */\r
+                                       NULL,                                                   /* The parameter passed to the task - not used in this simple case. */\r
+                                       mainQUEUE_RECEIVE_TASK_PRIORITY,/* The priority assigned to the task. */\r
+                                       NULL );                                                 /* The task handle is not required, so NULL is passed. */\r
 \r
-               xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
+               xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
+\r
+               /* Create the software timer, but don't start it yet. */\r
+               xTimer = xTimerCreate( "Timer",                         /* The text name assigned to the software timer - for debug only as it is not used by the kernel. */\r
+                                                               xTimerPeriod,           /* The period of the software timer in ticks. */\r
+                                                               pdTRUE,                         /* xAutoReload is set to pdTRUE. */\r
+                                                               NULL,                           /* The timer's ID is not used. */\r
+                                                               prvQueueSendTimerCallback );/* The function executed when the timer expires. */\r
+\r
+               if( xTimer != NULL )\r
+               {\r
+                       xTimerStart( xTimer, 0 );\r
+               }\r
 \r
                /* Start the tasks and timer running. */\r
                vTaskStartScheduler();\r
@@ -151,65 +180,86 @@ void main_blinky( void )
 static void prvQueueSendTask( void *pvParameters )\r
 {\r
 TickType_t xNextWakeTime;\r
-const unsigned long ulValueToSend = 100UL;\r
-const TickType_t xBlockTime = pdMS_TO_TICKS( mainQUEUE_SEND_FREQUENCY_MS );\r
+const TickType_t xBlockTime = mainTASK_SEND_FREQUENCY_MS;\r
+const uint32_t ulValueToSend = mainVALUE_SENT_FROM_TASK;\r
 \r
-       /* Remove compiler warning in the case that configASSERT() is not\r
-       defined. */\r
+       /* Prevent the compiler warning about the unused parameter. */\r
        ( void ) pvParameters;\r
 \r
-       /* Check the task parameter is as expected. */\r
-       configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER );\r
-\r
        /* Initialise xNextWakeTime - this only needs to be done once. */\r
        xNextWakeTime = xTaskGetTickCount();\r
 \r
        for( ;; )\r
        {\r
                /* Place this task in the blocked state until it is time to run again.\r
-               The block time is specified in ticks, the constant used converts ticks\r
-               to ms.  While in the Blocked state this task will not consume any CPU\r
-               time. */\r
+               The block time is specified in ticks, pdMS_TO_TICKS() was used to\r
+               convert a time specified in milliseconds into a time specified in ticks.\r
+               While in the Blocked state this task will not consume any CPU time. */\r
                vTaskDelayUntil( &xNextWakeTime, xBlockTime );\r
 \r
                /* Send to the queue - causing the queue receive task to unblock and\r
-               toggle the LED.  0 is used as the block time so the sending operation\r
+               write to the console.  0 is used as the block time so the send operation\r
                will not block - it shouldn't need to block as the queue should always\r
-               be empty at this point in the code. */\r
+               have at least one space at this point in the code. */\r
                xQueueSend( xQueue, &ulValueToSend, 0U );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvQueueSendTimerCallback( TimerHandle_t xTimerHandle )\r
+{\r
+const uint32_t ulValueToSend = mainVALUE_SENT_FROM_TIMER;\r
+\r
+       /* This is the software timer callback function.  The software timer has a\r
+       period of two seconds and is reset each time a key is pressed.  This\r
+       callback function will execute if the timer expires, which will only happen\r
+       if a key is not pressed for two seconds. */\r
+\r
+       /* Avoid compiler warnings resulting from the unused parameter. */\r
+       ( void ) xTimerHandle;\r
+\r
+       /* Send to the queue - causing the queue receive task to unblock and\r
+       write out a message.  This function is called from the timer/daemon task, so\r
+       must not block.  Hence the block time is set to 0. */\r
+       xQueueSend( xQueue, &ulValueToSend, 0U );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvQueueReceiveTask( void *pvParameters )\r
 {\r
-unsigned long ulReceivedValue;\r
+uint32_t ulReceivedValue;\r
 \r
-       /* Remove compiler warning in the case that configASSERT() is not\r
-       defined. */\r
+       /* Prevent the compiler warning about the unused parameter. */\r
        ( void ) pvParameters;\r
 \r
-       /* Check the task parameter is as expected. */\r
-       configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER );\r
-\r
        for( ;; )\r
        {\r
                /* Wait until something arrives in the queue - this task will block\r
                indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
-               FreeRTOSConfig.h. */\r
+               FreeRTOSConfig.h.  It will not use any CPU time while it is in the\r
+               Blocked state. */\r
                xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
 \r
-               /*  To get here something must have been received from the queue, but\r
-               is it the expected value?  If it is, toggle the LED. */\r
-               if( ulReceivedValue == 100UL )\r
+               /* To get here something must have been received from the queue, but\r
+               is it an expected value?  Normally calling printf() from a task is not\r
+               a good idea.  Here there is lots of stack space and only one task is\r
+               using console IO so it is ok.  However, note the comments at the top of\r
+               this file about the risks of making Windows system calls (such as \r
+               console output) from a FreeRTOS task. */\r
+               if( ulReceivedValue == mainVALUE_SENT_FROM_TASK )\r
+               {\r
+                       printf( "Message received from task\r\n" );\r
+               }\r
+               else if( ulReceivedValue == mainVALUE_SENT_FROM_TIMER )\r
                {\r
-                       /* Normally calling printf() from a task is not a good idea.  Here\r
-                       there is lots of stack space and only one task is using console  IO\r
-                       so it is ok. */\r
-                       printf( "Message received\r\n" );\r
-                       fflush( stdout );\r
-                       ulReceivedValue = 0U;\r
+                       printf( "Message received from software timer\r\n" );\r
                }\r
+               else\r
+               {\r
+                       printf( "Unexpected message\r\n" );\r
+               }\r
+\r
+               fflush( stdout );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
index 4f3c1676f7f66a76f14fa66dd4e22a0e791186db..b67a6fd0cc3398d58acdf6fcdbf8ddb211358747 100644 (file)
 #include "AbortDelay.h"\r
 #include "MessageBufferDemo.h"\r
 #include "StreamBufferDemo.h"\r
+#include "StreamBufferInterrupt.h"\r
+#include "MessageBufferAMP.h"\r
 \r
 /* Priorities at which the tasks are created. */\r
 #define mainCHECK_TASK_PRIORITY                        ( configMAX_PRIORITIES - 2 )\r
@@ -204,6 +206,8 @@ int main_full( void )
 \r
        vStartMessageBufferTasks();\r
        vStartStreamBufferTasks();\r
+       vStartStreamBufferInterruptDemo();\r
+       vStartMessageBufferAMPTasks();\r
 \r
        #if( configUSE_PREEMPTION != 0  )\r
        {\r
@@ -342,10 +346,28 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL );
                {\r
                        pcStatusMessage = "Error: Abort delay";\r
                }\r
+               else if( xIsInterruptStreamBufferDemoStillRunning() != pdPASS )\r
+               {\r
+                       pcStatusMessage = "Error: Stream buffer interrupt";\r
+               }\r
+               else if( xAreMessageBufferAMPTasksStillRunning() != pdPASS )\r
+               {\r
+                       pcStatusMessage = "Error: Message buffer AMP";\r
+               }\r
+\r
+               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+                       else if( xAreStaticAllocationTasksStillRunning() != pdPASS )\r
+                       {\r
+                               pcStatusMessage = "Error: Static allocation";\r
+                       }\r
+               #endif /* configSUPPORT_STATIC_ALLOCATION */\r
 \r
                /* This is the only task that uses stdout so its ok to call printf()\r
                directly. */\r
-               printf( ( char * ) "%s - %u\r\n", pcStatusMessage, ( unsigned int ) xTaskGetTickCount() );\r
+               printf( "%s - tick count %u - free heap %u - min free heap %u\r\n", pcStatusMessage,\r
+                                                                                                                                                          xTaskGetTickCount(),\r
+                                                                                                                                                          xPortGetFreeHeapSize(),\r
+                                                                                                                                                          xPortGetMinimumEverFreeHeapSize() );\r
                fflush( stdout );\r
        }\r
 }\r
@@ -454,6 +476,10 @@ TaskHandle_t xTimerTask;
        level functionality. */\r
        vPeriodicStreamBufferProcessing();\r
 \r
+       /* Writes a string to a string buffer four bytes at a time to demonstrate\r
+       a stream being sent from an interrupt to a task. */\r
+       vBasicStreamBufferSendFromISR();\r
+\r
        /* For code coverage purposes. */\r
        xTimerTask = xTimerGetTimerDaemonTaskHandle();\r
        configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );\r
index 6706629e9cbc31950b491b122ebdafd225db5376..80c976bd399aa901317dd932a5fc4c263a631035 100644 (file)
@@ -752,13 +752,23 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
                        {\r
                                traceQUEUE_SEND( pxQueue );\r
-                               xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
 \r
                                #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
+                               UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
+                                       xYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
+\r
                                        if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\r
+                                               if( ( xCopyPosition == queueOVERWRITE ) && ( uxPreviousMessagesWaiting != ( UBaseType_t ) 0 ) )\r
+                                               {\r
+                                                       /* Do not notify the queue set as an existing item\r
+                                                       was overwritten in the queue so the number of items\r
+                                                       in the queue has not changed. */\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                               else if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\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
@@ -805,6 +815,8 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                }\r
                                #else /* configUSE_QUEUE_SETS */\r
                                {\r
+                                       xYieldRequired = 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