integration/soc/sdcard: add mode parameter to enable read only, write only or read...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 10 Jul 2020 09:18:22 +0000 (11:18 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 10 Jul 2020 09:18:22 +0000 (11:18 +0200)
litex/soc/integration/soc.py
litex/soc/software/bios/cmds/cmd_litesdcard.c
litex/soc/software/liblitesdcard/sdcard.c

index a8c40e09070ef049cc9c714540185e3285c5a73d..8980ea4c7a76f53ca2ac1bc365f366503d0f3e30 100644 (file)
@@ -1244,7 +1244,8 @@ class LiteXSoC(SoC):
         self.add_csr(name)
 
     # Add SDCard -----------------------------------------------------------------------------------
-    def add_sdcard(self, name="sdcard", use_emulator=False):
+    def add_sdcard(self, name="sdcard", mode="read+write", use_emulator=False):
+        assert mode in ["read", "write", "read+write"]
         # Imports
         from litesdcard.emulator import SDEmulator
         from litesdcard.phy import SDPHY
@@ -1266,15 +1267,17 @@ class LiteXSoC(SoC):
         self.add_csr("sdcore")
 
         # Block2Mem DMA
-        bus = wishbone.Interface(data_width=self.bus.data_width, adr_width=self.bus.address_width)
-        self.submodules.sdblock2mem = SDBlock2MemDMA(bus=bus, endianness=self.cpu.endianness)
-        self.comb += self.sdcore.source.connect(self.sdblock2mem.sink)
-        self.bus.add_master("sdblock2mem", master=bus)
-        self.add_csr("sdblock2mem")
+        if "read" in mode:
+            bus = wishbone.Interface(data_width=self.bus.data_width, adr_width=self.bus.address_width)
+            self.submodules.sdblock2mem = SDBlock2MemDMA(bus=bus, endianness=self.cpu.endianness)
+            self.comb += self.sdcore.source.connect(self.sdblock2mem.sink)
+            self.bus.add_master("sdblock2mem", master=bus)
+            self.add_csr("sdblock2mem")
 
         # Mem2Block DMA
-        bus = wishbone.Interface(data_width=self.bus.data_width, adr_width=self.bus.address_width)
-        self.submodules.sdmem2block = SDMem2BlockDMA(bus=bus, endianness=self.cpu.endianness)
-        self.comb += self.sdmem2block.source.connect(self.sdcore.sink)
-        self.bus.add_master("sdmem2block", master=bus)
-        self.add_csr("sdmem2block")
+        if "write" in mode:
+            bus = wishbone.Interface(data_width=self.bus.data_width, adr_width=self.bus.address_width)
+            self.submodules.sdmem2block = SDMem2BlockDMA(bus=bus, endianness=self.cpu.endianness)
+            self.comb += self.sdmem2block.source.connect(self.sdcore.sink)
+            self.bus.add_master("sdmem2block", master=bus)
+            self.add_csr("sdmem2block")
index 68c077887abcac0bd37401eebdc1c48dc23f5a5b..c95e71347909050a881ebcfebb431c1b5c465427 100644 (file)
@@ -27,7 +27,7 @@ define_command(sdinit, sdcard_init, "Initialize SDCard", LITESDCARD_CMDS);
  * Perform SDcard block read
  *
  */
-#ifdef CSR_SDCORE_BASE
+#ifdef CSR_SDBLOCK2MEM_BASE
 static void sdread(int nb_params, char **params)
 {
        unsigned int block;
@@ -58,7 +58,7 @@ define_command(sdread, sdread, "Read SDCard block", LITESDCARD_CMDS);
  * Perform SDcard block write
  *
  */
-#ifdef CSR_SDCORE_BASE
+#ifdef CSR_SDMEM2BLOCK_BASE
 static void sdwrite(int nb_params, char **params)
 {
        int i;
index 5739809ca2b287a237b04c64f976d0cc379c5a2d..cb5f6138d57849b08ea5df7545a0818a2732233f 100644 (file)
@@ -555,6 +555,8 @@ int sdcard_init(void) {
        return 1;
 }
 
+#ifdef CSR_SDBLOCK2MEM_BASE
+
 void sdcard_read(uint32_t sector, uint32_t count, uint8_t* buf)
 {
        /* Initialize DMA Writer */
@@ -581,6 +583,10 @@ sdcard_set_block_count(count);
 #endif
 }
 
+#endif
+
+#ifdef CSR_SDMEM2BLOCK_BASE
+
 void sdcard_write(uint32_t sector, uint32_t count, uint8_t* buf)
 {
        while (count--) {
@@ -606,6 +612,7 @@ void sdcard_write(uint32_t sector, uint32_t count, uint8_t* buf)
                sector += 1;
        }
 }
+#endif
 
 /*-----------------------------------------------------------------------*/
 /* SDCard FatFs disk functions                                           */