From 1eff0799a418752ddafc14920e03038427edf6d2 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 6 Feb 2020 18:50:17 +0100 Subject: [PATCH] soc: add use_loc_if_exists on SoCCSR.add to use current location is already defined --- litex/soc/integration/soc.py | 45 ++++++++++++++++--------------- litex/soc/integration/soc_core.py | 14 +++++----- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 3847504e..3d466544 100755 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -323,30 +323,33 @@ class SoCCSR: self.logger.info(colorer("CSR Bus Handler created.", color="cyan")) # Add ------------------------------------------------------------------------------------------ - def add(self, name, n=None): + def add(self, name, n=None, use_loc_if_exists=False): allocated = False - if name in self.csrs.keys(): - self.logger.error("{} CSR name already used.".format(colorer(name, "red"))) - self.logger.error(self) - raise - if n in self.csrs.values(): - self.logger.error("{} CSR Location already used.".format(colorer(n, "red"))) - self.logger.error(self) - raise - if n is None: - allocated = True - n = self.alloc(name) - else: - if n < 0: - self.logger.error("{} CSR Location should be positive.".format( - colorer(n, color="red"))) + if not (use_loc_if_exists and name in self.csrs.keys()): + if name in self.csrs.keys(): + self.logger.error("{} CSR name already used.".format(colorer(name, "red"))) + self.logger.error(self) raise - if n > self.n_csrs: - self.logger.error("{} CSR Location too high (Up to {}).".format( - colorer(n, color="red"), - colorer(self.n_csrs, color="green"))) + if n in self.csrs.values(): + self.logger.error("{} CSR Location already used.".format(colorer(n, "red"))) + self.logger.error(self) raise - self.csrs[name] = n + if n is None: + allocated = True + n = self.alloc(name) + else: + if n < 0: + self.logger.error("{} CSR Location should be positive.".format( + colorer(n, color="red"))) + raise + if n > self.n_csrs: + self.logger.error("{} CSR Location too high (Up to {}).".format( + colorer(n, color="red"), + colorer(self.n_csrs, color="green"))) + raise + self.csrs[name] = n + else: + n = self.csrs[name] self.logger.info("{} CSR {} at Location {}.".format( colorer(name, color="underline"), colorer("allocated" if allocated else "added", color="yellow" if allocated else "green"), diff --git a/litex/soc/integration/soc_core.py b/litex/soc/integration/soc_core.py index 943c5c46..fd28b2f4 100644 --- a/litex/soc/integration/soc_core.py +++ b/litex/soc/integration/soc_core.py @@ -170,7 +170,7 @@ class SoCCore(SoC): # Add SoCController if with_ctrl: self.submodules.ctrl = SoCController() - self.add_csr("ctrl") + self.add_csr("ctrl", allow_user_defined=True) # Add CPU self.config["CPU_TYPE"] = str(cpu_type).upper() @@ -207,7 +207,7 @@ class SoCCore(SoC): self.add_wb_master(soc_bus) # Add CPU CSR (dynamic) - self.add_csr("cpu") + self.add_csr("cpu", allow_user_defined=True) # Add CPU interrupts for _name, _id in self.cpu.interrupts.items(): @@ -263,8 +263,8 @@ class SoCCore(SoC): else: self.submodules.uart_phy = uart.UARTPHY(platform.request(uart_name), clk_freq, uart_baudrate) self.submodules.uart = ResetInserter()(uart.UART(self.uart_phy)) - self.add_csr("uart_phy") - self.add_csr("uart") + self.add_csr("uart_phy", allow_user_defined=True) + self.add_csr("uart", allow_user_defined=True) self.add_interrupt("uart") # Add Identifier @@ -272,13 +272,13 @@ class SoCCore(SoC): if ident_version: ident = ident + " " + get_version() self.submodules.identifier = identifier.Identifier(ident) - self.add_csr("identifier_mem") + self.add_csr("identifier_mem", allow_user_defined=True) self.config["CLOCK_FREQUENCY"] = int(clk_freq) # Add Timer if with_timer: self.submodules.timer0 = timer.Timer() - self.add_csr("timer0") + self.add_csr("timer0", allow_user_defined=True) self.add_interrupt("timer0") # Add Wishbone to CSR bridge @@ -301,7 +301,7 @@ class SoCCore(SoC): self.irq.add(interrupt_name, interrupt_id) def add_csr(self, csr_name, csr_id=None, allow_user_defined=False): - self.csr.add(csr_name, csr_id) + self.csr.add(csr_name, csr_id, use_loc_if_exists=allow_user_defined) def initialize_rom(self, data): self.rom.mem.init = data -- 2.30.2