]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/Common/Minimal/BlockQ.c
Update some standard demo task implementations so they can be used with the cooperati...
[freertos] / FreeRTOS / Demo / Common / Minimal / BlockQ.c
index a35bf0674c462b42536f826b1550755bb7614964..b9b1adb8743bd5e8595809d49288595df2447f42 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. \r
+    FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
@@ -136,7 +136,7 @@ const portTickType xBlockTime = ( portTickType ) 1000 / portTICK_RATE_MS;
 const portTickType xDontBlock = ( portTickType ) 0;\r
 \r
        /* Create the first two tasks as described at the top of the file. */\r
-       \r
+\r
        /* First create the structure used to pass parameters to the consumer tasks. */\r
        pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );\r
 \r
@@ -150,7 +150,7 @@ const portTickType xDontBlock = ( portTickType ) 0;
        /* Pass in the variable that this task is going to increment so we can check it\r
        is still running. */\r
        pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );\r
-               \r
+\r
        /* Create the structure used to pass parameters to the producer task. */\r
        pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );\r
 \r
@@ -171,7 +171,7 @@ const portTickType xDontBlock = ( portTickType ) 0;
        xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );\r
        xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );\r
 \r
-       \r
+\r
 \r
        /* Create the second two tasks as described at the top of the file.   This uses\r
        the same mechanism but reverses the task priorities. */\r
@@ -201,7 +201,7 @@ const portTickType xDontBlock = ( portTickType ) 0;
        pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );\r
        pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;\r
        pxQueueParameters6->xBlockTime = xBlockTime;\r
-       pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] ); \r
+       pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );\r
 \r
        xTaskCreate( vBlockingQueueProducer, ( signed char * ) "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );\r
        xTaskCreate( vBlockingQueueConsumer, ( signed char * ) "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );\r
@@ -217,7 +217,7 @@ short sErrorEverOccurred = pdFALSE;
        pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;\r
 \r
        for( ;; )\r
-       {               \r
+       {\r
                if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )\r
                {\r
                        sErrorEverOccurred = pdTRUE;\r
@@ -234,6 +234,10 @@ short sErrorEverOccurred = pdFALSE;
                        /* Increment the variable we are going to post next time round.  The\r
                        consumer will expect the numbers to     follow in numerical order. */\r
                        ++usValue;\r
+\r
+                       #if configUSE_PREEMPTION == 0\r
+                               taskYIELD();\r
+                       #endif\r
                }\r
        }\r
 }\r
@@ -248,7 +252,7 @@ short sErrorEverOccurred = pdFALSE;
        pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;\r
 \r
        for( ;; )\r
-       {       \r
+       {\r
                if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )\r
                {\r
                        if( usData != usExpectedValue )\r
@@ -261,17 +265,26 @@ short sErrorEverOccurred = pdFALSE;
                        else\r
                        {\r
                                /* We have successfully received a message, so increment the\r
-                               variable used to check we are still running. */ \r
+                               variable used to check we are still running. */\r
                                if( sErrorEverOccurred == pdFALSE )\r
                                {\r
                                        ( *pxQueueParameters->psCheckVariable )++;\r
                                }\r
-                                                       \r
+\r
                                /* Increment the value we expect to remove from the queue next time\r
                                round. */\r
                                ++usExpectedValue;\r
-                       }                       \r
-               }               \r
+                       }\r
+\r
+                       #if configUSE_PREEMPTION == 0\r
+                       {\r
+                               if( pxQueueParameters->xBlockTime == 0 )\r
+                               {\r
+                                       taskYIELD();\r
+                               }\r
+                       }\r
+                       #endif\r
+               }\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -286,7 +299,7 @@ portBASE_TYPE xReturn = pdPASS, xTasks;
        /* Not too worried about mutual exclusion on these variables as they are 16\r
        bits and we are only reading them. We also only care to see if they have\r
        changed or not.\r
-       \r
+\r
        Loop through each check variable to and return pdFALSE if any are found not\r
        to have changed since the last call. */\r
 \r