Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Add xTaskGetHandle()

Posted by Dirk Eibach on October 8, 2009
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.h2009-08-09 19:55:50.000000000 +0200
+++ ../../neo-lwl/FreeRTOS/Source/include/task.h2009-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.c2009-08-09 19:55:50.000000000 +0200
+++ ../../neo-lwl/FreeRTOS/Source/tasks.c2009-10-08 14:35:24.775001569 +0200
@@ -82,6 +82,7 @@ typedef struct tskTaskControlBlock



#if ( configUSE_TRACE_FACILITY == 1 )

unsigned portBASE_TYPEuxTCBNumber;/*< This is used for tracing the scheduler and making debugging easier only. */

+xListItemxFullListItem;

#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>

RE: Add xTaskGetHandle()

Posted by Dirk Eibach on October 8, 2009
Aargh.
Sending a patch to this forum does not seem that easy. What is the recommended way for sending a patch?

RE: Add xTaskGetHandle()

Posted by Richard on October 9, 2009
I received your patch - thanks. This needs to be made more easy for sure.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner