PaulStoffregen преди 7 години
родител
ревизия
a6da621578
променени са 2 файла, в които са добавени 18 реда и са изтрити 13 реда
  1. +13
    -8
      utility/Sd2Card.cpp
  2. +5
    -5
      utility/Sd2Card.h

+ 13
- 8
utility/Sd2Card.cpp Целия файл

@@ -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
}
}

+ 5
- 5
utility/Sd2Card.h Целия файл

@@ -58,13 +58,13 @@ uint8_t const SPI_SCK_PIN = SCK_PIN;
/** Protect block zero from write if nonzero */
#define SD_PROTECT_BLOCK_ZERO 1
/** init timeout ms */
uint16_t const SD_INIT_TIMEOUT = 2000;
const unsigned int SD_INIT_TIMEOUT = 2000;
/** erase timeout ms */
uint16_t const SD_ERASE_TIMEOUT = 10000;
const unsigned int SD_ERASE_TIMEOUT = 10000;
/** read timeout ms */
uint16_t const SD_READ_TIMEOUT = 300;
const unsigned int SD_READ_TIMEOUT = 300;
/** write time out ms */
uint16_t const SD_WRITE_TIMEOUT = 600;
const unsigned int SD_WRITE_TIMEOUT = 600;
//------------------------------------------------------------------------------
// card types
/** Standard capacity V1 SD card */
@@ -141,7 +141,7 @@ class Sd2Card {
uint8_t sendWriteCommand(uint32_t blockNumber, uint32_t eraseCount);
void chipSelectHigh(void);
void chipSelectLow(void);
uint8_t waitNotBusy(uint16_t timeoutMillis);
uint8_t waitNotBusy(unsigned int timeoutMillis);
uint8_t writeData(uint8_t token, const uint8_t* src);
uint8_t waitStartBlock(void);
uint8_t setSckRate(uint8_t sckRateID);

Loading…
Отказ
Запис