Working Robot EEPROM Filesystem

Hey all!

During the last competition I decided to write up a filesystem for the EEPROM as something fun to do. After about a day’s worth of work, I came up with the Inverse Paradox filesystem (based on our team name :smiley: ). I thought some of you guys might find it useful or fun to play with.

I tested it quite extensively in the simulator and it should work properly 100% of the time. During the competition we stored mission critical data on it (ie, if it didn’t work, our robot would do nothing) and it worked great. We did everything from file deletions, to creating new files, and overwriting files. However I haven’t torture tested it or anything yet, and probably won’t.

A few notes though:

  1. You need Kevin’s EEPROM code for the filesystem to work!

  2. Please dump/backup your EEPROM before using the filesystem as it will overwrite any data you have in your EEPROM already.

  3. You’ll see there are some EEPROM_* functions in the filesystem.c file. These are helper functions that I added to Kevin’s code. To respect Kevin’s wishes I put them in filesystem.c rather than distribute a new eeprom.c file. You can add them to eeprom.c if you want to for aethestic reasons, just remember to add the prototypes to eeprom.h!

  4. The filesystem is blocking! This means that all writes must execute fully before the code will return to your control. This will likely timeout your controller’s GetData/PutData functions. To solve this problem, put them in a timer interrupt. I think the new default code does this already, but I’ve never used it.

  5. If anyone would like to make the filesystem non-blocking by using cached writes, please feel free to. This is a feature I was looking forward to writing, but never had the time to write.
    **
    So howto use the filesystem, with examples :smiley: :
    **

I apologize if these examples won’t compile, I just wrote them up quickly and don’t have a compiler around to test them.

  1. Format the EEPROM, then initialize the filesystem. The code below tries to initialize the FS, and if there is no FS, it’ll format the EEPROM and reinitialize. This should be done only once per powerup.


RETURN_CODE err;
err = FS_Init();

if( err == FS_ERROR_NO_FILESYSTEM ){
    FS_Format(FALSE);  /* Use TRUE instead of FALSE for a full format */
    err = FS_Init();
    if( err != FS_ERROR_SUCCESS ){
       printf("FS format and initialize failed.");  /* This should never happen */
    }
}


  1. Creating a file


RETURN_CODE err;
FILE file_id;
unsigned short file_size;

file_id = 0;  /* Akin to the file name on a PC */
file_size = 100; /* Any size between 1 and 880, if 0, no preallocation will occur */

/* Change TRUE to FALSE to not allow file overwrites */
err = File_New(file_id, file_size, TRUE);


  1. Writing a file. Remember, File_Write accepts a void pointer so you can pass it any data you want, be it structures, arrays, or even random memory locations. :stuck_out_tongue:


RETURN_CODE err;
FILE file_id;

unsigned char mydata] = "=D Cool stuff";
file_id = 0

err = File_Write(file_id, sizeof(mydata), mydata );


  1. Reading a file


RETURN_CODE err;
FILE file_id;

unsigned char mydata[13];
file_id = 0

err = File_Read(file_id, sizeof(mydata), mydata );


  1. Deleting a file


RETURN_CODE err;
FILE file_id;

file_id = 0;
err = File_Delete(file_id);


  1. Get a file size. This will return 0 if the file does not exist.


FILE file_id;
unsigned short size;

file_id = 0;
size = File_Size(file_id);


  1. Check if a file exists


BOOL isItThere;
FILE file_id;

file_id = 0;
isItThere = File_Exists(file_id);


Anyways, I hope you guys enjoy the filesystem, if anyone would like to maintain it and add more features, please do so and keep an updated copy in this thread. I will post a doc called Inverse Paradox Filesystem.doc soon, and it will explain in detail how the filesystem works internally as well as full documentation of the API and things that have yet to be implemented.

This coming September I’ll be heading to university so besides mentoring my team when I can, I won’t have much time to improve this code. I’ll be around now and again to see if there are any problems. That being said, the new controller looks awesome and you won’t need this code at all!! I’m a bit jealous. :wink:

PS, some thanks needs to goto Kevin for his awesome EEPROM code. :slight_smile:

Inverse Paradox Filesystem.doc (61 KB)
filesystem.h (1.67 KB)
filesystem.c (18.4 KB)


Inverse Paradox Filesystem.doc (61 KB)
filesystem.h (1.67 KB)
filesystem.c (18.4 KB)