FSRW FAT16 routines used by two cogs
edlikestoboogie
Posts: 71
I don't know if this question has been asked or not, but my application requires two seperate cogs to open up and write/read to files on an SD CARD using fsrw1.6 . I don't want both cogs to try to open a file at once, so I made a sort of "filesystem" to facilitate requests to open files and send a stream to write. I now feel like this "filesystem" is unnecessary. Does anyone know if its safe to use FSRW on two seperate cogs? if FSRW has a file open will it abort with an error code when another cog tries to open a new file?
Thanks in advance for an answer to this quick question.
Thanks in advance for an answer to this quick question.
Comments
What kind of files do you read/write? Do they have to be readable on a PC?
I added some code that I called vMem to the FSRW which allows to read/write at random positions in up to 4 files. And you can open/read/write/close another file with the regular FSRW functions. But it requires the files to be continuous (not fragmented) and already filled with the maximum number of bytes that you want to store.
Have a look over here:
http://forums.parallax.com/forums/default.aspx?f=25&m=401244&g=401357#m401357
I have a modified version of FSRW 2.6 that uses a file handle to support multiple open files instead of using VAR to provide multiple instances.· All of the routines call a function to swap the 10 state variables with the handle variables.· I could easily add a lock to this routine to make it cog-safe if your interested.
Dave
Just keep including it for as many files as you need.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
So I am reading a bit of your code. If a cog opens a file, and another cog attempts to open another file through that one instance of SD2.0, will an abort code be returned?
You need to include the object again. Only the VAR image will be coppied for the second and third inclusion however.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Post Edited (edlikestoboogie) : 6/9/2010 5:00:38 AM GMT
OBJ
fs1: "SD2.0_FATEngine.spin"
fs2: "SD2.0_FATEngine.spin"
...
And you should only call the initializer once (The FATEngineStart function). If you then give each "fs" handle to the different cogs each one will have an exclusive file system for themselves. As in each cog will have to mount the file system and traverse directories and such to get to the file they want.
No other work is required. Both cogs then share the readonly file sytem code and the block driver. This also means that preformance will go down slightly.
... Now, I really haven't tested this stuff throughly so do so at your own risk. I will warn you that if two processors are writing to the same block or such of the file system data can become corrupted. So avoid having both processors writing at the same time... Or bad stuff may happen. For reading there will be no problems.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,