|
|
@@ -224,7 +224,7 @@ uint8_t Sd2Card::SD_init(uint8_t sckRateID, uint8_t chipSelectPin) { |
|
|
|
type_ = 0;
|
|
|
|
chipSelectPin_ = chipSelectPin;
|
|
|
|
// 16-bit init start time allows over a minute
|
|
|
|
uint16_t t0 = (uint16_t)millis();
|
|
|
|
unsigned int t0 = millis();
|
|
|
|
uint32_t arg;
|
|
|
|
|
|
|
|
digitalWrite(chipSelectPin_, HIGH);
|
|
|
@@ -264,7 +264,8 @@ uint8_t Sd2Card::SD_init(uint8_t sckRateID, uint8_t chipSelectPin) { |
|
|
|
|
|
|
|
// command to go idle in SPI mode
|
|
|
|
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
|
|
|
if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {
|
|
|
|
unsigned int d = millis() - t0;
|
|
|
|
if (d > SD_INIT_TIMEOUT) {
|
|
|
|
goto fail; // SD_CARD_ERROR_CMD0
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -284,7 +285,8 @@ uint8_t Sd2Card::SD_init(uint8_t sckRateID, uint8_t chipSelectPin) { |
|
|
|
|
|
|
|
while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
|
|
|
|
// check for timeout
|
|
|
|
if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {
|
|
|
|
unsigned int d = millis() - t0;
|
|
|
|
if (d > SD_INIT_TIMEOUT) {
|
|
|
|
goto fail; // SD_CARD_ERROR_ACMD41
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -403,20 +405,23 @@ uint8_t Sd2Card::setSckRate(uint8_t sckRateID) { |
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// wait for card to go not busy
|
|
|
|
uint8_t Sd2Card::waitNotBusy(uint16_t timeoutMillis) {
|
|
|
|
uint16_t t0 = millis();
|
|
|
|
uint8_t Sd2Card::waitNotBusy(unsigned int timeoutMillis) {
|
|
|
|
unsigned int t0 = millis();
|
|
|
|
unsigned int d;
|
|
|
|
do {
|
|
|
|
if (spiRec() == 0XFF) return true;
|
|
|
|
d = millis() - t0;
|
|
|
|
}
|
|
|
|
while (((uint16_t)millis() - t0) < timeoutMillis);
|
|
|
|
while (d < timeoutMillis);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
/** Wait for start block token */
|
|
|
|
uint8_t Sd2Card::waitStartBlock(void) {
|
|
|
|
uint16_t t0 = millis();
|
|
|
|
unsigned int t0 = millis();
|
|
|
|
while ((status_ = spiRec()) == 0XFF) {
|
|
|
|
if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
|
|
|
|
unsigned int d = millis() - t0;
|
|
|
|
if (d > SD_READ_TIMEOUT) {
|
|
|
|
return false; // SD_CARD_ERROR_READ_TIMEOUT
|
|
|
|
}
|
|
|
|
}
|