]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/QueueSet.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / Common / Minimal / QueueSet.c
index b753d109bc23b3dbdcd553fa24a52434499d7879..da688d905273c3ffe563bb66c8f209c46d786e68 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
@@ -8,29 +8,20 @@
 \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
+    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
 \r
+    ***************************************************************************\r
     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
     >>!   obliged to provide the source code for proprietary components     !<<\r
     >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\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 on the following\r
     link: http://www.freertos.org/a00114.html\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?".  Have you defined configASSERT()?  *\r
-     *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
     ***************************************************************************\r
      *                                                                       *\r
      *    FreeRTOS provides completely free yet professionally developed,    *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *   Investing in training allows your team to be as productive as       *\r
-     *   possible as early as possible, lowering your overall development    *\r
-     *   cost, and enabling you to bring a more robust product to market     *\r
-     *   earlier than would otherwise be possible.  Richard Barry is both    *\r
-     *   the architect and key author of FreeRTOS, and so also the world's   *\r
-     *   leading authority on what is the world's most popular real time     *\r
-     *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
-     *   from Richard ensures your team will gain directly from his in-depth *\r
-     *   product knowledge and years of usage experience.  Contact Real Time *\r
-     *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
-     *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
-     *                                                                       *\r
-    ***************************************************************************\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
 \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    You are receiving this top quality software for free.  Please play *\r
-     *    fair and reciprocate by reporting any suspected issues and         *\r
-     *    participating in the community forum:                              *\r
-     *    http://www.FreeRTOS.org/support                                    *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
@@ -82,7 +56,7 @@
     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
     licenses offer ticketed support, indemnification and commercial middleware.\r
 \r
@@ -148,7 +122,7 @@ queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
 /* A delay inserted when the Tx task changes its priority to be above the idle\r
 task priority to ensure the idle priority tasks get some CPU time before the\r
 next iteration of the queue set Tx task. */\r
-#define queuesetTX_LOOP_DELAY  ( 200 / portTICK_PERIOD_MS )\r
+#define queuesetTX_LOOP_DELAY  pdMS_TO_TICKS( ( TickType_t ) 200 )\r
 \r
 /* The allowable maximum deviation between a received value and the expected\r
 received value.  A deviation will occur when data is received from a queue\r
@@ -213,8 +187,8 @@ static void prvChangeRelativePriorities( void );
  * Local pseudo random number seed and return functions.  Used to avoid calls\r
  * to the standard library.\r
  */\r
-static uint32_t prvRand( void );\r
-static void prvSRand( uint32_t ulSeed );\r
+static size_t prvRand( void );\r
+static void prvSRand( size_t uxSeed );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -249,7 +223,7 @@ expected. */
 static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
 \r
 /* Used by the pseudo random number generator. */\r
-static uint32_t ulNextRand = 0;\r
+static size_t uxNextRand = 0;\r
 \r
 /* The task handles are stored so their priorities can be changed. */\r
 TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;\r
@@ -260,14 +234,18 @@ void vStartQueueSetTasks( void )
 {\r
        /* Create the tasks. */\r
        xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );\r
