software/liblitesdcard: Add SDCARD_CMD18_SUPPORT #define to allow disabling/enabling Multiple Block Reads.

Also use Single Block Read when only 1 block to read, avoid stop transmission.
This commit is contained in:
Florent Kermarrec 2021-04-09 19:17:32 +02:00
parent 9bec0ce7a2
commit 5cdf621367
1 changed files with 33 additions and 14 deletions

View File

@ -21,7 +21,8 @@
#ifdef CSR_SDCORE_BASE #ifdef CSR_SDCORE_BASE
//#define SDCARD_DEBUG //#define SDCARD_DEBUG
//#define SDCARD_CMD23_SUPPORT //#define SDCARD_CMD23_SUPPORT /* SET_BLOCK_COUNT */
#define SDCARD_CMD18_SUPPORT /* READ_MULTIPLE_BLOCK */
#ifndef SDCARD_CLK_FREQ_INIT #ifndef SDCARD_CLK_FREQ_INIT
#define SDCARD_CLK_FREQ_INIT 400000 #define SDCARD_CLK_FREQ_INIT 400000
@ -473,22 +474,40 @@ int sdcard_init(void) {
void sdcard_read(uint32_t block, uint32_t count, uint8_t* buf) void sdcard_read(uint32_t block, uint32_t count, uint8_t* buf)
{ {
/* Initialize DMA Writer */ while (count) {
sdblock2mem_dma_enable_write(0); uint32_t nblocks;
sdblock2mem_dma_base_write((uint64_t)(uintptr_t) buf); #ifdef SDCARD_CMD18_SUPPORT
sdblock2mem_dma_length_write(512*count); nblocks = count;
sdblock2mem_dma_enable_write(1); #else
nblocks = 1;
/* Read Block(s) from SDCard */
#ifdef SDCARD_CMD23_SUPPORT
sdcard_set_block_count(count);
#endif #endif
sdcard_read_multiple_block(block, count); /* Initialize DMA Writer */
sdblock2mem_dma_enable_write(0);
sdblock2mem_dma_base_write((uint64_t)(uintptr_t) buf);
sdblock2mem_dma_length_write(512*nblocks);
sdblock2mem_dma_enable_write(1);
/* Wait for DMA Writer to complete */ /* Read Block(s) from SDCard */
while ((sdblock2mem_dma_done_read() & 0x1) == 0); #ifdef SDCARD_CMD23_SUPPORT
sdcard_set_block_count(nblocks);
#endif
if (nblocks > 1)
sdcard_read_multiple_block(block, nblocks);
else
sdcard_read_single_block(block);
sdcard_stop_transmission(); /* Wait for DMA Writer to complete */
while ((sdblock2mem_dma_done_read() & 0x1) == 0);
/* Stop transmission (Only for multiple block reads). */
if (nblocks > 1)
sdcard_stop_transmission();
/* Update Block/Buffer/Count */
block += nblocks;
buf += 512*nblocks;
count -= nblocks;
}
#ifndef CONFIG_CPU_HAS_DMA_BUS #ifndef CONFIG_CPU_HAS_DMA_BUS
/* Flush caches */ /* Flush caches */