integration/soc/SoC: Add collection of CSRs described in Main Module (ie Top-Level).

CSRs added to the Main Module were silently ignored. These are now collected and automatically
added to a "main" Sub-Module.

This feature is useful to quickly create/add CSRs in the design when debugging, ex:

# Adds a "debug" CSR to a SoC and connect register to pads:
self.debug = CSRStorage()
self.comb += pads.debug.eq(self.debug.storage).
This commit is contained in:
Florent Kermarrec 2022-10-28 10:01:33 +02:00
parent 1f2d4f017a
commit 3603e90ed8
1 changed files with 15 additions and 0 deletions

View File

@ -1190,6 +1190,21 @@ class SoC(LiteXModule):
colorer(len(self.dma_bus.slaves)))) colorer(len(self.dma_bus.slaves))))
self.add_config("CPU_HAS_DMA_BUS") self.add_config("CPU_HAS_DMA_BUS")
# SoC Main CSRs collection -----------------------------------------------------------------
# Collect CSRs created on the Main Module.
main_csrs = dict()
for name, obj in self.__dict__.items():
if isinstance(obj, (CSR, CSRStorage, CSRStatus)):
main_csrs[name] = obj
# Add Main CSRs to a "main" Sub-Module and delete it from Main Module.
if main_csrs:
self.main = LiteXModule()
for name, csr in main_csrs.items():
setattr(self.main, name, csr)
delattr(self, name)
# SoC CSR Interconnect --------------------------------------------------------------------- # SoC CSR Interconnect ---------------------------------------------------------------------
self.csr_bankarray = csr_bus.CSRBankArray(self, self.csr_bankarray = csr_bus.CSRBankArray(self,
address_map = self.csr.address_map, address_map = self.csr.address_map,