FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [January 2017 Threads]
inthe function vTaskList() I found:
~~~
/* Write the task name to the string, padding with spaces so it
can be printed in tabular form more easily. */
pcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );
/* Write the rest of the string. */
sprintf( pcWriteBuffer, "t%ct%ut%ut%urn", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );
pcWriteBuffer += strlen( pcWriteBuffer );
~~~
I wonder why the task name is written using prvWriteNameToBuffer() and not using the subsequent sprintf with the right formatting.
And why is called strlen instead of using the output of sprintf
If I write:
~~~
pcWriteBuffer += sprintf( pcWriteBuffer, "%-*st%ct%ut%ut%urn", ( configMAXTASKNAME_LEN - 1 ), pxTaskStatusArray[ x ].pcTaskName, cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );
~~~
It works (I use gcc toolchain).
why do not use this?
best regards
Max
...because doing that in GCC can, depending on your tools, more than
double the size of your executable image, massively increase the task's
stack requirements, and unknowingly result in a call to malloc() :-)
FreeRTOS is often used with very (extremely) stripped down versions of
sprintf() (we provide some ourselves) that only provide functionality
that is actually required, use minimal stack, are thread safe, etc.. If
we relied on a full sprintf() implementation then the code would not be
portable to those applications.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.