soc: add add_ram/add_rom methods

This commit is contained in:
Florent Kermarrec 2020-02-07 15:57:46 +01:00
parent e5a8ac1dab
commit 9445c33e9d
2 changed files with 30 additions and 9 deletions

View File

@ -38,11 +38,12 @@ def buildtime(with_time=True):
# SoCRegion ----------------------------------------------------------------------------------------
class SoCRegion:
def __init__(self, origin=None, size=None, cached=True):
self.logger = logging.getLogger("SoCRegion")
self.origin = origin
self.size = size
self.cached = cached
def __init__(self, origin=None, size=None, cached=True, read_only=False):
self.logger = logging.getLogger("SoCRegion")
self.origin = origin
self.size = size
self.cached = cached
self.read_only = read_only
def decoder(self):
origin = self.origin
@ -64,6 +65,8 @@ class SoCRegion:
if self.size is not None:
r += "Size: {}, ".format(colorer("0x{:08x}".format(self.size)))
r += "Cached: {}".format(colorer(self.cached))
if self.read_only:
r += ", Read Only"
return r
@ -534,6 +537,25 @@ class SoC(Module):
self.logger.info(self.irq)
self.logger.info(colorer("-"*80, color="bright"))
# SoC main components --------------------------------------------------------------------------
def add_ram(self, name, origin, size, contents=[], read_only=False):
ram_bus = wishbone.Interface(data_width=self.bus.data_width)
ram = wishbone.SRAM(size, bus=ram_bus, init=contents, read_only=read_only)
self.bus.add_slave(name, ram.bus, SoCRegion(origin=origin, size=size, read_only=read_only))
if hasattr(self, name):
self.logger.error("{} name already used.".format(colorer(name, "red")))
raise
self.logger.info("RAM {} {} {}.".format(
colorer(name),
colorer("added", "green"),
self.bus.regions[name]))
setattr(self.submodules, name, ram)
def add_rom(self, name, origin, size, contents=[]):
self.add_ram(name, origin, size, contents, read_only=True)
# SoC finalization -----------------------------------------------------------------------------
def do_finalize(self):
self.logger.info(colorer("-"*80, color="bright"))
self.logger.info(colorer("Finalized SoC:", color="cyan"))

View File

@ -124,6 +124,7 @@ class SoCCore(SoC):
self.csr_data_width = csr_data_width
self.csr_address_width = csr_address_width
self.with_wishbone = with_wishbone
self.wishbone_timeout_cycles = wishbone_timeout_cycles
# Modules instances ------------------------------------------------------------------------
@ -192,13 +193,11 @@ class SoCCore(SoC):
# Add integrated SRAM
if integrated_sram_size:
self.submodules.sram = wishbone.SRAM(integrated_sram_size, init=integrated_sram_init)
self.register_mem("sram", self.soc_mem_map["sram"], self.sram.bus, integrated_sram_size)
self.add_ram("sram", self.soc_mem_map["sram"], integrated_sram_size)
# Add integrated MAIN_RAM (only useful when no external SRAM/SDRAM is available)
if integrated_main_ram_size:
self.submodules.main_ram = wishbone.SRAM(integrated_main_ram_size, init=integrated_main_ram_init)
self.register_mem("main_ram", self.soc_mem_map["main_ram"], self.main_ram.bus, integrated_main_ram_size)
self.add_ram("main_ram", self.soc_mem_map["main_ram"], integrated_main_ram_size)
# Add UART
if with_uart: