From bf8173c874c8e82526364a67466aca8ac85a7472 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Sat, 22 Sep 2012 20:59:27 +0000 Subject: [PATCH] Added eTaskStateGet(). 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 | 1 + FreeRTOS/Demo/WIN32-MSVC/WIN32.suo | Bin 54784 -> 54784 bytes FreeRTOS/Demo/WIN32-MSVC/main.c | 67 +++++++++++++++++++++- FreeRTOS/Source/include/FreeRTOS.h | 4 ++ FreeRTOS/Source/include/list.h | 8 +++ FreeRTOS/Source/include/task.h | 28 +++++++++ FreeRTOS/Source/tasks.c | 62 ++++++++++++++++++++ 7 files changed, 168 insertions(+), 2 deletions(-) diff --git a/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h b/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h index 28afa9a25..77e9362e8 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/WIN32-MSVC/FreeRTOSConfig.h @@ -127,6 +127,7 @@ to exclude the API function. */ #define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 #define INCLUDE_xTaskGetIdleTaskHandle 1 #define INCLUDE_pcTaskGetTaskName 1 +#define INCLUDE_eTaskStateGet 1 extern void vAssertCalled( void ); #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled() diff --git a/FreeRTOS/Demo/WIN32-MSVC/WIN32.suo b/FreeRTOS/Demo/WIN32-MSVC/WIN32.suo index 2f4e676f815705edd3324a637654cc54ad584078..76f770280317eee95bc417c236e5ea7684b0939f 100644 GIT binary patch delta 3064 zcmb_e3s98T6~6c12Mes*Wg)P<*FOI5J}=+s}QVi`I*klvgx z6MHZBo+Qh;-4%#}<4O5yL!d(_w-8SMoc;Gn_jdNs_SQMy#( z7EH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OgKbf51hT ztqO@#oN;-mQ0<@-4|IMZEKF5`|dAHqQrgl_z1ZIVot< z2+9;f&f`x_vBJ+uR;Ce9Pfr6fNjvb6u`+_5dG&LAaJTE7!<&Ux?$?a!U?!YNhgX;Kj9m6*Mi3Hz`+1?{UO z7P7e0=qCy(_qf7W!W?zkSgOLy*hq0MTP=ercoU||R-+>*fa|a#-y7|Dk+A2PJgO<~ zg%yoMd127x`{H<2hA8Blhv#gKM=~ z^jB&5Hf-oj2w04GaaWQ_XE(1x+AjZ|Qk~eg>$)5*gSChpcgN_OSTyZ%fuVK?ZF|lk zBrE_zvXVUag4V2osm>1TmS}Zce1g%jI&vIUB`+hKAxexfcxsM@t-c%KLtVTVt%EfV z^)nF>u8dJLu&a`PunbxdV)Yb-y#j~jl0P1m7?uvl+H8mYvVq%3)(@6ZjZ`^I2kTMP z7VFS;r&YrR@Zo*`95Y=mcvk5tXDk3wojWj6y)H0zR$%H2 zEvJ@mEyvkVPYU0gM3yd<33g=`aXiNC>37lH*9BYe1#Y3KQG>ZlFDUI&;)?EQq1zth z8qIbSZz#fg&G_YnhO}oB-j1F#W(@D}BHW+w3Wv?7hGsF?-3$zT6e&iIAK|d|RH9O}E!Lc33?P?UFc`fB%QWwD9p&uW zrM$7q6=cmh)UKEEg`xHt4YjJ)qF3F0(SFk;gS9phPrmM?-YBKtKqE~#3)8W+q{#z4 z_Xqi5=M**2AHd)5Dbb}R?NWi$9W(AF;4? z)l7$u^)Mw;7kF!8GiE0O*ZpvContainer == ( 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 * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() diff --git a/FreeRTOS/Source/include/task.h b/FreeRTOS/Source/include/task.h index e7a989d40..6c6be5248 100644 --- a/FreeRTOS/Source/include/task.h +++ b/FreeRTOS/Source/include/task.h @@ -131,6 +131,16 @@ typedef struct xTASK_PARAMTERS xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ]; } 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. * @@ -601,6 +611,24 @@ void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTim */ unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) PRIVILEGED_FUNCTION; +/** + * task. h + *
eTaskState eTaskStateGet( xTaskHandle pxTask );
+ * + * 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 *
void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );
diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index cb123c528..8d622939b 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -733,6 +733,68 @@ tskTCB * pxNewTCB; #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 ) unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask ) -- 2.39.5