Quality RTOS & Embedded Software

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


Loading

vTaskGetRunTimeStats returning odd values

Posted by specialk on June 22, 2009
I managed to get FreeRTOS working properly on a 2148 (I'm still banging my head with the interrupts on the 2478, sigh), and have set up a task to retrieve the activity stats (great new feature by the way!). I'm getting some weird results, though:

Stats319023953
IDLE42949307805317615
LEDs5146637

As you can see I only have two tasks running. According to this page (http://www.freertos.org/index.html?http://www.freertos.org/a00021.html), I was expecting activity values in %, and clearly that third column is way out of wack. Do I need to be dividng that third column by total ticks, or something similar, to get a %?

It may also be that I haven't configured the timer properly as well. This is the code I'm using is as follows, based on an example on the website, but there is one register I wasn't sure about (see comments below):

// Run Time Statistics (declared in FreeRTOSConfig.h)

#include <lpc214x.h>

#include "FreeRTOS.h"
#include "task.h"

#include "stats/stats.h"

int statsHits = 0;

void statsSetupRunTimeStats( void )
{
// ToDo: Fix this ... it isn't working at present

const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;

/* Power up and feed the timer with a clock. */
SCB_PCONP |= SCB_PCONP_PCTIM1;

// ??? (this register doesn't exist on the 2148 ... equivalent?
// SCB_PCLKSEL0 = (SCB_PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
// ???

/* Reset Timer 0 */
T1_TCR = TCR_COUNT_RESET;

/* Just count up. */
T1_CTCR = CTCR_CTM_TIMER;

/* Prescale to a frequency that is good enough to get a decent resolution,
but not too fast so as to overflow all the time. */
T1_PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;

/* Start the counter. */
T1_TCR = TCR_COUNT_ENABLE;
}

void statsEnable (void)
{
// ToDo
}

void statsDisable (void)
{
// ToDo
}

// LED Task Handler
portTASK_FUNCTION (vStatsTask, pvParameters __attribute__ ((unused)))
{
statsSetupRunTimeStats();
char statsBuffer[100];
const portTickType xStatsDelay = 500 / portTICK_RATE_MS;

for (;;)
{
vTaskGetRunTimeStats(statsBuffer);
debug_printf(statsBuffer);
statsHits++;
vTaskDelay(xStatsDelay);
}
}



RE: vTaskGetRunTimeStats returning odd values

Posted by Dave on June 22, 2009
This is a better page to view http://www.freertos.org/rtos-run-time-stats.html

Is statsBuffer big enough? Is the stack of the task big enough to hold a 100 byte buffer (do you have stack overflow checking turned on?)?

The register that is missing is providing either the power or the clock to the timer peripheral. Your timer must be running otherwise everything would be 0.

RE: vTaskGetRunTimeStats returning odd values

Posted by specialk on June 22, 2009
The buffers and stack are big enough. I was just looking through the source code for "prvGenerateRunTimeStatsForTasksInList" (tasks.c), and it should indeed be generating percentages ... I'm not really sure what's up:

The three output possibilities are:

- sprintf( pcStatsString, ( portCHAR * ) "%s\t\t0\t\t0%%\r\n", pxNextTCB->pcTaskName );
- sprintf( pcStatsString, ( portCHAR * ) "%s\t\t%u\t\t%u%%\r\n", pxNextTCB->pcTaskName, ( unsigned int ) pxNextTCB->ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );
- sprintf( pcStatsString, ( portCHAR * ) "%s\t\t%u\t\t<1%%\r\n", pxNextTCB->pcTaskName, ( unsigned int ) pxNextTCB->ulRunTimeCounter );

I'm kind of scratching my head at the output I'm getting versus what the sprintf should be spitting out (they all contain the "%" character, for example).

Kevin.

RE: vTaskGetRunTimeStats returning odd values

Posted by Richard on June 23, 2009
First I would check that the timer is incrementing at the rate you expect by simply reading the timer values into an array, maybe from within the tick interrupt. For example you could have a tick hook function that does something like:

static long lIndex = 0;
static unsigned long ulTimerValues[ 500 ] = { 0 };

void vApplicationTickHook( void )
{
____if( lIndex < 500 )
____{
________ulTimerValues[ lIndex++ ] = portGET_RUN_TIME_COUNTER_VALUE();
____}
}


configUSE_TICK_HOOK and configGENERATE_RUN_TIME_STATS would both have to be set to 1.

Second I would look at the sprintf() implementation. Many that come with embedded compilers can be cut down to the bone and may not support the format specifiers you are using.

Regards.


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner