# PIC32configGENERATE\_RUN\_TIME\_STATS ignorance 

**URL:** <https://forums.freertos.org/t/pic32configgenerate-run-time-stats-ignorance/4306>\
**Category:** Kernel\
**Created:** [October 25, 2011, 2:27pm UTC](https://forums.freertos.org/t/pic32configgenerate-run-time-stats-ignorance/4306 "2011-10-25T14:27:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 25, 2011, 2:27pm UTC](https://forums.freertos.org/t/pic32configgenerate-run-time-stats-ignorance/4306/1 "2011-10-25T14:27:20Z")

</div>

**[roujesky](https://sourceforge.net/u/roujesky/)** wrote on [Tuesday, October 25, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be6fd500/#9fea):

Trying to implement runtime statistics and very ignorant and low blood sugar :(&nbsp;&nbsp; Here is where I am.  
First, I modified FreeRTOS.h with the following:

#if ( configGENERATE\_RUN\_TIME\_STATS == 1 )  
#define portALT\_GET\_RUN\_TIME\_COUNTER\_VALUE 1 //NOT in ebook, but added here…&nbsp; is this right???  
/\* Neuralog specific \*/  
void vSetupTimerForRunTimeStats(void);

#define portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS() vSetupTimerForRunTimeStats()

#define portGET\_RUN\_TIME\_COUNTER\_VALUE(ulCountValue) \  
{ \  
extern volatile unsighed long ulTMR2OverflowCount; \  
T2CONCLR = T2\_ON; \  
ulCountValue = (ulTMR2OverflowCount \<\< 16UL); \  
ulCountValue |= (unsigned long) ReadTimer2(); \  
T2CONSET = T2\_ON; \  
}

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
#ifndef portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS  
#error If configGENERATE\_RUN\_TIME\_STATS is defined then portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS must also be defined.&nbsp; portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base.  
#endif /\* portCONFIGURE\_TIMER\_FOR\_RUN\_TIME\_STATS \*/

#ifndef portGET\_RUN\_TIME\_COUNTER\_VALUE  
#ifndef portALT\_GET\_RUN\_TIME\_COUNTER\_VALUE  
#error If configGENERATE\_RUN\_TIME\_STATS is defined then either portGET\_RUN\_TIME\_COUNTER\_VALUE or portALT\_GET\_RUN\_TIME\_COUNTER\_VALUE must also be defined.&nbsp; See the examples provided and the FreeRTOS web site for more information.  
#endif /\* portALT\_GET\_RUN\_TIME\_COUNTER\_VALUE \*/  
#endif /\* portGET\_RUN\_TIME\_COUNTER\_VALUE \*/

#endif /\* configGENERATE\_RUN\_TIME\_STATS \*/

when I do this, I get the error:

…\…\Source\tasks.c: In function `vTaskGetRunTimeStats’:  
…\…\Source\tasks.c:1293: error: called object is not a function  
…\…\Source\tasks.c: In function `vTaskSwitchContext’:  
…\…\Source\tasks.c:1610: error: called object is not a function

I have the PIC32 version of Using the FreeRTOS….&nbsp;&nbsp;&nbsp;

Please point out my idiocracy 🙂

thanks!

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [October 25, 2011, 3:10pm UTC](https://forums.freertos.org/t/pic32configgenerate-run-time-stats-ignorance/4306/2 "2011-10-25T15:10:00Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, October 25, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be6fd500/#1e5f):

> //NOT in ebook, but added here…&nbsp; is this right???

No - you should not be altering FreeRTOS.h at all.&nbsp; That is part of the core kernel code.&nbsp; The macros you need can be added to FreeRTOSConfig.h, which is a file used to tailor the kernel to any particular application.

If you have the PIC32 eBook, then look at section “6.5 Execution Visualization—Run Time Statistics”, it describes it, and provides source code for the PIC32.

I presume you have seen this page too?&nbsp; The other thing you can do is look in the FreeRTOS/Demo directory for demos that use run time stats on non-PIC32 devices, just to use as references (you can search/grep for the macro names in the various FreeRTOSConfig.h files).

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 25, 2011, 6:03pm UTC](https://forums.freertos.org/t/pic32configgenerate-run-time-stats-ignorance/4306/3 "2011-10-25T18:03:22Z")

</div>

**[erupter](https://sourceforge.net/u/erupter/)** wrote on [Tuesday, October 25, 2011](https://sourceforge.net/p/freertos/discussion/382005/thread/be6fd500/#5ee7):

In my FreeRTOS.h I put this

```
#if( configGENERATE_RUN_TIME_STATS )
	#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() OpenCoreTimer(800); mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0));
	//#define portGET_RUN_TIME_COUNTER_VALUE()	_CP0_GET_COUNT() 
	#define portGET_RUN_TIME_COUNTER_VALUE()	getStatsTimerCount()
	
#endif

```

then in main.c (before any code) I put this

```
#if( configGENERATE_RUN_TIME_STATS )
	unsigned long long StatsTimerCount = 0;
	
	unsigned long long getStatsTimerCount( void )
	{
		return( StatsTimerCount );
	}
	
	void __ISR(_CORE_TIMER_VECTOR, ipl2) CoreTimerHandler(void)
	{
	    // .. things to do
	
		// .. Toggle the LED
		StatsTimerCount+=1;
	    // update the period
	    UpdateCoreTimer(800);
	
	    // clear the interrupt flag
	    mCTClearIntFlag();
	}
#endif

```

then there is the StatTask definition

```
static void prvStatsTask( void *pvParameters )
{
	int mycnt=0;
	for(;;)
	{
		for( mycnt=0; mycnt<1000; mycnt++)
			mybuff[mycnt]=0;
#if( configGENERATE_RUN_TIME_STATS )
		vTaskGetRunTimeStats(mybuff);
		mycnt=999;
		while(mybuff[mycnt]==0)
			mycnt--;
		if( !(USBUSARTIsTxTrfReady()))	
			while(!(USBUSARTIsTxTrfReady()))
				vTaskDelay(50);
		putUSBUSART(mybuff,mycnt);
#endif
		Task_1_Enable = 0;
		vTaskSuspend( hTask1 );
	}
}[/code[
this task is suspended right after creation.
I have used a button to trigger the task execution.
It's designed to execute on request and auto-suspend after completition.
This has worked quite nicely for me.
The pic runs at 80MHz, the scheduler runs at 1ms.
I think it's all you need to have the stats.
I output them on the USB CDC, that's why the scheduler runs at 1ms: it fires the USB poller at that rate.
```
