Aleksandar Atanasovski

MFS and volatile variables

Discussion created by Aleksandar Atanasovski on Apr 18, 2012
Latest reply on May 16, 2012 by Fabi

Hi all ,

I have an issue with MFS on SD Card file writing. I have function in which I open file (fopen()), then write into it (write()) and close file (fclose()). In that function I have several local variables defined. MFS writting only works when I declare these variables as volatile, otherwise file is not created/writen and in some situations SD card file sistem become corrupted (Windows require formating). All these problems disapears when I declare variables as volatile. Why this is happen . Is this some bug in MFS functions and interrupt handling or I make mistake. ?
For better understanding here is the part of function which not works well because not all locals are volatile :

void parameters_to_file()
{
volatile MQX_FILE_PTR fd;

int enum_id;

int_32 bytes_written;
int_32 data_length;

PARAMETERS_OBJECT* par_obj;
PARAMETER* par;
PARAMETER_DESCRIPTOR* par_desc;
PARAMETERS_OBJECT** objects;
PARAMETER** params;

int i , j , k;

enum_id = 1;

fd = fopen("c:mrk.bin","a+");

 /* write header */
strcpy((char*)&write_data, "device,");


bytes_written = write(fd,&write_data,data_length);
_time_delay(10);


// do something with variables //


fclose(fd);
}

Outcomes