The first is shown in the following code which reads data from the boards FRAM external non-volatile memory into the Write_Buffer and then onto a Flash Drive.
I initially had the read/write procedure ( 2** in code) stop when the incrementing chunks ( index_Fram := Index_Fram + sizeof(Write_Buffer);) of data exceed the last valid data write given by variable Mem_Next. This mostly works. However, they could be times that mem_next is not the largest address written to as there is an option where the data written to the FRAM may overwrite old data such that the new data is overwriting in the address of older data. So in that case Mem_next may be below the address write (after the wrap around) of older data which would mean this limit would not read the older (not yet written over data).
Therefore, I thought that if I put an EOF marker at the largest used memory address and read until that marker that I would get all of the data. However, when I compile 1**. in the code, it compiles without error, but unrelated code (such as the display code) no longer works. If looks like when the procedure hits the EOF marker it should return a 1 and drop out of the loop. While it may do that, without the display working I can not tell.
If I switch back to 2**. then it all (including the display) works correctly - so I figure it must be some basic misunderstanding on my part about what the FAT32_EOF function does.
This leads to an associated question. Do I even need to insert an EOF marker at the highest/largest data recorded point in the FRAM memory and if so -
what is the EOF marker for FAT32.
The best I could find from outside sources is that it is normally 0x0fffffff - for a 32 bit EOF marker. But, it was also noted that not all FAT routines necessarily comply with that format. So does anyone know what it is for the MK PIC32 Pascal compiler??
Any suggestions welcome
Thanks folks
Code: Select all
........................
..........
fHandle := FAT32_Open(fileName,FILE_APPEND_F32}); // 15 Oct 2014
Writebuffer := @Write_Buffer; //Points to data in buffer from FRAM external non-volatile memory
if (fHandle >= 0) then // was the file opened successfully?
begin // write bytes in Writebuffer to Flash Drive
//Loop loading data (EEPROM_To_Write_Buffer) from FRAM into Write_Buffer array in
// Fram_chunk bytes size and then append ( FAT32_Open(fileName,FILE_APPEND_F32))
// to Flash Drive (FAT32_Write) File until the index pointer to FRAM equal
// or exceeds Mem_Next (last data address written)
repeat //Transfer data from FRAM to Flash Drive
EEPROM_TO_WRITE_BUFFER; // 29 Sept 2014 Get Fram_chunks bytes of FRAM data
FAT32_Write(fhandle,WriteBuffer,Fram_Chunk); // 29 Sept 2014 30 Aug 2014
1**. until (FAT32_Eof(fhandle) >= 1) ; //Transfer data until end of FRAM File - PROBLEM Here
2**. until index_FRAM >= (Mem_next); // write until all of FRAM holding data is written - WORKS
FAT32_Close(fhandle);
screen_erase;
OLED_OUT(20,2, 4,line_color,'FILE WRITTEN'); // if successful
Delay_ms(1000);
screen_Erase;
end