I have a data logging application that is writing data, and for now syncing after each write. The board has been modified to trigger an interrupt when power goes away, with a capacitor holding the circuit up for a short time. The idea is to close the files.
Originally I thought I would set a global flag in the ISR, and poll that flag each time through my loop, closing the files when the flag is true. But, there are some places in my code where it gets into different loop for a short time, but long enough to screw this plan up.
So, I am thinking its best to close the files from inside the ISR. The problem with this approach is that the ISR might get called in the middle of a write operation, leaving the file in a funny state when the close is executed. Close calls Sync(), which does not appear to depend upon any interrupts. So it seems that it is safe to call close() from inside an ISR if I can solve the first problem.
It seems the solution is to put interrupts down in the sync() method. This way, a sync can not be interrupted. It may also be necessary to do this during the write() method, so that complete non-corrupted data is added to the buffer before the sync() happens.
I would appreciate any thoughts and suggestions.