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:
parent
9bec0ce7a2
commit
5cdf621367
|
@ -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,23 +474,41 @@ 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)
|
||||||
{
|
{
|
||||||
|
while (count) {
|
||||||
|
uint32_t nblocks;
|
||||||
|
#ifdef SDCARD_CMD18_SUPPORT
|
||||||
|
nblocks = count;
|
||||||
|
#else
|
||||||
|
nblocks = 1;
|
||||||
|
#endif
|
||||||
/* Initialize DMA Writer */
|
/* Initialize DMA Writer */
|
||||||
sdblock2mem_dma_enable_write(0);
|
sdblock2mem_dma_enable_write(0);
|
||||||
sdblock2mem_dma_base_write((uint64_t)(uintptr_t) buf);
|
sdblock2mem_dma_base_write((uint64_t)(uintptr_t) buf);
|
||||||
sdblock2mem_dma_length_write(512*count);
|
sdblock2mem_dma_length_write(512*nblocks);
|
||||||
sdblock2mem_dma_enable_write(1);
|
sdblock2mem_dma_enable_write(1);
|
||||||
|
|
||||||
/* Read Block(s) from SDCard */
|
/* Read Block(s) from SDCard */
|
||||||
#ifdef SDCARD_CMD23_SUPPORT
|
#ifdef SDCARD_CMD23_SUPPORT
|
||||||
sdcard_set_block_count(count);
|
sdcard_set_block_count(nblocks);
|
||||||
#endif
|
#endif
|
||||||
sdcard_read_multiple_block(block, count);
|
if (nblocks > 1)
|
||||||
|
sdcard_read_multiple_block(block, nblocks);
|
||||||
|
else
|
||||||
|
sdcard_read_single_block(block);
|
||||||
|
|
||||||
/* Wait for DMA Writer to complete */
|
/* Wait for DMA Writer to complete */
|
||||||
while ((sdblock2mem_dma_done_read() & 0x1) == 0);
|
while ((sdblock2mem_dma_done_read() & 0x1) == 0);
|
||||||
|
|
||||||
|
/* Stop transmission (Only for multiple block reads). */
|
||||||
|
if (nblocks > 1)
|
||||||
sdcard_stop_transmission();
|
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 */
|
||||||
flush_cpu_dcache();
|
flush_cpu_dcache();
|
||||||
|
|
Loading…
Reference in New Issue