mikaelpatel/Cosa — pull request #234 by SlashDevin (2014-08-28 15:24:15+00:00)
Title: Improve use of SD status; More flexible INIT timing

The R1 status that comes back from commands contains several error bits
and one IDLE state bit. Checking for errors involves only the error
bits.

The IDLE state bit is used to determine whether the initialization
process is completed. Some commands can be issued during the process,
but others must wait until the SD card is READY (i.e. not IDLE).

The standard allows up to 2s for the initialization process to complete.
The command can return immediately, but the process continues.

I suspect that faster cards may be READY sooner than the SEND_OP_COND
(e.g., at SEND_IF_COND), so checking the IDLE bit makes it fragile.
Again, the error bits have the error information.

To accommodate slower cards, the SEND_OP_COND must keep trying for up to
2s (i.e., 1000 * INIT_TIMEOUT). Here, I inserted a delay to pace the
retries, and to make it more immune to processor speed. It could be
changed to watch `millis()` instead.