+ def add_interrupt(self, interrupt_name, interrupt_id=None, allow_user_defined=False):
+ # check that interrupt_name is not already used
+ if interrupt_name in self.soc_interrupt_map.keys():
+ if allow_user_defined:
+ return
+ else:
+ raise ValueError("Interrupt conflit, {} name already used".format(interrupt_name))
+
+ # check that interrupt_id is in range
+ if interrupt_id is not None and interrupt_id >= 32:
+ raise ValueError("{} Interrupt ID out of range ({}, max=31)".format(
+ interrupt_namename, interrupt_id))
+
+ # interrupt_id not provided: allocate interrupt to the first available id
+ if interrupt_id is None:
+ for n in range(32):
+ if n not in self.soc_interrupt_map.values():
+ self.soc_interrupt_map.update({interrupt_name: n})
+ return
+ raise ValueError("No more space to allocate {} interrupt".format(name))
+ # interrupt_id provided: check that interrupt_id is not already used and add interrupt
+ else:
+ for _name, _id in self.soc_interrupt_map.items():
+ if interrupt_id == _id:
+ raise ValueError("Interrupt conflict, {} already used by {} interrupt".format(
+ interrupt_id, _name))
+ self.soc_interrupt_map.update({interrupt_name: interrupt_id})
+
+ def add_csr(self, csr_name, csr_id=None, allow_user_defined=False):
+ # check that csr_name is not already used
+ if csr_name in self.soc_csr_map.keys():
+ if allow_user_defined:
+ return
+ else:
+ raise ValueError("CSR conflit, {} name already used".format(csr_name))
+
+ # check that csr_id is in range
+ if csr_id is not None and csr_id >= 2**self.csr_address_width:
+ raise ValueError("{} CSR ID out of range ({}, max=31)".format(
+ csr_name, csr_id))
+
+ # csr_id not provided: allocate csr to the first available id
+ if csr_id is None:
+ for n in range(2**self.csr_address_width):
+ if n not in self.soc_csr_map.values():
+ self.soc_csr_map.update({csr_name: n})
+ return
+ raise ValueError("No more space to allocate {} csr".format(name))
+ # csr_id provided: check that csr_id is not already used and add csr
+ else:
+ for _name, _id in self.soc_csr_map.items():
+ if csr_id == _id:
+ raise ValueError("CSR conflict, {} already used by {} csr".format(
+ csr_id, _name))
+ self.soc_csr_map.update({csr_name: csr_id})
+