Go to Post I don't care what the team numbers said, on Friday there were no rookies there. - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 03-08-2008, 20:43
dragoonex's Avatar
dragoonex dragoonex is offline
Registered User
FRC #1325 (Inverse Paradox)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Canada
Posts: 9
dragoonex is on a distinguished road
Lightbulb 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 ). 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:

0. You need Kevin's EEPROM code for the filesystem to work!

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

2. 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!

3. 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.

4. 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 :


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.

Code:
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 */
    }
}
2. Creating a file

Code:
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);
3. 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.

Code:
RETURN_CODE err;
FILE file_id;

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

err = File_Write(file_id, sizeof(mydata), mydata );
4. Reading a file

Code:
RETURN_CODE err;
FILE file_id;

unsigned char mydata[13];
file_id = 0

err = File_Read(file_id, sizeof(mydata), mydata );
5. Deleting a file

Code:
RETURN_CODE err;
FILE file_id;

file_id = 0;
err = File_Delete(file_id);
6. Get a file size. This will return 0 if the file does not exist.

Code:
FILE file_id;
unsigned short size;

file_id = 0;
size = File_Size(file_id);
7. Check if a file exists

Code:
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.

PS, some thanks needs to goto Kevin for his awesome EEPROM code.
Attached Files
File Type: doc Inverse Paradox Filesystem.doc (61.0 KB, 275 views)
File Type: h filesystem.h (1.7 KB, 238 views)
File Type: c filesystem.c (18.4 KB, 323 views)

Last edited by dragoonex : 03-08-2008 at 22:23. Reason: Added documentation of how the filesystem works internally. I did not proofread yet. :P
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Team #1943 robot working jhallel Robot Showcase 0 21-02-2007 05:27
I've Been Working on the Robot Lyrics ipdude General Forum 1 25-01-2006 12:36
Another team's robot signal not working zeep25 Control System 2 25-02-2004 23:33
Robot Controller Not Working !?!?! Team1425 Electrical 3 24-01-2004 20:52


All times are GMT -5. The time now is 20:15.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi