I have a program that is writing a data file every 10 minutes to an SDCard on the RCM4300. The data file is about 200kBytes in size and all read/writes are through FAT16 (i.e. FAT16.lib). These files are also connected to a http and ftp server (i.e. http.lib and ftp_server.lib). The code works great for about 18-24 hours before failing. When it fails I can no longer access the SD card, even with a system reboot. Only option I have it to reformat the whole card.
I’ve exhausted my troubleshooting and still can’t understand or correct the issue. Here is a snippet of the writing code that is . Right before this code, I mount the SD Card. Right after this code, I un-mount it.
// Open (and maybe create) it...
rc = fat_Open(
first_part,
filename_plus,
FAT_FILE,
FAT_CREATE,
&my_file,
&prealloc
);
if (rc < 0) {
error_code = 20;
printf("Error writing Raw Data");
goto unmount_exit;
}
//Configure header details
strcpy(header,"Blah,Blah,Blah
");
len = strlen(header);
bytes = len;
rc = 0;
writ = 0;
// Keep writing header string to file until 'bytes'
// characters have been written
while (writ < bytes) {
if (len < (bytes-writ))
ltw = (int)len;
else {
ltw = (int)(bytes-writ);
header[ltw-1] = '
';
}
rc = fat_Write(&my_file, header, ltw);
if (rc > 0)
writ += rc;
if (rc < ltw)
break;
}
if (rc < 0)
printf("Error");
//Write 32000 comma delimited data points to file
for(t=0;t<32000;t++){
sprintf(obuf,"%06d
",(int)processed_datay[t]);
len = strlen(obuf);
bytes = len;
rc = 0;
writ = 0;
// Keep writing string to file until 'bytes'
// characters have been written
while (writ < bytes) {
if (len < (bytes-writ))
ltw = (int)len;
else {
ltw = (int)(bytes-writ);
obuf[ltw-1] = '
';
}
rc = fat_Write(&my_file, obuf, ltw);
if (rc > 0)
writ += rc;
if (rc < ltw)
break;
}
if (rc < 0)
printf("Error");
}
if (rc < 0) {
error_code = 20;
rc = fat_Close(&my_file);
unmount_exit;
}
// Done writing; close it.
rc = fat_Close(&my_file);