Add xTaskGetHandle()

I needed to get the handle of a task from the number shown by vTaskList(). So I added xTaskGetHandle(). Cheers
Dirk <pre><code>
diff -pur FreeRTOS/Source/include/task.h ../../neo-lwl/FreeRTOS/Source/include/task.h
— FreeRTOS/Source/include/task.h 2009-08-09 19:55:50.000000000 +0200
+++ ../../neo-lwl/FreeRTOS/Source/include/task.h 2009-10-08 14:09:51.051501389 +0200
@@ -1058,6 +1058,11 @@ void vTaskSwitchContext( void ); xTaskHandle xTaskGetCurrentTaskHandle( void ); /* + * Return the handle of the task identified by uNumber. + */ +xTaskHandle xTaskGetTaskHandle( unsigned portBASE_TYPE uNumber );
  • +/*
  * Capture the current time status for future reference.   */ void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ); diff -pur FreeRTOS/Source/tasks.c ../../neo-lwl/FreeRTOS/Source/tasks.c
— FreeRTOS/Source/tasks.c 2009-08-09 19:55:50.000000000 +0200
+++ ../../neo-lwl/FreeRTOS/Source/tasks.c 2009-10-08 14:35:24.775001569 +0200
@@ -82,6 +82,7 @@ typedef struct tskTaskControlBlock #if ( configUSE_TRACE_FACILITY == 1 ) unsigned portBASE_TYPE uxTCBNumber; /*< This is used for tracing the scheduler and making debugging easier only. */ + xListItem xFullListItem; #endif #if ( configUSE_MUTEXES == 1 ) @@ -132,6 +133,12 @@ static xList xPendingReadyList; /* #endif + #if ( configUSE_TRACE_FACILITY == 1 )
  • + static xList xFullTaskList; /*< All tasks */
+ #endif
  • /* File private variables. ———————*/
static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0; static volatile portTickType xTickCount = ( portTickType ) 0; @@ -446,6 +453,7 @@ tskTCB * pxNewTCB; { /* Add a counter into the TCB for tracing only. */ pxNewTCB->uxTCBNumber = uxTaskNumber; + vListInsertEnd(&xFullTaskList, &pxNewTCB->xFullListItem); } #endif uxTaskNumber++; @@ -1852,6 +1860,13 @@ static void prvInitialiseTCBVariables( t
pxTCB->ulRunTimeCounter = 0UL; } #endif
  • + #if ( configUSE_TRACE_FACILITY == 1 )
+ { + vListInitialiseItem( &( pxTCB->xFullListItem ) ); + listSET_LIST_ITEM_OWNER( &( pxTCB->xFullListItem ), pxTCB ); + } + #endif } /*—————————————*/ @@ -1880,6 +1895,12 @@ unsigned portBASE_TYPE uxPriority; } #endif + #if ( configUSE_TRACE_FACILITY == 1 ) + { + vListInitialise( ( xList * ) &xFullTaskList ); + } + #endif
  • /* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList
using list2. */ pxDelayedTaskList = &xDelayedTaskList1; @@ -2222,6 +2243,29 @@ void vTaskExitCritical( void ) #endif /*—————————————*/ +#if ( configUSE_TRACE_FACILITY == 1 )
  • +xTaskHandle xTaskGetTaskHandle( unsigned portBASE_TYPE uNumber )
+{ +xTaskHandle handle = NULL; +tskTCB *pxNextTCB=NULL, *pxFirstTCB=NULL; + portENTER_CRITICAL(); + { + listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, &xFullTaskList ); + do + { + listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, &xFullTaskList ); + if ( pxNextTCB->uxTCBNumber == uNumber ) { + handle = pxNextTCB; + break; + } + } while( pxNextTCB != pxFirstTCB ); + } + portEXIT_CRITICAL(); + return handle; +}; +#endif +/*—————————————*/ </code></pre>

Add xTaskGetHandle()

Aargh.
Sending a patch to this forum does not seem that easy. What is the recommended way for sending a patch?

Add xTaskGetHandle()

I received your patch – thanks.  This needs to be made more easy for sure. Regards.