I can not recall having seen previous questions about this.
I have a data logger with a removable SD card.
I have connected the "disk present" line of the socket to an interrupt pin.
At this moment I have to check if the switch is already released the moment the card is pressed, or if it will be released when the card is actually removed.
But I assume it will be already open contact when the card is getting pressed to be removed such that you have more time.
ISR( INT7_vect) { tEvent l_Event; // close file as fast as possible f_sync(&file1); // first make sure the file is synchronizeed f_close(&file1); // then close the file
Inside the interrupt my intention was to immediately sync and close the file
But I now realize that the LCD is also controlled through the same SPI interface and it might be that that is updated at the time of removal or worst the disk is being written.
I wonder what I should do now.
technically whenever I write to the disk I also immediately sync the file, so that it is up to date. so a close of the file is all that would remain but that still gives me a conflict
On old projects were I used an SD card I never closed a file, and always let the system crash by removing batteries.
I did always do a sync after writing and have never experienced corrupted files or crashed disks.
But there should be a somewhat nicer way to do things.
Now I have a couple of flags that indicate if the disk is present/initialized/mounted and if a file is open. these I also immediately clear in the interrupt.
but that does not solve my problem with ensuring that the file is at least synchronized.
Hope you can shed a light on this.
best thing is making it not removable, but that at this point is not an option as there is no access to this disk and we want do a readout.