MCU: TM4C1294NCPDT
TI-RTOS: v2.01.00.03
CCS: v6.0.1.0040
-
Hi,
I have an SD card connected to the MCU & the driver I am using is SDSPI. The file read/write operations I am performing are using TI-RTOS file access function (fwrite) & not elm-chan's file access functions. I have noticed that, if a file is open (in write mode) & data is being written to it (say once every second), the data written to the file after the file was opened is lost if power is withdrawn from the board.
My application requires that whenever there will be a power removal from the system, the file should be immediately saved & all written data retained (I have a power retain window of some 100 mSec or 150 mSec). On my system hardware, the NMI pin is hardwired to the power fail detection circuitry. Whenever, there is a power fail detected, the NMI pin of the MCU is pulled high & NMI interrupt gets triggered (NMI function may have 100 mSec of time to do its work).
I initially decided to keep the file handle in a global variable & whenever the NMI is triggered due to power failure, I will call fclose(file_handle) [from the NMI function]. But I wonder, what will happen if fwrite is called from a Task & while fwrite is NOT yet complete (not returned / function still running) & the fclose is triggered from the NMI function?
Can anybody suggest some good way of implementing what I am trying to implement? Or some better way than what I am planning to incorporate?
-
Thanks
-
Regards
Soumayjit