]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/WIN32-MSVC/main.c
Added eTaskStateGet().
[freertos] / FreeRTOS / Demo / WIN32-MSVC / main.c
index 87332631869caa1765655d504c64389848818ab4..65acc328a4b0092580b7fa0eee404485b7b32535 100644 (file)
 /* Task function prototypes. */\r
 static void prvCheckTask( void *pvParameters );\r
 \r
+/* A task that is created from the idle task to test the functionality of \r
+eTaskStateGet(). */\r
+static void prvTestTask( void *pvParameters );\r
+\r
 /* The variable into which error messages are latched. */\r
 static char *pcStatusMessage = "OK";\r
 \r
@@ -252,10 +256,28 @@ const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationIdleHook( void )\r
+static void prvTestTask( void *pvParameters )\r
 {\r
 const unsigned long ulMSToSleep = 5;\r
-xTaskHandle xIdleTaskHandle, xTimerTaskHandle;\r
+\r
+       /* Just to remove compiler warnings. */\r
+       ( void ) pvParameters;\r
+\r
+       /* This task is just used to test the eTaskStateGet() function.  It\r
+       does not have anything to do. */\r
+       for( ;; )\r
+       {\r
+               /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
+               tasks waiting to be terminated by the idle task. */\r
+               Sleep( ulMSToSleep );\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\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
 \r
@@ -293,6 +315,18 @@ extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
                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
+\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
        vSemaphoreDelete() macro.  Care must be taken not to delete a semaphore\r
@@ -311,6 +345,35 @@ extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
                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
 }\r
 /*-----------------------------------------------------------*/\r