Ver código fonte

Delete even more never-used stuff

main
PaulStoffregen 8 anos atrás
pai
commit
e524fd7739
2 arquivos alterados com 20 adições e 116 exclusões
  1. +15
    -29
      utility/Sd2Card.cpp
  2. +5
    -87
      utility/Sd2Card.h

+ 15
- 29
utility/Sd2Card.cpp Ver arquivo

@@ -225,11 +225,10 @@ void Sd2Card::chipSelectLow(void) {
* \param[in] chipSelectPin SD chip select pin number.
*
* \return The value one, true, is returned for success and
* the value zero, false, is returned for failure. The reason for failure
* can be determined by calling errorCode() and errorData().
* the value zero, false, is returned for failure.
*/
uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
errorCode_ = type_ = 0;
type_ = 0;
chipSelectPin_ = chipSelectPin;
// 16-bit init start time allows over a minute
uint16_t t0 = (uint16_t)millis();
@@ -273,8 +272,7 @@ uint8_t Sd2Card::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) {
error(SD_CARD_ERROR_CMD0);
goto fail;
goto fail; // SD_CARD_ERROR_CMD0
}
}
// check SD version
@@ -284,8 +282,7 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
// only need last byte of r7 response
for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
if (status_ != 0XAA) {
error(SD_CARD_ERROR_CMD8);
goto fail;
goto fail; // SD_CARD_ERROR_CMD8
}
type(SD_CARD_TYPE_SD2);
}
@@ -295,15 +292,13 @@ uint8_t Sd2Card::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) {
error(SD_CARD_ERROR_ACMD41);
goto fail;
goto fail; // SD_CARD_ERROR_ACMD41
}
}
// if SD2 read OCR register to check for SDHC card
if (type() == SD_CARD_TYPE_SD2) {
if (cardCommand(CMD58, 0)) {
error(SD_CARD_ERROR_CMD58);
goto fail;
goto fail; // SD_CARD_ERROR_CMD58
}
if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);
// discard rest of ocr - contains allowed voltage range
@@ -332,8 +327,7 @@ uint8_t Sd2Card::readBlock(uint32_t block, uint8_t* dst)
// use address if not SDHC card
if (type() != SD_CARD_TYPE_SDHC) block <<= 9;
if (cardCommand(CMD17, block)) {
error(SD_CARD_ERROR_CMD17);
goto fail;
goto fail; // SD_CARD_ERROR_CMD17
}
if (!waitStartBlock()) {
goto fail;
@@ -369,8 +363,7 @@ uint8_t Sd2Card::readBlock(uint32_t block, uint8_t* dst)
uint8_t Sd2Card::readRegister(uint8_t cmd, void* buf) {
uint8_t* dst = reinterpret_cast<uint8_t*>(buf);
if (cardCommand(cmd, 0)) {
error(SD_CARD_ERROR_READ_REG);
goto fail;
goto fail; // SD_CARD_ERROR_READ_REG
}
if (!waitStartBlock()) goto fail;
// transfer data
@@ -450,13 +443,11 @@ uint8_t Sd2Card::waitStartBlock(void) {
uint16_t t0 = millis();
while ((status_ = spiRec()) == 0XFF) {
if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
error(SD_CARD_ERROR_READ_TIMEOUT);
return false;
return false; // SD_CARD_ERROR_READ_TIMEOUT
}
}
if (status_ != DATA_START_BLOCK) {
error(SD_CARD_ERROR_READ);
return false;
return false; // SD_CARD_ERROR_READ
}
return true;
}
@@ -473,28 +464,24 @@ uint8_t Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
#if SD_PROTECT_BLOCK_ZERO
// don't allow write to first block
if (blockNumber == 0) {
error(SD_CARD_ERROR_WRITE_BLOCK_ZERO);
goto fail;
goto fail; // SD_CARD_ERROR_WRITE_BLOCK_ZERO
}
#endif // SD_PROTECT_BLOCK_ZERO
// use address if not SDHC card
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
if (cardCommand(CMD24, blockNumber)) {
error(SD_CARD_ERROR_CMD24);
goto fail;
goto fail; // SD_CARD_ERROR_CMD24
}
if (!writeData(DATA_START_BLOCK, src)) goto fail;
// wait for flash programming to complete
if (!waitNotBusy(SD_WRITE_TIMEOUT)) {
error(SD_CARD_ERROR_WRITE_TIMEOUT);
goto fail;
goto fail; // SD_CARD_ERROR_WRITE_TIMEOUT
}
// response is r2 so get and check two bytes for nonzero
if (cardCommand(CMD13, 0) || spiRec()) {
error(SD_CARD_ERROR_WRITE_PROGRAMMING);
goto fail;
goto fail; // SD_CARD_ERROR_WRITE_PROGRAMMING
}
chipSelectHigh();
return true;
@@ -533,9 +520,8 @@ uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
status_ = spiRec();
if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
error(SD_CARD_ERROR_WRITE);
chipSelectHigh();
return false;
return false; // SD_CARD_ERROR_WRITE
}
return true;
}

+ 5
- 87
utility/Sd2Card.h Ver arquivo

