Throw exception if two CSR have the same name
authorJean THOMAS <git0@pub.jeanthomas.me>
Mon, 8 Jun 2020 11:23:48 +0000 (13:23 +0200)
committerJean THOMAS <git0@pub.jeanthomas.me>
Mon, 8 Jun 2020 11:23:48 +0000 (13:23 +0200)
lambdasoc/periph/base.py

index 8789ee3146bb3e246ff4fdf407b4aeda4890db95..84c3452c4f597dca6968a103b3921bea0280959c 100644 (file)
@@ -253,6 +253,8 @@ class CSRBank:
         name = name or tracer.get_var_name(depth=2 + src_loc_at).lstrip("_")
 
         elem_name = "{}_{}".format(self._name_prefix, name)
+        if any(elem.name == elem_name for (elem, _, _) in self._csr_regs):
+            raise Exception("CSR \"{}\" has already been defined".format(elem_name))
         elem = csr.Element(width, access, name=elem_name)
         self._csr_regs.append((elem, addr, alignment))
         return elem