#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
/* 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
}\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
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
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
#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
*/\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
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
*/\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
#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