Quality RTOS & Embedded Software

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




Loading

accessor func issue with file-scope variable

Posted by jinx on July 7, 2011
Hi
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];

xSemaphoreGive(measMutex);
}

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
{
/*todo
* 1. store these measurements locally - done
* 2. provide access to other external functions
* 3. to these values
*/


printDebug("\r\n");


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;


xSemaphoreTake(getRTCSemaphore(),portMAX_DELAY);

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

printDebug("viewtask\r\n");


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

/* Allow the other sender task to execute. */
//taskYIELD();
}
}



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.

http://www.freertos.org/FAQ-how-to-use-the-FreeRTOS-support-forum.html

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) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS