MFS and volatile variables

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MFS and volatile variables

1,012件の閲覧回数
infoterm
Contributor I

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);
}

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 返信

744件の閲覧回数
Fabi
Contributor III

Hi infoterm,

I'm not so familiar with MFS. But, could it be a buffer overflow issue? So could you try to limit the data_length inside the parameter_to_file() function to max. Bytes you are awaiting? I know such issues at 8 and 16 bit processors, where an 32 bit value can be illegal because of interrupted copy operation. Which processor do you use?

0 件の賞賛
返信