Quality RTOS & Embedded Software

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




Loading

question about vTaskList()

Posted by mastupristi on January 25, 2017

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


question about vTaskList()

Posted by rtel on January 25, 2017

...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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS