pic32/libraries/SD/utility/Sd2Card.cpp
//------------------------------------------------------------------------------
/**
 * Read part of a 512 byte block from an SD card.
 *
 * \param[in] block Logical block to be read.
 * \param[in] offset Number of bytes to skip at start of block
 * \param[out] dst Pointer to the location that will receive the data.
 * \param[in] count Number of bytes to read
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
Read part of a 512 byte block from an SD card.
\param[in] block Logical block to be read.
\param[in] offset Number of bytes to skip at start of block
\param[out] dst Pointer to the location that will receive the data.
\param[in] count Number of bytes to read
\return The value one, true, is returned for success and
the value zero, false, is returned for failure.
Read part of a 512 byte block from an SD card . \ param [ in ] block Logical block to be read . \ param [ in ] offset Number of bytes to skip at start of block \ param [ out ] dst Pointer to the location that will receive the data . \ param [ in ] count Number of bytes to read \ return The value one true is returned for success and the value zero false is returned for failure .
uint8_t Sd2Card::readData(uint32_t block,
        uint16_t offset, uint16_t count, uint8_t* dst) {
  if (count == 0) return true;
  if ((count + offset) > 512) {
    goto fail;
  }
  if (!inBlock_ || block != block_ || offset < offset_) {
    block_ = block;
    if (type()!= SD_CARD_TYPE_SDHC) block <<= 9;
    if (cardCommand(CMD17, block)) {
      error(SD_CARD_ERROR_CMD17);
      goto fail;
    }
    if (!waitStartBlock()) {
      goto fail;
    }
    offset_ = 0;
    inBlock_ = 1;
  }
  for (;offset_ < offset; offset_++) {
    spiRec();
  }
  for (uint16_t i = 0; i < count; i++) {
    dst[i] = spiRec();
  }
  offset_ += count;
  if (!partialBlockRead_ || offset_ >= 512) {
    readEnd();
  }
  return true;
 fail:
  chipSelectHigh();
  return false;
}
uint8_t Sd2Card :: readData ( uint32_t block , uint16_t offset , uint16_t count , uint8_t * dst ) { if ( count == 0 ) return true ; if ( ( count + offset ) > 512 ) { goto fail ; } if ( ! inBlock_ || block != block_ || offset < offset_ ) { block_ = block ; if ( type ( ) != SD_CARD_TYPE_SDHC ) block <<= 9 ; if ( cardCommand ( CMD17 , block ) ) { error ( SD_CARD_ERROR_CMD17 ) ; goto fail ; } if ( ! waitStartBlock ( ) ) { goto fail ; } offset_ = 0 ; inBlock_ = 1 ; } for ( ; offset_ < offset ; offset_ ++ ) { spiRec ( ) ; } for ( uint16_t i = 0 ; i < count ; i ++ ) { dst [ i ] = spiRec ( ) ; } offset_ += count ; if ( ! partialBlockRead_ || offset_ >= 512 ) { readEnd ( ) ; } return true ; fail : chipSelectHigh ( ) ; return false ; }
Read part of a 512 byte block from an SD card.
Read part of a 512 byte block from an SD card .
// use address if not SDHC card // skip data before offset // transfer data // read rest of data, checksum and set chip select high