当前位置: 首页>>代码示例>>C++>>正文


C++ chipSelectHigh函数代码示例

本文整理汇总了C++中chipSelectHigh函数的典型用法代码示例。如果您正苦于以下问题:C++ chipSelectHigh函数的具体用法?C++ chipSelectHigh怎么用?C++ chipSelectHigh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了chipSelectHigh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: error

/** Start a write multiple blocks sequence.
 *
 * \param[in] blockNumber Address of first block in sequence.
 * \param[in] eraseCount The number of blocks to be pre-erased.
 *
 * \note This function is used with writeData() and writeStop()
 * for optimized multiple block writes.
 *
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
uint8_t Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) {
#if SD_PROTECT_BLOCK_ZERO
  // don't allow write to first block
  if (blockNumber == 0) {
    error(SD_CARD_ERROR_WRITE_BLOCK_ZERO);
    goto fail;
  }
#endif  // SD_PROTECT_BLOCK_ZERO
  // send pre-erase count
  if (cardAcmd(ACMD23, eraseCount)) {
    error(SD_CARD_ERROR_ACMD23);
    goto fail;
  }
  // use address if not SDHC card
  if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
  if (cardCommand(CMD25, blockNumber)) {
    error(SD_CARD_ERROR_CMD25);
    goto fail;
  }
  return true;

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:EichenbergerFabrice,项目名称:waspmote-api-v.030,代码行数:36,代码来源:Sd2Card.cpp

示例2: while

//------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks
uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
#ifdef OPTIMIZE_HARDWARE_SPI

  // send data - optimized loop
  SPDR = token;

  // send two byte per iteration
  for (uint16_t i = 0; i < 512; i += 2) {
    while (!(SPSR & (1 << SPIF)));
    SPDR = src[i];
    while (!(SPSR & (1 << SPIF)));
    SPDR = src[i+1];
  }

  // wait for last data byte
  while (!(SPSR & (1 << SPIF)));

#else  // OPTIMIZE_HARDWARE_SPI
  spiSend(token);
  for (uint16_t i = 0; i < 512; i++) {
    spiSend(src[i]);
  }
#endif  // OPTIMIZE_HARDWARE_SPI
  spiSend(0xff);  // dummy crc
  spiSend(0xff);  // dummy crc

  status_ = spiRec();
  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
    error(SD_CARD_ERROR_WRITE);
    chipSelectHigh();
    return false;
  }
  return true;
}
开发者ID:EichenbergerFabrice,项目名称:waspmote-api-v.030,代码行数:36,代码来源:Sd2Card.cpp

示例3: error

/**
 * Writes a 512 byte block to an SD card.
 *
 * \param[in] blockNumber Logical block to be written.
 * \param[in] src Pointer to the location of the data to be written.
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
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);
        SerialDebug.println("Error: Write block zero");
        goto fail;
    }
#endif  // SD_PROTECT_BLOCK_ZERO

    // use address if not SDHC card
    if (type() != SD_CARD_TYPE_SDHC)
        blockNumber <<= 9;
    if (cardCommand(CMD24, blockNumber))
    {
        SerialDebug.println("Error: CMD24");
        error(SD_CARD_ERROR_CMD24);
        goto fail;
    }
    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);
        SerialDebug.println("Error: Write timeout");
        goto fail;
    }
    // response is r2 so get and check two bytes for nonzero
    if (cardCommand(CMD13, 0) || spiRec())
    {
        error(SD_CARD_ERROR_WRITE_PROGRAMMING);
        SerialDebug.println("Error: Write programming");
        goto fail;
    }
    chipSelectHigh();
    return true;

fail:
    chipSelectHigh();
    SerialDebug.println("Error: Sd2Card::writeBlock");
    return false;
}
开发者ID:jdkarpin,项目名称:AeroQuad,代码行数:54,代码来源:Sd2Card.cpp

示例4: while

/** Skip remaining data in a block when in partial block read mode. */
void Sd2Card::readEnd(void) {
  if (inBlock_) {
      // skip data and crc
    while (offset_++ < 514) spiRec();
    chipSelectHigh();
    inBlock_ = 0;
  }
}
开发者ID:JacobChrist,项目名称:chipKIT32-MAX,代码行数:9,代码来源:Sd2Card.cpp

示例5: error

/** read CID or CSR register */
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;
  }
  if (!waitStartBlock()) goto fail;
  // transfer data
  for (uint16_t i = 0; i < 16; i++) dst[i] = spiRec();
  spiRec();  // get first crc byte
  spiRec();  // get second crc byte
  chipSelectHigh();
  return true;

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:JacobChrist,项目名称:chipKIT32-MAX,代码行数:19,代码来源:Sd2Card.cpp

