accessor func issue with file-scope variable

oahmad2 wrote on Thursday, July 07, 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; 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;


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 <NumMeas; 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;
    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?

edwards3 wrote on Thursday, July 07, 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.

oahmad2 wrote on Thursday, July 07, 2011:

I just did some further tinkering and it is a compiler issue.  when I change it to int return values it works…