Shop OBEX P1 Docs P2 Docs Learn Events
purpose of timeout in fsrw driver? — Parallax Forums

purpose of timeout in fsrw driver?

agsags Posts: 386
edited 2013-07-30 22:57 in Propeller 1
Looking at the safe_spi.spin driver used by fsrw, I see there is some effort to keep track of time and automatically release the card after a timeout (defined as 125 ms).

Can someone explain the purpose of this? I don't see any such requirement in the SD specification. Is it a power saving step? Does it extend lifetime of the SD card? Is it to enable sharing the SPI bus with other devices?

Thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-30 18:10
    I assume that the timeout is there for the same reason that it's in sdspiFemto.spin. In case something happens to the SD card, the I/O call will return with an error indication so the calling code can attempt to recover or at least report the error.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-07-30 18:43
    ags wrote: »
    Looking at the safe_spi.spin driver used by fsrw, I see there is some effort to keep track of time and automatically release the card after a timeout (defined as 125 ms).

    Can someone explain the purpose of this? I don't see any such requirement in the SD specification. Is it a power saving step? Does it extend lifetime of the SD card? Is it to enable sharing the SPI bus with other devices?

    Thanks.

    Communication with an SD memory is via the SD memory controller chip which is built into every SD card along with the memory chip itself. The controller is responsible for managing the Flash memory and handling the wear levelling and mapping of bad sectors etc. Because of this the controller may take a lot longer to respond to a command and if it's really bad then too long. Since the host software is looking for a valid response then a timeout is required otherwise it is quite possible that it could be locked in an endless loop and this could also be because of an invalid sequence or because the card is stuck in block mode etc. So all the host software needs to know is if it worked or if it failed, hence the timeout.
  • agsags Posts: 386
    edited 2013-07-30 22:57
    After further thought I'm wondering if the timeout might be primarily to take the card out of block transfer mode without user intervention. The caller is not aware that the driver is setting up all transfers as multi-block, and so wouldn't be aware of the need to terminate with the appropriate command or token.

    I suppose the definitive answer will have to come from lonesock (the author).
Sign In or Register to comment.