]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/QueueSet.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / Common / Minimal / QueueSet.c
index 34c87e1dfd9081033263fe2cad762c50c6a9185e..b82923abd3d4e4103c3848e27ec7f27aa3c657d1 100644 (file)
@@ -1,67 +1,30 @@
 /*\r
-    FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. \r
-    All rights reserved\r
-\r
-    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
-\r
-    ***************************************************************************\r
-     *                                                                       *\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
-     *    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
-     *    Thank you!                                                         *\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 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
-     *    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
-    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, 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
-    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
+ * FreeRTOS Kernel V10.0.0\r
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software. If you wish to use our Amazon\r
+ * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
 \r
 /*\r
  * Tests the use of queue sets.\r
@@ -118,7 +81,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
@@ -153,7 +116,7 @@ static void prvQueueSetReceivingTask( void *pvParameters );
  * range of the value being used to distinguish between the two message\r
  * sources.\r
  */\r
-static void prvCheckReceivedValue( unsigned long ulReceived );\r
+static void prvCheckReceivedValue( uint32_t ulReceived );\r
 \r
 /*\r
  * For purposes of test coverage, functions that read from and write to a\r
@@ -172,7 +135,7 @@ static void prvSetupTest( void );
  * Checks a value received from a queue falls within the range of expected\r
  * values.\r
  */\r
-static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived );\r
+static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived );\r
 \r
 /*\r
  * Increase test coverage by occasionally change the priorities of the two tasks\r
@@ -183,8 +146,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 unsigned long prvRand( void );\r
-static void prvSRand( unsigned long ulSeed );\r
+static size_t prvRand( void );\r
+static void prvSRand( size_t uxSeed );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -193,7 +156,7 @@ static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
 \r
 /* Counts how many times each queue in the set is used to ensure all the\r
 queues are used. */\r
-static unsigned long ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
+static uint32_t ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
 \r
 /* The handle of the queue set to which the queues are added. */\r
 static QueueSetHandle_t xQueueSet;\r
@@ -203,23 +166,23 @@ it increments ulCycleCounter on each iteration.
 xAreQueueSetTasksStillRunning() returns pdPASS if the value of\r
 ulCycleCounter has changed between consecutive calls, and pdFALSE if\r
 ulCycleCounter has stopped incrementing (indicating an error condition). */\r
-static volatile unsigned long ulCycleCounter = 0UL;\r
+static volatile uint32_t ulCycleCounter = 0UL;\r
 \r
 /* Set to pdFAIL if an error is detected by any queue set task.\r
 ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */\r
-static volatile portBASE_TYPE xQueueSetTasksStatus = pdPASS;\r
+static volatile BaseType_t xQueueSetTasksStatus = pdPASS;\r
 \r
 /* Just a flag to let the function that writes to a queue from an ISR know that\r
 the queues are setup and can be used. */\r
-static volatile portBASE_TYPE xSetupComplete = pdFALSE;\r
+static volatile BaseType_t xSetupComplete = pdFALSE;\r
 \r
 /* The value sent to the queue from the ISR is file scope so the\r
 xAreQueeuSetTasksStillRunning() function can check it is incrementing as\r
 expected. */\r
-static volatile unsigned long ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
+static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;\r
 \r
 /* Used by the pseudo random number generator. */\r
