Add in the pcTaskGetTaskName(), xTaskGetIdleTaskHandle() and xTimerGetTimerTaskHandle() API functions.
diff --git a/Source/include/FreeRTOS.h b/Source/include/FreeRTOS.h
index e5eb39a..5fdbb36 100644
--- a/Source/include/FreeRTOS.h
+++ b/Source/include/FreeRTOS.h
@@ -138,6 +138,14 @@
#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 3c44904..0032a51 100644
--- a/Source/include/task.h
+++ b/Source/include/task.h
@@ -1007,6 +1007,19 @@
/**
* task. h
+ * <PRE>signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );</PRE>
+ *
+ * @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
* <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
*
* configUSE_TRACE_FACILITY must be defined as 1 for this function to be
@@ -1157,6 +1170,14 @@
*/
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 3faef90..578f05b 100644
--- a/Source/include/timers.h
+++ b/Source/include/timers.h
@@ -284,6 +284,15 @@
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 );
*
* Timer functionality is provided by a timer service/daemon task. Many of the
diff --git a/Source/tasks.c b/Source/tasks.c
index 020443d..1691497 100644
--- a/Source/tasks.c
+++ b/Source/tasks.c
@@ -157,6 +157,12 @@
#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 @@
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 @@
}
/*-----------------------------------------------------------*/
+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 @@
}
#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 7e5ef22..2d3f3ba 100644
--- a/Source/timers.c
+++ b/Source/timers.c
@@ -110,6 +110,12 @@
/* 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 @@
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 @@
}
/*-----------------------------------------------------------*/
+#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;