mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Added eTaskStateGet().
Added default value for INCLUDE_eTaskStateGet.
This commit is contained in:
parent
48a307ff5f
commit
eb1f7bc166
|
@ -127,6 +127,7 @@ to exclude the API function. */
|
||||||
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
|
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
|
||||||
#define INCLUDE_xTaskGetIdleTaskHandle 1
|
#define INCLUDE_xTaskGetIdleTaskHandle 1
|
||||||
#define INCLUDE_pcTaskGetTaskName 1
|
#define INCLUDE_pcTaskGetTaskName 1
|
||||||
|
#define INCLUDE_eTaskStateGet 1
|
||||||
|
|
||||||
extern void vAssertCalled( void );
|
extern void vAssertCalled( void );
|
||||||
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()
|
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()
|
||||||
|
|
Binary file not shown.
|
@ -133,6 +133,10 @@
|
||||||
/* Task function prototypes. */
|
/* Task function prototypes. */
|
||||||
static void prvCheckTask( void *pvParameters );
|
static void prvCheckTask( void *pvParameters );
|
||||||
|
|
||||||
|
/* A task that is created from the idle task to test the functionality of
|
||||||
|
eTaskStateGet(). */
|
||||||
|
static void prvTestTask( void *pvParameters );
|
||||||
|
|
||||||
/* The variable into which error messages are latched. */
|
/* The variable into which error messages are latched. */
|
||||||
static char *pcStatusMessage = "OK";
|
static char *pcStatusMessage = "OK";
|
||||||
|
|
||||||
|
@ -252,10 +256,28 @@ const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vApplicationIdleHook( void )
|
static void prvTestTask( void *pvParameters )
|
||||||
{
|
{
|
||||||
const unsigned long ulMSToSleep = 5;
|
const unsigned long ulMSToSleep = 5;
|
||||||
xTaskHandle xIdleTaskHandle, xTimerTaskHandle;
|
|
||||||
|
/* Just to remove compiler warnings. */
|
||||||
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* This task is just used to test the eTaskStateGet() function. It
|
||||||
|
does not have anything to do. */
|
||||||
|
for( ;; )
|
||||||
|
{
|
||||||
|
/* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
|
||||||
|
tasks waiting to be terminated by the idle task. */
|
||||||
|
Sleep( ulMSToSleep );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void vApplicationIdleHook( void )
|
||||||
|
{
|
||||||
|
const unsigned long ulMSToSleep = 15;
|
||||||
|
xTaskHandle xIdleTaskHandle, xTimerTaskHandle, xTestTask;
|
||||||
signed char *pcTaskName;
|
signed char *pcTaskName;
|
||||||
const unsigned char ucConstQueueNumber = 0xaaU, ucConstTaskNumber = 0x55U;
|
const unsigned char ucConstQueueNumber = 0xaaU, ucConstTaskNumber = 0x55U;
|
||||||
|
|
||||||
|
@ -293,6 +315,18 @@ extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
|
||||||
pcStatusMessage = "Error: Returned timer task handle was incorrect";
|
pcStatusMessage = "Error: Returned timer task handle was incorrect";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This task is running, make sure its state is returned as running. */
|
||||||
|
if( eTaskStateGet( xIdleTaskHandle ) != eRunning )
|
||||||
|
{
|
||||||
|
pcStatusMessage = "Error: Returned idle task state was incorrect";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If this task is running, then the timer task must be blocked. */
|
||||||
|
if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )
|
||||||
|
{
|
||||||
|
pcStatusMessage = "Error: Returned timer task state was incorrect";
|
||||||
|
}
|
||||||
|
|
||||||
/* If xMutexToDelete has not already been deleted, then delete it now.
|
/* If xMutexToDelete has not already been deleted, then delete it now.
|
||||||
This is done purely to demonstrate the use of, and test, the
|
This is done purely to demonstrate the use of, and test, the
|
||||||
vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
|
vSemaphoreDelete() macro. Care must be taken not to delete a semaphore
|
||||||
|
@ -311,6 +345,35 @@ extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );
|
||||||
configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );
|
configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );
|
||||||
vSemaphoreDelete( xMutexToDelete );
|
vSemaphoreDelete( xMutexToDelete );
|
||||||
xMutexToDelete = NULL;
|
xMutexToDelete = NULL;
|
||||||
|
|
||||||
|
/* Other tests that should only be performed once follow. The test task
|
||||||
|
is not created on each iteration because to do so would cause the death
|
||||||
|
task to report an error (too many tasks running). */
|
||||||
|
|
||||||
|
/* Create a test task to use to test other eTaskStateGet() return values. */
|
||||||
|
if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )
|
||||||
|
{
|
||||||
|
/* If this task is running, the test task must be in the ready state. */
|
||||||
|
if( eTaskStateGet( xTestTask ) != eReady )
|
||||||
|
{
|
||||||
|
pcStatusMessage = "Error: Returned test task state was incorrect 1";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now suspend the test task and check its state is reported correctly. */
|
||||||
|
vTaskSuspend( xTestTask );
|
||||||
|
if( eTaskStateGet( xTestTask ) != eSuspended )
|
||||||
|
{
|
||||||
|
pcStatusMessage = "Error: Returned test task state was incorrect 2";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now delete the task and check its state is reported correctly. */
|
||||||
|
vTaskDelete( xTestTask );
|
||||||
|
if( eTaskStateGet( xTestTask ) != eDeleted )
|
||||||
|
{
|
||||||
|
pcStatusMessage = "Error: Returned test task state was incorrect 3";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -165,6 +165,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * );
|
||||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
#define INCLUDE_uxTaskGetStackHighWaterMark 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef INCLUDE_cTaskStateGet
|
||||||
|
#define INCLUDE_cTaskStateGet 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef configUSE_RECURSIVE_MUTEXES
|
#ifndef configUSE_RECURSIVE_MUTEXES
|
||||||
#define configUSE_RECURSIVE_MUTEXES 0
|
#define configUSE_RECURSIVE_MUTEXES 0
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -253,6 +253,14 @@ xList * const pxConstList = ( pxList ); \
|
||||||
*/
|
*/
|
||||||
#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) )
|
#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) )
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the list a list item is contained within (referenced from).
|
||||||
|
*
|
||||||
|
* @param pxListItem The list item being queried.
|
||||||
|
* @return A pointer to the xList object that references the pxListItem
|
||||||
|
*/
|
||||||
|
#define listLIST_ITEM_CONTAINED( pxListItem ) ( ( pxListItem )->pvContainer )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This provides a crude means of knowing if a list has been initialised, as
|
* This provides a crude means of knowing if a list has been initialised, as
|
||||||
* pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()
|
* pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()
|
||||||
|
|
|
@ -131,6 +131,16 @@ typedef struct xTASK_PARAMTERS
|
||||||
xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];
|
xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];
|
||||||
} xTaskParameters;
|
} xTaskParameters;
|
||||||
|
|
||||||
|
/* Task states returned by eTaskStateGet. */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
eRunning = 0, /* A task is querying the state of itself, so must be running. */
|
||||||
|
eReady, /* The task being queried is in a read or pending ready list. */
|
||||||
|
eBlocked, /* The task being queried is in the Blocked state. */
|
||||||
|
eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
|
||||||
|
eDeleted /* The task being queried has been deleted, but its TCB has not yet been freed. */
|
||||||
|
} eTaskState;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Defines the priority used by the idle task. This must not be modified.
|
* Defines the priority used by the idle task. This must not be modified.
|
||||||
*
|
*
|
||||||
|
@ -601,6 +611,24 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim
|
||||||
*/
|
*/
|
||||||
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
|
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* task. h
|
||||||
|
* <pre>eTaskState eTaskStateGet( xTaskHandle pxTask );</pre>
|
||||||
|
*
|
||||||
|
* INCLUDE_eTaskStateGet must be defined as 1 for this function to be available.
|
||||||
|
* See the configuration section for more information.
|
||||||
|
*
|
||||||
|
* Obtain the state of any task. States are encoded by the eTaskState
|
||||||
|
* enumerated type.
|
||||||
|
*
|
||||||
|
* @param pxTask Handle of the task to be queried.
|
||||||
|
*
|
||||||
|
* @return The state of pxTask at the time the function was called. Note the
|
||||||
|
* state of the task might change between the function being called, and the
|
||||||
|
* functions return value being tested by the calling task.
|
||||||
|
*/
|
||||||
|
eTaskState eTaskStateGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* task. h
|
* task. h
|
||||||
* <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
|
* <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>
|
||||||
|
|
|
@ -733,6 +733,68 @@ tskTCB * pxNewTCB;
|
||||||
#endif
|
#endif
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if ( INCLUDE_eTaskStateGet == 1 )
|
||||||
|
|
||||||
|
eTaskState eTaskStateGet( xTaskHandle pxTask )
|
||||||
|
{
|
||||||
|
eTaskState eReturn;
|
||||||
|
xList *pxStateList;
|
||||||
|
tskTCB *pxTCB;
|
||||||
|
|
||||||
|
pxTCB = ( tskTCB * ) pxTask;
|
||||||
|
|
||||||
|
if( pxTCB == pxCurrentTCB )
|
||||||
|
{
|
||||||
|
/* The task calling this function is querying its own state. */
|
||||||
|
eReturn = eRunning;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
taskENTER_CRITICAL();
|
||||||
|
{
|
||||||
|
pxStateList = ( xList * ) listLIST_ITEM_CONTAINED( &( pxTCB->xGenericListItem ) );
|
||||||
|
}
|
||||||
|
taskEXIT_CRITICAL();
|
||||||
|
|
||||||
|
if( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) )
|
||||||
|
{
|
||||||
|
/* The task being queried is referenced from one of the Blocked
|
||||||
|
lists. */
|
||||||
|
eReturn = eBlocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ( INCLUDE_vTaskSuspend == 1 )
|
||||||
|
else if( pxStateList == &xSuspendedTaskList )
|
||||||
|
{
|
||||||
|
/* The task being queried is referenced from the suspended
|
||||||
|
list. */
|
||||||
|
eReturn = eSuspended;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ( INCLUDE_vTaskDelete == 1 )
|
||||||
|
else if( pxStateList == &xTasksWaitingTermination )
|
||||||
|
{
|
||||||
|
/* The task being queried is referenced from the deleted
|
||||||
|
tasks list. */
|
||||||
|
eReturn = eDeleted;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* If the task is not in any other state, it must be in the
|
||||||
|
Ready (including pending ready) state. */
|
||||||
|
eReturn = eReady;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return eReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#if ( INCLUDE_uxTaskPriorityGet == 1 )
|
#if ( INCLUDE_uxTaskPriorityGet == 1 )
|
||||||
|
|
||||||
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask )
|
unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask )
|
||||||
|
|
Loading…
Reference in a new issue