@@ -66,52 +66,6 @@ uint16_t const SD_READ_TIMEOUT = 300;
/** write time out ms */
uint16_t const SD_WRITE_TIMEOUT = 600;
//------------------------------------------------------------------------------
// SD card errors
/** timeout error for command CMD0 */
uint8_t const SD_CARD_ERROR_CMD0 = 0X1;
/** CMD8 was not accepted - not a valid SD card*/
uint8_t const SD_CARD_ERROR_CMD8 = 0X2;
/** card returned an error response for CMD17 (read block) */
uint8_t const SD_CARD_ERROR_CMD17 = 0X3;
/** card returned an error response for CMD24 (write block) */
uint8_t const SD_CARD_ERROR_CMD24 = 0X4;
/** WRITE_MULTIPLE_BLOCKS command failed */
uint8_t const SD_CARD_ERROR_CMD25 = 0X05;
/** card returned an error response for CMD58 (read OCR) */
uint8_t const SD_CARD_ERROR_CMD58 = 0X06;
/** SET_WR_BLK_ERASE_COUNT failed */
uint8_t const SD_CARD_ERROR_ACMD23 = 0X07;
/** card's ACMD41 initialization process timeout */
uint8_t const SD_CARD_ERROR_ACMD41 = 0X08;
/** card returned a bad CSR version field */
uint8_t const SD_CARD_ERROR_BAD_CSD = 0X09;
/** erase block group command failed */
uint8_t const SD_CARD_ERROR_ERASE = 0X0A;
/** card not capable of single block erase */
uint8_t const SD_CARD_ERROR_ERASE_SINGLE_BLOCK = 0X0B;
/** Erase sequence timed out */
uint8_t const SD_CARD_ERROR_ERASE_TIMEOUT = 0X0C;
/** card returned an error token instead of read data */
uint8_t const SD_CARD_ERROR_READ = 0X0D;
/** read CID or CSD failed */
uint8_t const SD_CARD_ERROR_READ_REG = 0X0E;
/** timeout while waiting for start of read data */
uint8_t const SD_CARD_ERROR_READ_TIMEOUT = 0X0F;
/** card did not accept STOP_TRAN_TOKEN */
uint8_t const SD_CARD_ERROR_STOP_TRAN = 0X10;
/** card returned an error token as a response to a write operation */
uint8_t const SD_CARD_ERROR_WRITE = 0X11;
/** attempt to write protected block zero */
uint8_t const SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0X12;
/** card did not go ready for a multiple block write */
uint8_t const SD_CARD_ERROR_WRITE_MULTIPLE = 0X13;
/** card returned an error to a CMD13 status check after a write */
uint8_t const SD_CARD_ERROR_WRITE_PROGRAMMING = 0X14;
/** timeout occurred during write programming */
uint8_t const SD_CARD_ERROR_WRITE_TIMEOUT = 0X15;
/** incorrect rate selected */
uint8_t const SD_CARD_ERROR_SCK_RATE = 0X16;
//------------------------------------------------------------------------------
// card types
/** Standard capacity V1 SD card */
uint8_t const SD_CARD_TYPE_SD1 = 1;
@@ -127,51 +81,17 @@ uint8_t const SD_CARD_TYPE_SDHC = 3;
class Sd2Card {
public:
/** Construct an instance of Sd2Card. */
Sd2Card(void) : errorCode_(0), type_(0) {}
/**
* \return error code for last error. See Sd2Card.h for a list of error codes.
*/
uint8_t errorCode(void) const {return errorCode_;}
/** \return error data for last error. */
uint8_t errorData(void) const {return status_;}
/**
* Initialize an SD flash memory card with default clock rate and chip
* select pin. See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
*/
uint8_t init(void) {
return init(SPI_FULL_SPEED, SD_CHIP_SELECT_PIN);
}
/**
* Initialize an SD flash memory card with the selected SPI clock rate
* and the default SD chip select pin.
* See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
*/
uint8_t init(uint8_t sckRateID) {
return init(sckRateID, SD_CHIP_SELECT_PIN);
}
Sd2Card(void) : type_(0) {}
/* Initialize an SD flash memory card with the selected SPI clock rate
* and the SD chip select pin. */
uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin);
uint8_t type(void) const {return type_;}
/** Returns the current value, true or false, for partial block read. */
uint8_t readBlock(uint32_t block, uint8_t* dst);
/**
* Read a cards CID register. The CID contains card identification
* information such as Manufacturer ID, Product name, Product serial
* number and Manufacturing date. */
uint8_t readCID(cid_t* cid) {
return readRegister(CMD10, cid);
}
/**
* Read a cards CSD register. The CSD contains Card-Specific Data that
* provides information regarding access to the card's contents. */
uint8_t readCSD(csd_t* csd) {
return readRegister(CMD9, csd);
}
uint8_t setSckRate(uint8_t sckRateID);
/** Return the card type: SD V1, SD V2 or SDHC */
uint8_t type(void) const {return type_;}
uint8_t writeBlock(uint32_t blockNumber, const uint8_t* src);
private:
uint8_t chipSelectPin_;
uint8_t errorCode_;
uint8_t status_;
uint8_t type_;
// private functions
@@ -180,7 +100,6 @@ class Sd2Card {
return cardCommand(cmd, arg);
}
uint8_t cardCommand(uint8_t cmd, uint32_t arg);
void error(uint8_t code) {errorCode_ = code;}
uint8_t readRegister(uint8_t cmd, void* buf);
uint8_t sendWriteCommand(uint32_t blockNumber, uint32_t eraseCount);
void chipSelectHigh(void);
@@ -189,7 +108,6 @@ class Sd2Card {
uint8_t waitNotBusy(uint16_t timeoutMillis);
uint8_t writeData(uint8_t token, const uint8_t* src);
uint8_t waitStartBlock(void);
uint8_t readData(uint32_t block,
uint16_t offset, uint16_t count, uint8_t* dst);
uint8_t setSckRate(uint8_t sckRateID);
};
#endif // Sd2Card_h

Carregando…
Cancelar
Salvar