This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF: Implementing "append" functionality for a file

Part Number: CC3220SF

Hello there!

I am implementing "append" like functionality by having 2 files parallel to each other (one of them is existing temporary only).
So I create and open temp. file, copy original file content to it, append new data, close the file, delete the original,
rename the temp. to the name of deleted original file.

I am thinking about alternative solution:

I would love to keep both files all the time existing to avoid problems by creating new files again and again:

0) create temp. and original file
.... (some writing to original file will happen in mean time)
1) open temp. file for writing
2) copy original file content to temp. file
3) write new data to temp. file (aka append)
4) close temp. file
5) close original file
6) rename original file to original_old
7) rename temp. file to original
8) rename original_old to temp. file

As this means also some writings to FLASH memory, is this solution better?

I am referring here to TI documentation:

Thank you in advance for response!

Regards
Jiří

  • Hi Jiri, 

    Renaming a file will also update the FAT entry.

    If you need to use two files (let's say "file1" and "file2"), i would create a wrapper in software that will switch between the two. for example:

    at init:

        operationalFile = "file1"

        tempFile = "file2"

    append(newBuf)

    {

    read (operationalFile , buf);

    write(tempFile , buf)

    write(tempFile , newBuf);

    temp = tempFile;

    tempFile = operationalFile;

    operationalFile = temp;

    }

    The read() and write() are just for simplification. I assume you will not store the entire content in a RAM buffer and will copy small fragments of the file at each time.

    The main thing is that the name change is handled by the software to limit the FAT access.

    br,

    Kobi

  • Hello Kobi,

    thank you for very fast response and great idea!
    I will implement it based on your advice!

    Regards
    Jiří