jeffs4653 wrote on Wednesday, May 29, 2019:
Hello, and first post here;
I have created a function that allows the user to change the “PC readable” ASCII text name of a task on the fly after it has been defined in the xTaskCreate function. I use this to modify the name of a task at different times during my application so when the task list is viewed, a better idea of what the task is doing can be determined.
However, I’ve had to place this code within tasks.c/task.h, which has obvious drawbacks and could be condsidered going against many conventions.
My post is two fold,
First, would/could there be any consideration to adding this function to FreeRTOS in future versions, as I feel it does serve a purpose.
Second, if anyone has some suggestions as to incorporate this routine from outside of tasks.c so the sanctity of the kernel is not touched, I would be most grateful. The function appears to be referencing items from within tasks.c that cannot be seen outside of it.
Included here is the code used for this function. It is basically a modification of pcgetTaskName:
void pcTaskSetName( TaskHandle_t xTaskToQuery, char *newName )
{
TCB_t *pxTCB;
/* If null is passed in here then the name of the calling task is being
queried. */
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
configASSERT( pxTCB );
strncpy(pxTCB->pcTaskName, newName, configMAX_TASK_NAME_LEN - 1);
pxTCB->pcTaskName[configMAX_TASK_NAME_LEN - 1] = 0;
}
and the associated h file content in task.h:
/**
* task. h
* <PRE>char *pcTaskSetName( TaskHandle_t xTaskToQuery, char *newName );</PRE>
*
* @return The text (human readable) name of the task referenced by the handle
* xTaskToQuery. A task can query its own name by either passing in its own
* handle, or by setting xTaskToQuery to NULL.
*
* \defgroup pcTaskGetName pcTaskGetName
* \ingroup TaskUtils
*/
void pcTaskSetName( TaskHandle_t xTaskToQuery, char *newName ) PRIVILEGED_FUNCTION;
Appreciate any thoughts.