soc: add use_loc_if_exists on SoCIRQ.add to use current location is already defined
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 6 Feb 2020 18:50:44 +0000 (19:50 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 6 Feb 2020 18:50:44 +0000 (19:50 +0100)
litex/soc/integration/soc.py
litex/soc/integration/soc_core.py

index 3d466544a689e642a836447b6a9de6f920296e1f..17ceb5fffc25a30f42507550842a509c0a003266 100755 (executable)
@@ -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)
-        else:
-            if n < 0:
-                self.logger.error("{} IRQ Location should be positive.".format(
-                    colorer(n, color="red")))
+        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 > self.n_irqs:
-                self.logger.error("{} IRQ Location too high (Up to {}).".format(
-                    colorer(n, color="red"),
-                    colorer(self.n_csrs, color="green")))
+            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:
+            n = self.irqs[name]
         self.irqs[name] = n
         self.logger.info("{} IRQ {} at Location {}.".format(
             colorer(name, color="underline"),
index fd28b2f4067a0b40d20783ee947d4845219ffdc1..d167b04b015afac1b7359784551bc53471661474 100644 (file)
@@ -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)