Shop OBEX P1 Docs P2 Docs Learn Events
Need help understanding return value from object — Parallax Forums

Need help understanding return value from object

Don MDon M Posts: 1,653
edited 2012-04-25 06:25 in Propeller 1
I am using FSRW in one of my programs. I wanted to modify my program to indicate if the sd card didn't mount.

I use this statement in my program:
sd.mount(0)

to mount the card with the pins starting at P0.

In the fsrw object it mentions this:
{{
'   Mount a volume.  The address passed in is passed along to the block
'   layer; see the currently used block layer for documentation.  If the
'   volume mounts, a 0 is returned, else abort is called.
}}

My program hangs if the card doesn't mount. How do I acknowledge this "abort" ? I want to display a message indicating the problem and take alternate actions.

Thanks.

Don

Comments

  • Don MDon M Posts: 1,653
    edited 2012-04-24 14:10
    I tried this but it didn't work:
    m := sd.mount(0)
      if m < 0
         term.str(string("SD card failed to mount", 13))
         abort
      else
         term.str(string("SD card mounted OK", 13))
    

    The "SD card mounted OK" message works but not the fail message.
  • NurbitNurbit Posts: 53
    edited 2012-04-24 14:15
    Hi Don
    I'm new to the prop myself but from looking at the fsrw code, I don't think sd.mount will return anything.
    I think you will need to use sd.mount_explicit if you want to get a return value.

    I have seen an object somewhere that did do a check and reported back if there was an error but I'm afraid I can't remember what it was for (I thought it was sidcog but it's not)

    Of course, being new to this, I might be completely wrong but I think you might want to use the mount_explicit version instead
  • JonnyMacJonnyMac Posts: 9,197
    edited 2012-04-24 14:19
    I think the abort codes are negative numbers in FSRW. In my code, I tend to do this:
    check := \sd.mount_explicit(SD_DO, SD_CLK, SD_DI, SD_CS)
      if (check == 0)
        com1.str(string("-- sd card mounted", CR))
        
      else
        com1.str(string("-- sd card failed to mount", CR))
        repeat
          waitcnt(0)                                                ' stop here
    


    Note the \ in front of the mount_explicit (which allows you to define the pins); this allows the abort mechanism in Spin to get back to this line cleanly.
  • Don MDon M Posts: 1,653
    edited 2012-04-24 14:21
    Hi Nurbit-

    Actually calling sd.mount(0) passes the the first pin (0) to the sd.mount_explicit method. mount_explicit is the method that contains the dialouge about a "0" being returned if it mounts and an abort if not that I mentioned above.
  • NurbitNurbit Posts: 53
    edited 2012-04-24 14:26
    ah, fair enough

    Like I said, I'm new to the prop and spin so I make most of it up in my head :)
  • Don MDon M Posts: 1,653
    edited 2012-04-24 14:35
    Jon-

    Thanks. That works. At first I tried this:
    m := sd.mount(0)
      if m == 0
         term.str(string("SD card mounted OK", 13))
      else
         term.str(string("SD card failed to mount", 13))
         repeat
           waitcnt(0) 
    

    but it didn't work. When I changed it to this:
    m := \sd.mount_explicit(SD_DO, SD_CLK, SD_DI, SD_CS) 
      if m == 0
         term.str(string("SD card mounted OK", 13))
      else
         term.str(string("SD card failed to mount", 13))
         repeat
           waitcnt(0)
    

    then it does work.

    So I guess it has to do with your comment "this allows the abort mechanism in Spin to get back to this line cleanly". Why does it work that way? Is it because the first way: sd.mount(0) goes through to sd.mount_explicit and the abort does not get passed back through the sd.mount?
  • kuronekokuroneko Posts: 3,623
    edited 2012-04-24 23:27
    In your first example (sd.mount(0)) you don't actually catch the abort. You should precede the method call with a backslash (abort trap) like you did in the second example. Other than that mount() is just an easier form of mount_explicit().
  • Don MDon M Posts: 1,653
    edited 2012-04-25 06:25
    That does work. Thanks!
Sign In or Register to comment.