示例6: error

/** Start a write multiple blocks sequence.
 *
 * \param[in] blockNumber Address of first block in sequence.
 * \param[in] eraseCount The number of blocks to be pre-erased.
 *
 * \note This function is used with writeData() and writeStop()
 * for optimized multiple block writes.
 *
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
bool Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) {
  // send pre-erase count
  if (cardAcmd(ACMD23, eraseCount)) {
    error(SD_CARD_ERROR_ACMD23);
    goto fail;
  }
  // use address if not SDHC card
  if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;
  if (cardCommand(CMD25, blockNumber)) {
    error(SD_CARD_ERROR_CMD25);
    goto fail;
  }
  chipSelectHigh();
  return true;

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:Kazuyoko,项目名称:MarlinKimbra4due,代码行数:30,代码来源:Sd2Card.cpp

示例7: millis

//------------------------------------------------------------------------------
bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
  // wait for start block token
  uint16_t t0 = millis();
  while ((status_ = spiRec()) == 0XFF) {
    if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {
      error(SD_CARD_ERROR_READ_TIMEOUT);
      goto fail;
    }
  }
  if (status_ != DATA_START_BLOCK) {
    error(SD_CARD_ERROR_READ);
    goto fail;
  }
  // transfer data
  spiRead(dst, count);

#ifdef SD_CHECK_AND_RETRY
  {
    uint16_t calcCrc = CRC_CCITT(dst, count);
    uint16_t recvCrc = spiRec() << 8;
    recvCrc |= spiRec();
    if (calcCrc != recvCrc)
    {
        error(SD_CARD_ERROR_CRC);
        goto fail;
    }
  }
#else
  // discard CRC
  spiRec();
  spiRec();
#endif
  chipSelectHigh();
  // Send an additional dummy byte, required by Toshiba Flash Air SD Card
  spiSend(0XFF);
  return true;

 fail:
  chipSelectHigh();
  // Send an additional dummy byte, required by Toshiba Flash Air SD Card
  spiSend(0XFF);
  return false;
}
开发者ID:rollingdice,项目名称:marlin4due,代码行数:44,代码来源:Sd2Card.cpp

示例8: spiSend

/** End a write multiple blocks sequence.

    \return The value one, true, is returned for success and
    the value zero, false, is returned for failure.
*/
uint8_t Sd2Card::writeStop(void)
{
    if (!waitNotBusy(SD_WRITE_TIMEOUT))
    {
        goto fail;
    }
    spiSend(STOP_TRAN_TOKEN);
    if (!waitNotBusy(SD_WRITE_TIMEOUT))
    {
        goto fail;
    }
    chipSelectHigh();
    return true;

fail:
    error(SD_CARD_ERROR_STOP_TRAN);
    chipSelectHigh();
    return false;
}
开发者ID:rei-vilo,项目名称:SD_TM4C,代码行数:24,代码来源:Sd2Card.cpp

示例9: error

/**
 * Read a 512 byte block from an SD card device.
 *
 * \param[in] block Logical block to be read.
 * \param[out] dst Pointer to the location that will receive the data.

 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
int Sd2Card::readBlock(uint32_t block, uint8_t* dst) {
	//return readData(block, 0, 512, dst);
	unsigned int *idst;
	int i;


	if (!inBlock_ || block != block_) {
		block_ = block;
		// 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;
		}
		if (!waitStartBlock()) {
			goto fail;
		}
		offset_ = 0;
		inBlock_ = 1;
	}
		/* Do fast readout */

	idst = (unsigned int*)dst;
	for (i=128;i!=0;i--) {
		*idst++=spiRec32(wishboneSlot_);
		// USPIDATA=0xff;
		// USPIDATA=0xff;
		// USPIDATA=0xff;
		// USPIDATA=0xff;
		//*idst++=USPIDATA;
	}
	chipSelectHigh();
	inBlock_ = 0;
	return true;

fail:
	chipSelectHigh();
	return false;
}
开发者ID:GadgetFactory,项目名称:DesignLab_Examples,代码行数:48,代码来源:Sd2Card.cpp

示例10: ENABLED

/**
 * Read a 512 byte block from an SD card.
 *
 * \param[in] blockNumber Logical block to be read.
 * \param[out] dst Pointer to the location that will receive the data.
 * \return The value one, true, is returned for success and
 * the value zero, false, is returned for failure.
 */
bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
#if ENABLED(SD_CHECK_AND_RETRY)
  uint8_t retryCnt = 3;
  // use address if not SDHC card
  if (type()!= SD_CARD_TYPE_SDHC) blockNumber <<= 9;
 retry2:
  retryCnt --;
  if (cardCommand(CMD17, blockNumber)) {
    error(SD_CARD_ERROR_CMD17);
    if (retryCnt > 0) goto retry;
    goto fail;
  }
  if (!readData(dst, 512))
  {
    if (retryCnt > 0) goto retry;
    goto fail;
  }
  return true;
 retry:
   chipSelectHigh();
   cardCommand(CMD12, 0);//Try sending a stop command, but ignore the result.
   errorCode_ = 0;
   goto retry2;
#else
  // use address if not SDHC card
  if (type()!= SD_CARD_TYPE_SDHC) blockNumber <<= 9;
  if (cardCommand(CMD17, blockNumber)) {
    error(SD_CARD_ERROR_CMD17);
    goto fail;
  }
  return readData(dst, 512);
#endif

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:Kazuyoko,项目名称:MarlinKimbra4due,代码行数:45,代码来源:Sd2Card.cpp

示例11: spiSend

//------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks
uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
  spiSend(token);
  for (uint16_t i = 0; i < 512; i++) {
    spiSend(src[i]);
  }
  spiSend(0xff);  // dummy crc
  spiSend(0xff);  // dummy crc

  status_ = spiRec();
  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
    error(SD_CARD_ERROR_WRITE);
    chipSelectHigh();
    return false;
  }
  return true;
}
开发者ID:abiaozsh,项目名称:MyCode,代码行数:18,代码来源:Sd2Card.cpp

示例12: error

/**
 * 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) {
  uint16_t n;

  if (count == 0) return true;
  if ((count + offset) > 512) {
    goto fail;
  }
  if (!inBlock_ || block != block_ || offset < offset_) {
    block_ = block;
    // 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;
    }
    if (!waitStartBlock()) {
      goto fail;
    }
    offset_ = 0;
    inBlock_ = 1;
  }

  // skip data before offset
  for (;offset_ < offset; offset_++) {
    spiRec();
  }

  n = count;

  // transfer data
  for (uint16_t i = 0; i < n; i++) {
    dst[i] = spiRec();
  }

  offset_ += count;
  if (!partialBlockRead_ || offset_ >= 512) {
    // read rest of data, checksum and set chip select high
    readEnd();
  }

  return true;

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:hotemup,项目名称:chipKIT32-MAX,代码行数:57,代码来源:Sd2Card.cpp

示例13: spiSendBlock

//------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks
bool Sd2Card::writeData(uint8_t token, const uint8_t* src) {
  spiSendBlock(token, src);

  spiSend(0xff);  // dummy crc
  spiSend(0xff);  // dummy crc

  status_ = spiRec();
  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {
    error(SD_CARD_ERROR_WRITE);
    goto fail;
  }
  return true;

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:Kazuyoko,项目名称:MarlinKimbra4due,代码行数:19,代码来源:Sd2Card.cpp

示例14: while

/** Skip remaining data in a block when in partial block read mode. */
void Sd2Card::readEnd(void) {
  if (inBlock_) {
      // skip data and crc
#ifdef OPTIMIZE_HARDWARE_SPI
    // optimize skip for hardware
    SPDR = 0XFF;
    while (offset_++ < 513) {
      while (!(SPSR & (1 << SPIF)));
      SPDR = 0XFF;
    }
    // wait for last crc byte
    while (!(SPSR & (1 << SPIF)));
#else  // OPTIMIZE_HARDWARE_SPI
    while (offset_++ < 514) spiRec();
#endif  // OPTIMIZE_HARDWARE_SPI
    chipSelectHigh();
    inBlock_ = 0;
  }
}
开发者ID:cuav,项目名称:MAAT,代码行数:20,代码来源:Sd2Card.cpp

示例15: while

/** Wait for start block token */
int Sd2Card::waitStartBlock(void) {
	//unsigned t0 = millis();
	unsigned count = 30000;
	while ((status_ = spiRec()) == 0XFF) {
		if (count-- == 0) {
			error(SD_CARD_ERROR_READ_TIMEOUT);
			goto fail;
		}
	}

  if (status_ != DATA_START_BLOCK) {
    error(SD_CARD_ERROR_READ);
    goto fail;
  }
  return true;

 fail:
  chipSelectHigh();
  return false;
}
开发者ID:GadgetFactory,项目名称:DesignLab_Examples,代码行数:21,代码来源:Sd2Card.cpp


注:本文中的chipSelectHigh函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。