-       xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );\r
-\r
-       /* It is important that the sending task does not attempt to write to a\r
-       queue before the queue has been created.  It is therefore placed into the\r
-       suspended state before the scheduler has started.  It is resumed by the\r
-       receiving task after the receiving task has created the queues and added the\r
-       queues to the queue set. */\r
-       vTaskSuspend( xQueueSetSendingTask );\r
+\r
+       if( xQueueSetSendingTask != NULL )\r
+       {\r
+               xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );\r
+\r
+               /* It is important that the sending task does not attempt to write to a\r
+               queue before the queue has been created.  It is therefore placed into\r
+               the suspended state before the scheduler has started.  It is resumed by\r
+               the receiving task after the receiving task has created the queues and\r
+               added the queues to the queue set. */\r
+               vTaskSuspend( xQueueSetSendingTask );\r
+       }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -321,24 +299,25 @@ BaseType_t xReturn = pdPASS, x;
 \r
 static void prvQueueSetSendingTask( void *pvParameters )\r
 {\r
-uint32_t ulTaskTxValue = 0, ulQueueToWriteTo;\r
+uint32_t ulTaskTxValue = 0;\r
+size_t uxQueueToWriteTo;\r
 QueueHandle_t xQueueInUse;\r
 \r
        /* Remove compiler warning about the unused parameter. */\r
        ( void ) pvParameters;\r
 \r
        /* Seed mini pseudo random number generator. */\r
-       prvSRand( ( uint32_t ) &ulTaskTxValue );\r
+       prvSRand( ( size_t ) &ulTaskTxValue );\r
 \r
        for( ;; )\r
        {\r
                /* Generate the index for the queue to which a value is to be sent. */\r
-               ulQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;\r
-               xQueueInUse = xQueues[ ulQueueToWriteTo ];\r
+               uxQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;\r
+               xQueueInUse = xQueues[ uxQueueToWriteTo ];\r
 \r
                /* Note which index is being written to to ensure all the queues are\r
                used. */\r
-               ( ulQueueUsedCounter[ ulQueueToWriteTo ] )++;\r
+               ( ulQueueUsedCounter[ uxQueueToWriteTo ] )++;\r
 \r
                /* Send to the queue to unblock the task that is waiting for data to\r
                arrive on a queue within the queue set to which this queue belongs. */\r
@@ -421,6 +400,7 @@ static void prvQueueSetReceivingTask( void *pvParameters )
 {\r
 uint32_t ulReceived;\r
 QueueHandle_t xActivatedQueue;\r
+TickType_t xBlockTime;\r
 \r
        /* Remove compiler warnings. */\r
        ( void ) pvParameters;\r
@@ -431,14 +411,28 @@ QueueHandle_t xActivatedQueue;
 \r
        for( ;; )\r
        {\r
+               /* For test coverage reasons, the block time is dependent on the\r
+               priority of this task - which changes during the test.  When the task\r
+               is at the idle priority it polls the queue set. */\r
+               if( uxTaskPriorityGet( NULL ) == tskIDLE_PRIORITY )\r
+               {\r
+                       xBlockTime = 0;\r
+               }\r
+               else\r
+               {\r
+                       xBlockTime = portMAX_DELAY;\r
+               }\r
+\r
                /* Wait for a message to arrive on one of the queues in the set. */\r
                xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );\r
-               configASSERT( xActivatedQueue );\r
 \r
                if( xActivatedQueue == NULL )\r
                {\r
-                       /* This should not happen as an infinite delay was used. */\r
-                       xQueueSetTasksStatus = pdFAIL;\r
+                       if( xBlockTime != 0 )\r
+                       {\r
+                               /* This should not happen as an infinite delay was used. */\r
+                               xQueueSetTasksStatus = pdFAIL;\r
+                       }\r
                }\r
                else\r
                {\r
@@ -458,11 +452,11 @@ QueueHandle_t xActivatedQueue;
                                prvCheckReceivedValue( ulReceived );\r
                        }\r
                        taskEXIT_CRITICAL();\r
-               }\r
 \r
-               if( xQueueSetTasksStatus == pdPASS )\r
-               {\r
-                       ulCycleCounter++;\r
+                       if( xQueueSetTasksStatus == pdPASS )\r
+                       {\r
+                               ulCycleCounter++;\r
+                       }\r
                }\r
        }\r
 }\r
@@ -630,8 +624,7 @@ static BaseType_t xQueueToWriteTo = 0;
        {\r
                ulISRTxValue++;\r
 \r
-               /* If the Tx value has wrapped then set it back to its\r
-               initial value. */\r
+               /* If the Tx value has wrapped then set it back to its initial value. */\r
                if( ulISRTxValue == 0UL )\r
                {\r
                        ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
@@ -731,15 +724,15 @@ uint32_t ulValueToSend = 0;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static uint32_t prvRand( void )\r
+static size_t prvRand( void )\r
 {\r
-       ulNextRand = ( ulNextRand * 1103515245UL ) + 12345UL;\r
-    return ( ulNextRand / 65536UL ) % 32768UL;\r
+       uxNextRand = ( uxNextRand * ( size_t ) 1103515245 ) + ( size_t ) 12345;\r
+       return ( uxNextRand / ( size_t ) 65536 ) % ( size_t ) 32768;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvSRand( uint32_t ulSeed )\r
+static void prvSRand( size_t uxSeed )\r
 {\r
-    ulNextRand = ulSeed;\r
+       uxNextRand = uxSeed;\r
 }\r
 \r