]> git.sur5r.net Git - freertos/commitdiff
Added eTaskStateGet().
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 22 Sep 2012 20:59:27 +0000 (20:59 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 22 Sep 2012 20:59:27 +0000 (20:59 +0000)
Added default value for INCLUDE_eTaskStateGet.

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

FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h
FreeRTOS/Demo/WIN32-MSVC/WIN32.suo
FreeRTOS/Demo/WIN32-MSVC/main.c
FreeRTOS/Source/include/FreeRTOS.h
FreeRTOS/Source/include/list.h
FreeRTOS/Source/include/task.h
FreeRTOS/Source/tasks.c

index 28afa9a253b5eaae0782088ab321de7e325d0473..77e9362e8c0a1590994712a7541d9382cd0161d9 100644 (file)
@@ -127,6 +127,7 @@ to exclude the API function. */
 #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1\r
 #define INCLUDE_xTaskGetIdleTaskHandle         1\r
 #define INCLUDE_pcTaskGetTaskName                      1\r
+#define INCLUDE_eTaskStateGet                          1\r
 \r
 extern void vAssertCalled( void );\r
 #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()\r
index 2f4e676f815705edd3324a637654cc54ad584078..76f770280317eee95bc417c236e5ea7684b0939f 100644 (file)
Binary files a/FreeRTOS/Demo/WIN32-MSVC/WIN32.suo and b/FreeRTOS/Demo/WIN32-MSVC/WIN32.suo differ
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
index c12f5d76fe7b8e86a2c15516ab8964fe79d7bf00..17c5c682d201767b1ce08f7c62bd1326634a1bd6 100644 (file)
@@ -165,6 +165,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * );
        #define INCLUDE_uxTaskGetStackHighWaterMark 0\r
 #endif\r
 \r
+#ifndef INCLUDE_cTaskStateGet\r
+       #define INCLUDE_cTaskStateGet 0\r
+#endif\r
+\r
 #ifndef configUSE_RECURSIVE_MUTEXES\r
        #define configUSE_RECURSIVE_MUTEXES 0\r
 #endif\r
index 28d4f248eff22577908d3adcd0559e996863e987..223b4f533515f5db6d63f7f53804c1fa87ee64f5 100644 (file)
@@ -253,6 +253,14 @@ xList * const pxConstList = ( pxList );                                                                                                    \
  */\r
 #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) )\r
 \r
+/*\r
+ * Return the list a list item is contained within (referenced from).\r
+ *\r
+ * @param pxListItem The list item being queried.\r
+ * @return A pointer to the xList object that references the pxListItem\r
+ */\r
+#define listLIST_ITEM_CONTAINED( pxListItem ) ( ( pxListItem )->pvContainer )\r
+\r
 /*\r
  * This provides a crude means of knowing if a list has been initialised, as\r
  * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()\r
index e7a989d405e6c01b5a728870d04d63c6bb43842c..6c6be5248e56092f1cfe6bda4b8306df6da304e7 100644 (file)
@@ -131,6 +131,16 @@ typedef struct xTASK_PARAMTERS
        xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];\r
 } xTaskParameters;\r
 \r
+/* Task states returned by eTaskStateGet. */\r
+typedef enum\r
+{\r
+       eRunning = 0,   /* A task is querying the state of itself, so must be running. */\r
+       eReady,                 /* The task being queried is in a read or pending ready list. */\r
+       eBlocked,               /* The task being queried is in the Blocked state. */\r
+       eSuspended,             /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */\r
+       eDeleted                /* The task being queried has been deleted, but its TCB has not yet been freed. */\r
+} eTaskState;\r
+\r
 /*\r
  * Defines the priority used by the idle task.  This must not be modified.\r
  *\r
@@ -601,6 +611,24 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim
  */\r
 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;\r
 \r
+/**\r
+ * task. h\r
+ * <pre>eTaskState eTaskStateGet( xTaskHandle pxTask );</pre>\r
+ *\r
+ * INCLUDE_eTaskStateGet must be defined as 1 for this function to be available.\r
+ * See the configuration section for more information.\r
+ *\r
+ * Obtain the state of any task.  States are encoded by the eTaskState \r
+ * enumerated type.\r
+ *\r
+ * @param pxTask Handle of the task to be queried.\r
+ *\r
+ * @return The state of pxTask at the time the function was called.  Note the\r
+ * state of the task might change between the function being called, and the\r
+ * functions return value being tested by the calling task.\r
+ */\r
+eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;\r
+\r
 /**\r
  * task. h\r
  * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>\r
index cb123c528a8143e4013f74c1459d59116ee2321f..8d622939babf8baca1649b52d0c580a1fdff00fe 100644 (file)
@@ -733,6 +733,68 @@ tskTCB * pxNewTCB;
 #endif\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( INCLUDE_eTaskStateGet == 1 )\r
+       \r
+       eTaskState eTaskStateGet( xTaskHandle pxTask )\r
+       {\r
+       eTaskState eReturn;\r
+       xList *pxStateList;\r
+       tskTCB *pxTCB;\r
+\r
+               pxTCB = ( tskTCB * ) pxTask;\r
+\r
+               if( pxTCB == pxCurrentTCB )\r
+               {\r
+                       /* The task calling this function is querying its own state. */\r
+                       eReturn = eRunning;\r
+               }\r
+               else\r
+               {\r
+                       taskENTER_CRITICAL();\r
+                       {\r
+                               pxStateList = ( xList * ) listLIST_ITEM_CONTAINED( &( pxTCB->xGenericListItem ) );\r
+                       }\r
+                       taskEXIT_CRITICAL();\r
+\r
+                       if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) )\r
+                       {\r
+                               /* The task being queried is referenced from one of the Blocked \r
+                               lists. */\r
+                               eReturn = eBlocked;\r
+                       }\r
+\r
+                       #if ( INCLUDE_vTaskSuspend == 1 )\r
+                               else if( pxStateList == &xSuspendedTaskList )\r
+                               {\r
+                                       /* The task being queried is referenced from the suspended \r
+                                       list. */\r
+                                       eReturn = eSuspended;\r
+                               }\r
+                       #endif\r
+\r
+                       #if ( INCLUDE_vTaskDelete == 1 )\r
+                               else if( pxStateList == &xTasksWaitingTermination )\r
+                               {\r
+                                       /* The task being queried is referenced from the deleted \r
+                                       tasks list. */\r
+                                       eReturn = eDeleted;\r
+                               }\r
+                       #endif\r
+\r
+                       else\r
+                       {\r
+                               /* If the task is not in any other state, it must be in the\r
+                               Ready (including pending ready) state. */\r
+                               eReturn = eReady;\r
+                       }\r
+               }\r
+\r
+               return eReturn;\r
+       }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
 #if ( INCLUDE_uxTaskPriorityGet == 1 )\r
 \r
        unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask )\r