Quality RTOS & Embedded Software

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




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists