bool SdioDmaSdCard::readBlock(void *dest,uint32_t blockIndex) { _dmaFinished=_sdioFinished=false; // enable the relevant interrupts SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR); SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR); // issue the command if(!readBlockCommand(blockIndex,BLOCK_SIZE)) return false; // use DMA to transfer the data beginRead(dest,BLOCK_SIZE); // wait for completion or error if(!waitForTransfer()) return false; // wait for the peripheral to go quiet SdCardSdioFeature::waitForReceiveComplete(); return true; }
bool SdioDmaSdCard::writeBlocks(const void *src,uint32_t blockIndex,uint32_t numBlocks) { _dmaFinished=_sdioFinished=false; // enable the relevant interrupts SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR); SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR); // issue the command if(!writeBlocksCommand(blockIndex,BLOCK_SIZE,numBlocks)) return false; // use DMA to transfer the data beginWrite(src,numBlocks*BLOCK_SIZE); // wait for completion or error and issue the stop transfer command if(!waitForTransfer() || !stopTransfer()) return false; // wait for the peripheral to go quiet SdCardSdioFeature::waitForTransmitComplete(); return true; }
bool SdioDmaSdCard::writeBlocks(const void *src,uint32_t blockIndex,uint32_t numBlocks) { const uint8_t *ptr; for(ptr=static_cast<const uint8_t *>(src);numBlocks;numBlocks--,blockIndex++,ptr+=BLOCK_SIZE) if(!writeBlock(ptr,blockIndex)) return false; return true; #if 0 _dmaFinished=_sdioFinished=false; // enable the relevant interrupts SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR); SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR); // issue the command if(!writeBlocksCommand(blockIndex,BLOCK_SIZE,numBlocks)) return false; // use DMA to transfer the data beginWrite(dest,numBlocks*BLOCK_SIZE); // wait for completion or error if(!waitForTransfer()) return false; // wait for the peripheral to go quiet SdCardSdioFeature::waitForTransmitComplete(); return true; #endif }