From 4fd10f25c4043639f2dd072be1c842be4115d906 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Wed, 27 Jul 2011 14:02:37 +0000 Subject: [PATCH] Add in the pcTaskGetTaskName(), xTaskGetIdleTaskHandle() and xTimerGetTimerTaskHandle() API functions. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1512 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Source/include/FreeRTOS.h | 8 ++++++++ Source/include/task.h | 21 ++++++++++++++++++++ Source/include/timers.h | 9 +++++++++ Source/tasks.c | 41 ++++++++++++++++++++++++++++++++++++++- Source/timers.c | 32 +++++++++++++++++++++++++++++- 5 files changed, 109 insertions(+), 2 deletions(-) diff --git a/Source/include/FreeRTOS.h b/Source/include/FreeRTOS.h index e5eb39abb..5fdbb3677 100644 --- a/Source/include/FreeRTOS.h +++ b/Source/include/FreeRTOS.h @@ -138,6 +138,14 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #error Missing definition: configUSE_16_BIT_TICKS should be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details. #endif +#ifndef INCLUDE_xTaskGetIdleTaskHandle + #define INCLUDE_xTaskGetIdleTaskHandle 0 +#endif + +#ifndef INCLUDE_xTimerGetTimerTaskHandle + #define INCLUDE_xTimerGetTimerTaskHandle 0 +#endif + #ifndef configUSE_APPLICATION_TASK_TAG #define configUSE_APPLICATION_TASK_TAG 0 #endif diff --git a/Source/include/task.h b/Source/include/task.h index 3c44904dc..0032a51c8 100644 --- a/Source/include/task.h +++ b/Source/include/task.h @@ -1005,6 +1005,19 @@ portTickType xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION; */ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION; +/** + * task. h + *
signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );
+ * + * @return The text (human readable) name of the task referenced by the handle + * xTaskToQueury. A task can query its own name by either passing in its own + * handle, or by setting xTaskToQuery to NULL. + * + * \page pcTaskGetTaskName pcTaskGetTaskName + * \ingroup TaskUtils + */ +signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery ); + /** * task. h *
void vTaskList( char *pcWriteBuffer );
@@ -1157,6 +1170,14 @@ constant. */ */ portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION; +/** + * xTaskGetIdleTaskHandle() is only available if + * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h. + * + * Simply returns the handle of the idle task. It is not valid to call + * xTaskGetIdleTaskHandle() before the scheduler has been started. + */ +xTaskHandle xTaskGetIdleTaskHandle( void ); /*----------------------------------------------------------- * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES diff --git a/Source/include/timers.h b/Source/include/timers.h index 3faef90d8..578f05b43 100644 --- a/Source/include/timers.h +++ b/Source/include/timers.h @@ -283,6 +283,15 @@ void *pvTimerGetTimerID( xTimerHandle xTimer ) PRIVILEGED_FUNCTION; */ portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer ) PRIVILEGED_FUNCTION; +/** + * xTimerGetTimerTaskHandle() is only available if + * INCLUDE_xTimerGetTimerTaskHandle is set to 1 in FreeRTOSConfig.h. + * + * Simply returns the handle of the timer service/daemon task. It it not valid + * to call xTimerGetTimerTaskHandle() before the scheduler has been started. + */ +xTaskHandle xTimerGetTimerTaskHandle( void ); + /** * portBASE_TYPE xTimerStart( xTimerHandle xTimer, portTickType xBlockTime ); * diff --git a/Source/tasks.c b/Source/tasks.c index 020443d31..16914978c 100644 --- a/Source/tasks.c +++ b/Source/tasks.c @@ -157,6 +157,12 @@ PRIVILEGED_DATA static xList xPendingReadyList; /*< Tasks that have been r #endif +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + + PRIVILEGED_DATA static xTaskHandle xIdleTaskHandle = NULL; + +#endif + /* File private variables. --------------------------------*/ PRIVILEGED_DATA static volatile unsigned portBASE_TYPE uxCurrentNumberOfTasks = ( unsigned portBASE_TYPE ) 0; PRIVILEGED_DATA static volatile portTickType xTickCount = ( portTickType ) 0; @@ -1090,7 +1096,18 @@ void vTaskStartScheduler( void ) portBASE_TYPE xReturn; /* Add the idle task at the lowest priority. */ - xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), ( xTaskHandle * ) NULL ); + #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + { + /* Create the idle task, storing its handle in xIdleTaskHandle so it can + be returned by the xTaskGetIdleTaskHandle() function. */ + xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), &xIdleTaskHandle ); + } + #else + { + /* Create the idle task without storing its handle. */ + xReturn = xTaskCreate( prvIdleTask, ( signed char * ) "IDLE", tskIDLE_STACK_SIZE, ( void * ) NULL, ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), NULL ); + } + #endif #if ( configUSE_TIMERS == 1 ) { @@ -1281,6 +1298,17 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) } /*-----------------------------------------------------------*/ +signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery ) +{ +tskTCB *pxTCB; + + /* If null is passed in here then the name of the calling task is being queried. */ + pxTCB = prvGetTCBFromHandle( xTaskToQuery ); + configASSERT( pxTCB ); + return &( pxTCB->pcTaskName[ 0 ] ); +} +/*-----------------------------------------------------------*/ + #if ( configUSE_TRACE_FACILITY == 1 ) void vTaskList( signed char *pcWriteBuffer ) @@ -1455,8 +1483,19 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) } #endif +/*----------------------------------------------------------*/ +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) + xTaskHandle xTaskGetIdleTaskHandle( void ) + { + /* If xTaskGetIdleTaskHandle() is called before the scheduler has been + started, then xIdleTaskHandle will be NULL. */ + configASSERT( ( xIdleTaskHandle != NULL ) ); + return xIdleTaskHandle; + } + +#endif /*----------------------------------------------------------- * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES diff --git a/Source/timers.c b/Source/timers.c index 7e5ef22ad..2d3f3bad8 100644 --- a/Source/timers.c +++ b/Source/timers.c @@ -110,6 +110,12 @@ PRIVILEGED_DATA static xList *pxOverflowTimerList; /* A queue that is used to send commands to the timer service task. */ PRIVILEGED_DATA static xQueueHandle xTimerQueue = NULL; +#if ( INCLUDE_xTimerGetTimerTaskHandle == 1 ) + + PRIVILEGED_DATA static xTaskHandle xTimerTaskHandle = NULL; + +#endif + /*-----------------------------------------------------------*/ /* @@ -183,7 +189,18 @@ portBASE_TYPE xReturn = pdFAIL; if( xTimerQueue != NULL ) { - xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY, NULL); + #if ( INCLUDE_xTimerGetTimerTaskHandle == 1 ) + { + /* Create the timer task, storing its handle in xTimerTaskHandle so + it can be returned by the xTimerGetTimerTaskHandle() function. */ + xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY, &xTimerTaskHandle ); + } + #else + { + /* Create the timer task without storing its handle. */ + xReturn = xTaskCreate( prvTimerTask, ( const signed char * ) "Tmr Svc", ( unsigned short ) configTIMER_TASK_STACK_DEPTH, NULL, ( unsigned portBASE_TYPE ) configTIMER_TASK_PRIORITY, NULL); + } + #endif } configASSERT( xReturn ); @@ -267,6 +284,19 @@ xTIMER_MESSAGE xMessage; } /*-----------------------------------------------------------*/ +#if ( INCLUDE_xTimerGetTimerTaskHandle == 1 ) + + xTaskHandle xTimerGetTimerTaskHandle( void ) + { + /* If xTimerGetTimerTaskHandle() is called before the scheduler has been + started, then xTimerTaskHandle will be NULL. */ + configASSERT( ( xTimerTaskHandle != NULL ) ); + return xTimerTaskHandle; + } + +#endif +/*-----------------------------------------------------------*/ + static void prvProcessExpiredTimer( portTickType xNextExpireTime, portTickType xTimeNow ) { xTIMER *pxTimer; -- 2.39.2