-static unsigned long 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
@@ -230,22 +193,26 @@ 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
-portBASE_TYPE xAreQueueSetTasksStillRunning( void )\r
+BaseType_t xAreQueueSetTasksStillRunning( void )\r
 {\r
-static unsigned long ulLastCycleCounter, ulLastISRTxValue = 0;\r
-static unsigned long ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
-portBASE_TYPE xReturn = pdPASS, x;\r
+static uint32_t ulLastCycleCounter, ulLastISRTxValue = 0;\r
+static uint32_t ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };\r
+BaseType_t xReturn = pdPASS, x;\r
 \r
        if( ulLastCycleCounter == ulCycleCounter )\r
        {\r
@@ -291,24 +258,25 @@ portBASE_TYPE xReturn = pdPASS, x;
 \r
 static void prvQueueSetSendingTask( void *pvParameters )\r
 {\r
-unsigned long 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( ( unsigned long ) &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
@@ -341,7 +309,7 @@ QueueHandle_t xQueueInUse;
 \r
 static void prvChangeRelativePriorities( void )\r
 {\r
-static unsigned portBASE_TYPE ulLoops = 0;\r
+static UBaseType_t ulLoops = 0;\r
 static eRelativePriorities ePriorities = eEqualPriority;\r
 \r
        /* Occasionally change the task priority relative to the priority of\r
@@ -389,8 +357,9 @@ static eRelativePriorities ePriorities = eEqualPriority;
 \r
 static void prvQueueSetReceivingTask( void *pvParameters )\r
 {\r
-unsigned long ulReceived;\r
+uint32_t ulReceived;\r
 QueueHandle_t xActivatedQueue;\r
+TickType_t xBlockTime;\r
 \r
        /* Remove compiler warnings. */\r
        ( void ) pvParameters;\r
@@ -401,14 +370,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
@@ -428,11 +411,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
@@ -440,7 +423,7 @@ QueueHandle_t xActivatedQueue;
 \r
 void vQueueSetAccessQueueSetFromISR( void )\r
 {\r
-static unsigned long ulCallCount = 0;\r
+static uint32_t ulCallCount = 0;\r
 \r
        /* xSetupComplete is set to pdTRUE when the queues have been created and\r
        are available for use. */\r
@@ -463,9 +446,9 @@ static unsigned long ulCallCount = 0;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvCheckReceivedValue( unsigned long ulReceived )\r
+static void prvCheckReceivedValue( uint32_t ulReceived )\r
 {\r
-static unsigned long ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;\r
+static uint32_t ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;\r
 \r
        /* Values are received in tasks and interrupts.  It is likely that the\r
        receiving task will sometimes get preempted by the receiving interrupt\r
@@ -543,9 +526,9 @@ static unsigned long ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR =
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static portBASE_TYPE prvCheckReceivedValueWithinExpectedRange( unsigned long ulReceived, unsigned long ulExpectedReceived )\r
+static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived )\r
 {\r
-portBASE_TYPE xReturn = pdPASS;\r
+BaseType_t xReturn = pdPASS;\r
 \r
        if( ulReceived > ulExpectedReceived )\r
        {\r
@@ -571,7 +554,7 @@ portBASE_TYPE xReturn = pdPASS;
 static void prvReceiveFromQueueInSetFromISR( void )\r
 {\r
 QueueSetMemberHandle_t xActivatedQueue;\r
-unsigned long ulReceived;\r
+uint32_t ulReceived;\r
 \r
        /* See if any of the queues in the set contain data. */\r
        xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );\r
@@ -594,14 +577,14 @@ unsigned long ulReceived;
 \r
 static void prvSendToQueueInSetFromISR( void )\r
 {\r
-static portBASE_TYPE xQueueToWriteTo = 0;\r
+static BaseType_t xQueueToWriteTo = 0;\r
+uint32_t ulTxValueSnapshot = ulISRTxValue;\r
 \r
-       if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulISRTxValue, NULL ) == pdPASS )\r
+       if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulTxValueSnapshot, NULL ) == pdPASS )\r
        {\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
@@ -619,8 +602,8 @@ static portBASE_TYPE xQueueToWriteTo = 0;
 \r
 static void prvSetupTest( void )\r
 {\r
-portBASE_TYPE x;\r
-unsigned long ulValueToSend = 0;\r
+BaseType_t x;\r
+uint32_t ulValueToSend = 0;\r
 \r
        /* Ensure the queues are created and the queue set configured before the\r
        sending task is unsuspended.\r
@@ -632,8 +615,8 @@ unsigned long ulValueToSend = 0;
        for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )\r
        {\r
                /* Create the queue and add it to the set.  The queue is just holding\r
-               unsigned long value. */\r
-               xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( unsigned long ) );\r
+               uint32_t value. */\r
+               xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( uint32_t ) );\r
                configASSERT( xQueues[ x ] );\r
                if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )\r
                {\r
@@ -701,15 +684,15 @@ unsigned long ulValueToSend = 0;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static unsigned long 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( unsigned long ulSeed )\r
+static void prvSRand( size_t uxSeed )\r
 {\r
-    ulNextRand = ulSeed;\r
+       uxNextRand = uxSeed;\r
 }\r
 \r