From c9759d5b6c54bd02a5bb114ac10122edd8e5a756 Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Sat, 5 Aug 2006 08:08:47 +0000 Subject: [PATCH] Now tries multiple times to get a Relative Card Address at startup --- source/disc_io/io_m3sd.c | 17 ++++++++++++++--- source/disc_io/io_scsd.c | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/source/disc_io/io_m3sd.c b/source/disc_io/io_m3sd.c index 5ea117b..d4151db 100644 --- a/source/disc_io/io_m3sd.c +++ b/source/disc_io/io_m3sd.c @@ -35,6 +35,9 @@ before reporting no card inserted. * Fixed writeData function to timeout on error * writeSectors function now wait until the card is ready before continuing with a transfer + + 2006-08-05 - Chishm + * Tries multiple times to get a Relative Card Address at startup */ #include "io_m3sd.h" @@ -272,9 +275,17 @@ static bool _M3SD_initCard (void) { _M3SD_getResponse_R2 (responseBuffer); // Get a new address - _M3SD_sendCommand (SEND_RELATIVE_ADDR, 0); - _M3SD_getResponse_R6 (responseBuffer); - _M3SD_relativeCardAddress = (responseBuffer[1] << 24) | (responseBuffer[2] << 16); + for (i = 0; i < MAX_STARTUP_TRIES ; i++) { + _M3SD_sendCommand (SEND_RELATIVE_ADDR, 0); + _M3SD_getResponse_R6 (responseBuffer); + _M3SD_relativeCardAddress = (responseBuffer[1] << 24) | (responseBuffer[2] << 16); + if ((responseBuffer[3] & 0x1e) != (SD_STATE_STBY << 1)) { + break; + } + } + if (i >= MAX_STARTUP_TRIES) { + return false; + } // Some cards won't go to higher speeds unless they think you checked their capabilities _M3SD_sendCommand (SEND_CSD, _M3SD_relativeCardAddress); diff --git a/source/disc_io/io_scsd.c b/source/disc_io/io_scsd.c index f4891a5..7358deb 100644 --- a/source/disc_io/io_scsd.c +++ b/source/disc_io/io_scsd.c @@ -36,6 +36,9 @@ 2006-07-25 - Chishm * Improved startup function that doesn't delay hundreds of seconds before reporting no card inserted. + + 2006-08-05 - Chishm + * Tries multiple times to get a Relative Card Address at startup */ #include "io_scsd.h" @@ -224,9 +227,17 @@ static bool _SCSD_initCard (void) { _SCSD_getResponse_R2 (responseBuffer); // Get a new address - _SCSD_sendCommand (SEND_RELATIVE_ADDR, 0); - _SCSD_getResponse_R6 (responseBuffer); - _SCSD_relativeCardAddress = (responseBuffer[1] << 24) | (responseBuffer[2] << 16); + for (i = 0; i < MAX_STARTUP_TRIES ; i++) { + _SCSD_sendCommand (SEND_RELATIVE_ADDR, 0); + _SCSD_getResponse_R6 (responseBuffer); + _SCSD_relativeCardAddress = (responseBuffer[1] << 24) | (responseBuffer[2] << 16); + if ((responseBuffer[3] & 0x1e) != (SD_STATE_STBY << 1)) { + break; + } + } + if (i >= MAX_STARTUP_TRIES) { + return false; + } // Some cards won't go to higher speeds unless they think you checked their capabilities _SCSD_sendCommand (SEND_CSD, _SCSD_relativeCardAddress);