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

Statistics implementation PIC32 Example 18

Posted by Duncan McNamara on March 16, 2012
PIC24
MPLAB X 1.10 Mac
C30 Compiler

Following example 18 for PIC32 and making minor changes for PIC24, I am getting compiler errors. I have the addition to FreeRTOSConfig.h as:
/* The following should not be included in asm files. */
#ifdef __LANGUAGE_C__

/* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() is defined to call the
function that sets up timer 2 (T2) as the time base for the run time
statistics. T2 is a 16-bit timer and generates an interrupt when it
overflows.

portALT_GET_RUN_TIME_COUNTER_VALUE() is defined to set its parameter to
the current run time stats counter/time value. The returned timer value
is 32-bits long, and is formed by shifting the T2 overflow count into the
top two bytes of a 32-bit number, then bitwise ORing the result with the
current T2 count value. */
void vSetupTimerForRunTimeStats( void );
unsigned long ulGetRunTimeStatsCounterValue( void );
extern unsigned long ulCountValue;
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vSetupTimerForRunTimeStats()

/* T2 is 16-bits and generate an interrupt when it overflows. The
number of overflows is stored in ulTMR2OverflowCount. Thismacro
combines the current 16-bit counter value with the number of overflows
to return a 32-bit timer value. */
#define portALT_GET_RUN_TIME_COUNTER_VALUE( ulCountValue )\
{\
extern volatile unsigned long ulTMR2OverflowCount;\
unsigned long ulCountValue; \
\
/* Disconnect the clock from the counter so it does not change \
while its value is being used. */\
T2CON_VALUE = T2_OFF;\
\
/* The number of overflows is shifted into the most significant \
two bytes of the returned 32-bit value. */\
ulCountValue = ( ulTMR2OverflowCount << 16UL );\
\
/* The current T2 counter value is used as the least \
significant two bytes of the returned 32-bit value. */\
ulCountValue |= ( unsigned long ) ReadTimer2();\
\
/* Reconnect the clock to the counter. */\
T2CON_VALUE = T2_ON;\
}

#endif /* __LANGUAGE_C__ */

Note: T2CON_VALUE is being set to match comments and turn timer off at start. This define and value was all that was changed for PIC24

My error is reported in task.c as:
../../../Source/tasks.c: In function 'vTaskGetRunTimeStats':
../../../Source/tasks.c:1340: error: invalid lvalue in assignment
../../../Source/tasks.c:1340: error: invalid lvalue in assignment
../../../Source/tasks.c: In function 'vTaskSwitchContext':
../../../Source/tasks.c:1598: error: invalid lvalue in assignment
../../../Source/tasks.c:1598: error: invalid lvalue in assignment

It appears that the defined function does not appear to return an unsigned long to the caller(??).
ulCountValue was not previously defined so I have defined it globally for debugging purposes (prior to main())

Thoughts?

RE: Statistics implementation PIC32 Example 18

Posted by Richard on March 16, 2012
ulCountValue is defined - it is in the code you have posted as the parameter to the macro in the code you have posted! You have then created another copy of it inside the macro, so I'm not sure what the pre-processor and subsequently the compiler will do at all. It sounds like you then have a third global variable of the same name defined before main(), which will never get used anyway as the block scope one in the macro will shadow it.

I would suggest starting by removing the two unnecessary variables that have the same name as the macro parameter and see what that does. If you get the same error then, it must be something inside the macro that is causing it as the macro is not supposed to return an unsigned long to the caller, but assign the unsigned long to the macro parameter.

Regards.

RE: Statistics implementation PIC32 Example 18

Posted by Duncan McNamara on March 16, 2012
Richard,

Correct, these additions were evidence of my desperation and their removal put me back at start. If the result is to be the assignment of the value to the macro parameter (ulCountValue in FreeRTOSConfig.c), I assume that is passed to the variable ulTotalRunTime in task.c. I am trying to understand why this is not working and looking at C30 vs C32 compiler differences.

One other function definition I can not find code for via the new IDE is:
unsigned long ulGetRunTimeStatsCounterValue( void );
This is before the macro definition and I do not see a corresponding function

Another thought I had was that the Macro in question uses PIC24 peripheral macros and I have included a header in FreeRTOSConfig.h in hopes that that would be available to task.c if needed. Where is the macro evaluated? Should I just toggle bits and not use the externally defined macros like T2CON_VALUE?

Thanks,
Duncan

RE: Statistics implementation PIC32 Example 18

Posted by Richard on March 17, 2012
“ I am trying to understand why this is not working and looking at C30 vs C32 compiler differences.”


This is just standard C code, I would be very surprised if your problem was anything to do with a compiler difference.


“One other function definition I can not find code for via the new IDE is:
unsigned long ulGetRunTimeStatsCounterValue( void );”


That just looks like a mistake to me and that the macro portGET_RUN_TIME_COUNTER_VALUE() was originally used - which could have used the ulGetRunTimeStatsCounterValue() function, but portALT_GET_RUN_TIME_COUNTER_VALUE() does not - the prototype would be wrong for a start (the "ALT" in the macro name just means "ALTernative").

To find which line in the macro is causing the problem I would suggest temporarily converting the macro to a function. The compiler will then tell you the line the error is occurring on.

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