MFS and volatile variables

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MFS and volatile variables

552 次查看
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 回复

284 次查看
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 项奖励