FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [July 2011 Threads] accessor func issue with file-scope variablePosted 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 variablePosted 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 variablePosted 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...
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|