From 39458c92eb6f248a43da917fe009ab3bef5389f5 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 6 Feb 2020 19:50:44 +0100 Subject: [PATCH] soc: add use_loc_if_exists on SoCIRQ.add to use current location is already defined --- litex/soc/integration/soc.py | 45 ++++++++++++++++--------------- litex/soc/integration/soc_core.py | 6 ++--- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 3d466544a..17ceb5fff 100755 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -404,29 +404,32 @@ class SoCIRQ: self.logger.info(colorer("IRQ 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.irqs.keys(): - self.logger.error("{} IRQ name already used.".format(colorer(name, "red"))) - self.logger.error(self) - raise - if n in self.irqs.values(): - self.logger.error("{} IRQ Location already used.".format(colorer(n, "red"))) - self.logger.error(self) - raise - if n is None: - allocated = True - n = self.alloc(name) + if not (use_loc_if_exists and name in self.irqs.keys()): + if name in self.irqs.keys(): + self.logger.error("{} IRQ name already used.".format(colorer(name, "red"))) + self.logger.error(self) + raise + if n in self.irqs.values(): + self.logger.error("{} IRQ 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("{} IRQ Location should be positive.".format( + colorer(n, color="red"))) + raise + if n > self.n_irqs: + self.logger.error("{} IRQ Location too high (Up to {}).".format( + colorer(n, color="red"), + colorer(self.n_csrs, color="green"))) + raise else: - if n < 0: - self.logger.error("{} IRQ Location should be positive.".format( - colorer(n, color="red"))) - raise - if n > self.n_irqs: - self.logger.error("{} IRQ Location too high (Up to {}).".format( - colorer(n, color="red"), - colorer(self.n_csrs, color="green"))) - raise + n = self.irqs[name] self.irqs[name] = n self.logger.info("{} IRQ {} at Location {}.".format( colorer(name, color="underline"), diff --git a/litex/soc/integration/soc_core.py b/litex/soc/integration/soc_core.py index fd28b2f40..d167b04b0 100644 --- a/litex/soc/integration/soc_core.py +++ b/litex/soc/integration/soc_core.py @@ -265,7 +265,7 @@ class SoCCore(SoC): self.submodules.uart = ResetInserter()(uart.UART(self.uart_phy)) self.add_csr("uart_phy", allow_user_defined=True) self.add_csr("uart", allow_user_defined=True) - self.add_interrupt("uart") + self.add_interrupt("uart", allow_user_defined=True) # Add Identifier if ident: @@ -279,7 +279,7 @@ class SoCCore(SoC): if with_timer: self.submodules.timer0 = timer.Timer() self.add_csr("timer0", allow_user_defined=True) - self.add_interrupt("timer0") + self.add_interrupt("timer0", allow_user_defined=True) # Add Wishbone to CSR bridge self.config["CSR_DATA_WIDTH"] = csr_data_width @@ -298,7 +298,7 @@ class SoCCore(SoC): # Methods -------------------------------------------------------------------------------------- def add_interrupt(self, interrupt_name, interrupt_id=None, allow_user_defined=False): - self.irq.add(interrupt_name, interrupt_id) + self.irq.add(interrupt_name, interrupt_id, use_loc_if_exists=allow_user_defined) def add_csr(self, csr_name, csr_id=None, allow_user_defined=False): self.csr.add(csr_name, csr_id, use_loc_if_exists=allow_user_defined)