Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists