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


accessor func issue with file-scope variable

Posted by jinx on July 7, 2011
I am having a bizarre issue and I just want to know if it is an RTOS issue.
I have a local file-scope array static double MeasValues[NumMeas]; in a file called measurements.c
This array has individual measurements located within it such as temp, press, flow, etc.
I have an accessor function defined in this same file to provide a get_ for these measurements; an example is:

double blck_getFlowMeasurement(void)
double flow;

if(xSemaphoreTake(measMutex, portMAX_DELAY) == pdTRUE)
flow = MeasValues[Flow];


return flow;


This local variable is being updated in the measurements.c file as follows:

static void measTask( void *pvParameters )
int i;

portTickType xLastWakeTime;

xLastWakeTime = xTaskGetTickCount();

for( ;; )
if(xSemaphoreTake(measMutex, portMAX_DELAY) == pdTRUE)//updating the measurements
* 1. store these measurements locally - done
* 2. provide access to other external functions
* 3. to these values


for(i=0; i {
if(*(Measurements.MeasFuncPtr) != NULL)
ADC_Values = readADC(Measurements.adc, Measurements.adcChannel);
MeasValues = Measurements.MeasFuncPtr(countsToVolts(Measurements.adc, ADC_Values));

xSemaphoreGive(measMutex);//done updating measurements

//block until period is over
vTaskDelayUntil( &xLastWakeTime, ( MEAS_TASK_PERIOD_in_ms / portTICK_RATE_MS ) );

In another file called view.c I call this function periodically to get the value for these variables:

static void blck_viewTask( void *pvParameters )
char tmpString[20];
int hr, min, sec;
double test;


for( ;; )
//block read on RTC
blck_readRTC(&hr, &min, &sec);


sprintf(tmpString, "%2.1f\r\n", blck_getFlowMeasurement());

/* Allow the other sender task to execute. */

I am running into an issue where the values returned from the function blck_getFlowMeasurement() is 0.0.

Any ideas as to why it is not working? I also created a local variable to read this value and I get a huge random variable.

Is there something from an RTOS perspective that might be causing this?

RE: accessor func issue with file-scope variable

Posted by MEdwards on July 7, 2011
“Any ideas as to why it is not working?”

Not unless you tell us which chip you are using, which compiler you are using, and which libraries you are using for printf.


RE: accessor func issue with file-scope variable

Posted by jinx on July 7, 2011
I just did some further tinkering and it is a compiler issue. when I change it to int return values it works...

[ 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