Shop OBEX P1 Docs P2 Docs Learn Events
SD Card access problem — Parallax Forums

SD Card access problem

PyrotomPyrotom Posts: 84
edited 2008-09-16 18:05 in Propeller 1
I have used Tom Rockiki's fsrw object quite successfully in a number of my objects to read files from an SD card. But now I'm faced with a problem which may be in my understanding of Spin objects, or may be a problem with fsrw. Or may just be me... cry.gif The situation is this: I have two objects, both of which use fsrw to read files. They both work fine independently. But when I try to call both of them from a higher level object, only the first one called works. The things I would try in other languages would be to "unmount" the SD card after each use to free it up for later objects, or create the fsrw object in my high level object, mount the SD card there, and pass a reference to it down to my lower level objects to use. But I can't do the first because fsrw does not have an "unmount" method, and I don't know how to do the second, or even if it is possible.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-15 19:32
    When more than one process needs to access the same externally connected device, it is best to assign responsibility for accessing the device to a single process, then have other processes communicate to the process whenever they need access. This way you have a "clearing house" through which all accesses must occur and it can order the accesses so you do not encounter concurency issues.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-15 19:35
    This is the symptom of a general problem, that of needing an I/O driver that's callable from several different objects. It's a limitation of the object mechanism in Spin. Generally what works is to change all the working variables moving them from the VAR section where there's one instance per reference to the object into a DAT section which is only allocated once (along with the code) for all references to the object. This has been done for a version of FullDuplexSerial, but not for Rokicki's object.

    As Paul mentioned, you have to be careful when the objects involved execute on different cogs. This isn't the only way objects are used though.
  • jazzedjazzed Posts: 11,803
    edited 2008-09-15 20:21
    FSRW does not use a file handle. It appears as if you can only open one file at a time. I'm sure someone will clarify if I have this wrong [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • rokickirokicki Posts: 1,000
    edited 2008-09-15 21:29
    At this time, I do not recommend using fsrw from different cogs.

    If someone wants me to modify fsrw so it can be called from different objects within the same cog,
    that would not be too difficult (of course only one file can be open at a time right now).

    The original poster appears to simply need it to work from different objects within the same cog;
    is this correct?

    -tom
  • PyrotomPyrotom Posts: 84
    edited 2008-09-15 21:31
    Right, I know it can only have one file open at a time. I just want to be able to open files one after the other, but from different objects. My project first reads a script off of the SD card into memory. Some of the actions in the script are references to other files on the card that need to be read by a different object. There would never be more than one file open at a time. Looks like I'll just merge the objects so that all the file reads come from the same object, but that somehow feels like I'm not using the object nature of Spin the way it seems like I should.
  • Harrison.Harrison. Posts: 484
    edited 2008-09-15 23:42
    I modified fsrw to support multiple open files along with support for multiple cog use. It's not heavily tested since these modifications work for me and I don't really have time to test it throughly. Note that you must remember not to open the same file from two separate copies of the object. It is also important to remember to close all files after you are done with them.

    You can get it from harrisonpham.com/embedded/PropTCP/beta/fstest4.zip. It should be a drop in replacement for fsrw (I also added an unmount method). The file fstest.spin has an example on how to open multiple files at once (the demo just copies a file byte by byte).
  • PyrotomPyrotom Posts: 84
    edited 2008-09-16 18:05
    Very cool. Thanks!
Sign In or Register to comment.