Hi all,
I am successfully integrating SD card with LPC2148. Am able to read write data in .txt, .csv files. While opening and closing of file it takes too much time, fopen() takes 8ms, and fclose() takes around 68ms. Its too over for my application for writing the content it just takes the micro second so there is no issue on that. I check all the things with logical analyzer. If any one knows how to use file writing without using fclose() in SD card.I want to reduces the time,then periodically writing to the file so i dont need to close the file.
Thanks in time,
Regards, K Ganesh
Hi I have added my code I am using global variables but its simple to understand , also i put the command on each line. My code working perfect with using fclose(); but without it it cant work it create a file on path and take time for writing but nothing in the file.
void Update_Log(void) { CString l_File_Path; FILE *fRace_Log; SIM_PORT_TOG_1(); //Toggling the input pin /* Getting RTC */ Get_Real_Time(); // RTC will be updated automatically in processes l_File_Path = FUN_SDC_Get_File_Path(C_File_Type_Race); /* Opening Log files initially */ SIM_PORT_TOG_5(); fRace_Log = fopen(l_File_Path, "a+"); SIM_PORT_TOG_5(); /* Writing to the file as recommended by the customer */ { SIM_PORT_TOG_3(); /* Logging Date */ fprintf(fRace_Log,sDateLogFormat,vDateLogFormat);//Updating Date fprintf(fRace_Log,sRaceLogDelimiter); /* Logging Time */ fprintf(fRace_Log,sTimeLogFormat,vTimeLogFormat);//Updating Time fprintf(fRace_Log,sRaceLogDelimiter); fprintf(fRace_Log,"\n"); SIM_PORT_TOG_3();//Toggling 3rd pin } SIM_PORT_TOG_4(); // fclose(fRace_Log);//It takes too time SIM_PORT_TOG_4(); SIM_PORT_TOG_1(); }
Note that small writes seldom actually result in a real write - the data just gets cached. So when enough new data arrives or the program makes a fclose(), you finally get the data written to disk. Next thing here is that fclose() should do more than just write the file data - it should finalize disk allocation mappings and the directory entry too.
So your microseconds for the write isn't really the time for the write to memory card but the time for buffering your data pending a later flush of data to the memory card.
In some situations, it's possible to break up the program into one part that handles the memory card writes, and another part that runs the normal business logic. So the program can continue to do whatever should be done while the file writes are allowed to take whatever time they need in the background. In some situations, it can be meaningful to add some other memory technology, like FRAM, for instant buffering of data. And then "formalize" the data into a standard file system at a different time.