def __init__(self, parent, **keys): """ Create interface object if node is a node or name. __init__(self,parent,name) __init__(self,parent,node) __init__(self,parent,nodestring) """ self._parent = parent if "name" in keys: WrapperXml.__init__(self, nodename="interface") self.name = keys["name"] elif "node" in keys: WrapperXml.__init__(self, node=keys["node"]) elif "wxml" in keys: WrapperXml.__init__(self, nodestring=keys["wxml"]) else: raise PodError("Keys unknown in Interface", 0) self._registerslist = [] self.portslist = [] self._slaveslist = [] self._bus = None if self.interface_class == "master": self.alloc_mem = AllocMem(self) if self.interface_class == "slave": self.interfacemaster = None if self.get_node("slaves") is not None: for element in self.get_subnodes("slaves", "slave"): self._slaveslist.append(Slave(self, node=element)) if self.get_node("registers") is not None: for element in self.get_subnodes("registers", "register"): self._registerslist.append(Register(self, node=element)) if self.get_node("ports") is not None: for node in self.get_subnodes("ports", "port"): self.portslist.append(Port(self, node=node)) # set bus if self.bus_name is not None: self.bus = self.bus_name
def __init__(self,parent,**keys): """ Create interface object if node is a node or name. __init__(self,parent,name) __init__(self,parent,node) __init__(self,parent,nodestring) """ if "name" in keys: self.__initname(keys["name"]) elif "node" in keys: self.__initnode(keys["node"]) elif "wxml" in keys: self.__initwxml(keys["wxml"]) else: raise Error("Keys unknown in Interface",0) self.parent = parent self.registerslist = [] self.portslist = [] self.slaveslist = [] self.id = None # each slave bus has unique identifiant num if self.getClass()=="master": self.allocMem = AllocMem(self) if self.getClass()=="slave": self.interfacemaster = None if self.getNode("slaves") != None: for element in self.getSubNodeList("slaves","slave"): self.slaveslist.append(Slave(self,node=element)) if self.getNode("registers") != None: for element in self.getSubNodeList("registers","register"): self.registerslist.append(Register(self,node=element)) if self.getNode("ports") != None: for node in self.getSubNodeList("ports","port"): self.portslist.append(Port(self,node=node)) # set bus if self.getBusName() != None: self.setBus(self.getBusName())
class Interface(WrapperXml): """ Manage components interfaces attributes: registerbaseaddress -- register base address registerslist -- list of register object portslist -- list of port object bus -- bustype """ def __init__(self,parent,**keys): """ Create interface object if node is a node or name. __init__(self,parent,name) __init__(self,parent,node) __init__(self,parent,nodestring) """ if "name" in keys: self.__initname(keys["name"]) elif "node" in keys: self.__initnode(keys["node"]) elif "wxml" in keys: self.__initwxml(keys["wxml"]) else: raise Error("Keys unknown in Interface",0) self.parent = parent self.registerslist = [] self.portslist = [] self.slaveslist = [] self.id = None # each slave bus has unique identifiant num if self.getClass()=="master": self.allocMem = AllocMem(self) if self.getClass()=="slave": self.interfacemaster = None if self.getNode("slaves") != None: for element in self.getSubNodeList("slaves","slave"): self.slaveslist.append(Slave(self,node=element)) if self.getNode("registers") != None: for element in self.getSubNodeList("registers","register"): self.registerslist.append(Register(self,node=element)) if self.getNode("ports") != None: for node in self.getSubNodeList("ports","port"): self.portslist.append(Port(self,node=node)) # set bus if self.getBusName() != None: self.setBus(self.getBusName()) def __initname(self,name): WrapperXml.__init__(self,nodename="interface") self.setAttribute("name",name) def __initnode(self,node): WrapperXml.__init__(self,node=node) def __initwxml(self,nodestring): WrapperXml.__init__(self,nodestring=nodestring) def setMaster(self,masterinterface): if self.getClass() != "slave": raise Error("interface "+self.getName()+" must be slave",0) elif masterinterface.getClass() != "master": raise Error("interface "+masterinterface.getClass()+" must be master",0) self.interfacemaster = masterinterface def getMaster(self): if self.getClass() != "slave": raise Error("Only slave interface could have a master",0) if self.interfacemaster==None: raise Error("Interface "+self.getName()+" is not connected on a master",0) return self.interfacemaster def getClass(self): return self.getAttribute("class") def setClass(self,classname): if not classname in INTERFACE_CLASS: raise Error("classname "+classname+" unknown") self.setAttribute("class",classname) def getClockAndResetName(self): value = self.getAttribute("clockandreset") if value == None: raise Error("No clock and reset name in '"+self.getName()+"' interface") return value #TODO: def getClockAndResetInterface(self): print "TODO getclockandresetinterface" def setClockAndReset(self,interfacename): #check if interfacename exist self.getParent().getInterface(interfacename) #TODO: check if interfacename is a clockandreset self.setAttribute("clockandreset",interfacename) def getBase(self): try: base = self.getAttribute("base","registers") except AttributeError: raise Error("Base address register not set",0) if base == None: raise Error("Base address register not set",0) else: return base def getBaseInt(self): try: return int(self.getBase(),16) except Error: return 0 def getAddressSize(self): """ Return the size of address port """ try: return int( self.getPortByType( self.bus.getSignalName("slave","address")).getSize()) except Error: return 0 def getMemorySize(self): return ((2**(self.getAddressSize()))*self.regStep()) def setBase(self,baseoffset): """ Set the base offset for this interface baseoffset is an hexadecimal string the interface must be a slave bus """ if self.getBusName() == None: raise Error("Interface is not a bus",1) if self.getClass() != "slave": raise Error("Bus must be slave",1) size = self.getMemorySize() if int(baseoffset,16)%(size)!=0: raise Error("Offset must be a multiple of " + hex(size),1) self.setAttribute("base",baseoffset,"registers") def getBusName(self): return self.getAttribute("bus") def getBus(self): return self.bus def setBus(self,attribute): self.bus = Bus(self,name=attribute) self.setAttribute("bus",attribute) def getPortsList(self): return self.portslist def getPort(self,portname): for port in self.portslist: if port.getName() == portname: return port raise Error("Port "+portname+" does not exists",1) def getPortByType(self,porttypename): for port in self.portslist: if port.getType() == porttypename: return port raise Error("Not port with type "+ str(porttypename),1) def addPort(self,port): port.setParent(self) self.portslist.append(port) self.addSubNode(nodename="ports",subnode=port) def deletePin(self,instancedest,interfacedest=None,portdest=None,\ pindest=None,portsource=None,pinsource=None): """ Delete all interface pins """ if portsource==None: for port in self.getPortsList(): port.deletePin(instancedest=instancedest) else: port = self.getPort(portsource) port.deletePin(instancedest, interfacedest, portdest, pindest, pinsource) def getSlavesList(self): return self.slaveslist def delSlave(self,slave): self.allocMem.delInterfaceSlave(slave.getInterface()) self.slaveslist.remove(slave) self.delSubNode("slaves","slave",{"instancename":slave.getInstanceName(),\ "interfacename":slave.getInterfaceName()}) def deleteBus(self,instanceslavename,interfaceslavename=None): """ delete slave bus connection """ for slave in self.getSlavesList(): if slave.getInstanceName() == instanceslavename: if interfaceslavename==None: self.delSlave(slave) return elif slave.getInterfaceName() == interfaceslavename: self.delSlave(slave) return raise Error("Bus connection "+str(self.getName())+" -> "+str(instanceslavename)+"."+str(interfaceslavename) +" doesn't exist",0) def connectBus(self,instanceslave,interfaceslavename): """ Connect an interfaceslave to an interface bus master """ interfaceslave = instanceslave.getInterface(interfaceslavename) for slave in self.getSlavesList(): if slave.getInstanceName()==instanceslave.getInstanceName()\ and slave.getInterfaceName()==interfaceslavename: raise Error("Bus connection for "+\ slave.getInstanceName()+"."+\ slave.getInterfaceName()+\ " already exists",1) if self.getBusName() == None: raise Error("Interface "+self.getName()+" must be a bus ",0) if interfaceslave.getBusName() == None: raise Error("Interface "+interfaceslave.getName()+" must be a bus ",0) if self.getBusName() != interfaceslave.getBusName(): raise Error("Can't connect "+self.getBusName()+\ " on "+interfaceslave.getBusName(),1) if self.getClass() != "master": raise Error(self.getName() + " is not a master",0) if interfaceslave.getBusName() == None : raise Error(instanceslave.getInstanceName()+\ "."+interfaceslave.getName()+" is not a bus",1) if interfaceslave.getClass() != "slave": raise Error(instanceslave.getInstanceName()+\ "."+interfaceslave.getName()+" is not a slave",1) self.addSubNode(nodename="slaves",\ subnodename="slave",\ attributedict= {"instancename":instanceslave.getInstanceName(),\ "interfacename":interfaceslavename}) self.slaveslist.append(Slave(self,\ instancename=instanceslave.getInstanceName(),\ interfacename=interfaceslavename)) self.allocMem.addInterfaceSlave(interfaceslave) interfaceslave.setMaster(self) interfaceslave.setID(self.allocMem.getID()) instanceslave.getGeneric(genericname="id").setValue( str(interfaceslave.getID())) def setID(self,id): self.id = id def getID(self): return self.id def autoconnectPin(self): for port in self.getPortsList(): port.autoconnectPin() def connectClkDomain(self,instancedestname,interfacedestname): """ Connect clock domain """ for slave in self.getSlavesList(): if slave.getInstanceName()==instancedestname \ and slave.getInterfaceName()==interfacedestname: raise Error("Clock connection "+instancedestname+\ "."+interfacedestname+" exists",1) self.addSubNode(nodename="slaves",subnodename="slave", attributedict={"instancename":instancedestname, "interfacename":interfacedestname}) self.slaveslist.append(Slave(self,\ instancename=instancedestname,\ interfacename=interfacedestname)) def getRegister(self,registername): for register in self.getRegisterList(): if register.getName() == registername: return register raise Error("No register with name "+registername,0) def getRegisterList(self): return self.registerslist def getRegisterMap(self): """ Return the memory mapping for slave interface """ if len(self.registerslist)!=0: listreg = [] # sort registers dict by offset order self.registerslist.sort(lambda x, y:cmp(int(x.getOffset(),16), int(y.getOffset(),16))) #display each register for register in self.registerslist: listreg.append({"offset":int(register.getOffset(),16)*self.regStep()+\ int(self.getBase(),16),\ "name":register.getName()}) return listreg else: return [{"offset":int(self.getBase(),16),"name":self.getName()}] def regStep(self): """ Step between two register """ return int(self.bus.getDataSize())/8 def getSysconInstance(self): """ Return syscon instance that drive master interface """ for instance in self.getParent().getParent().getInstancesList(): for interface in instance.getInterfacesList(): if interface.getClass() == "clk_rst": for slave in interface.getSlavesList(): if slave.getInstanceName() == \ self.getParent().getInstanceName() and \ slave.getInterfaceName() == self.getName(): return instance raise Error("No syscon for interface "+self.getName()+\ " of instance "+self.getParent().getInstanceName(),0) def addRegister(self,register_name): if self.getBusName() == None: raise Error("Interface must be a bus") elif self.getClass() != "slave": raise Error("Bus must be a slave") #TODO: check if enough space in memory mapping to add register register = Register(self,register_name=register_name) self.registerslist.append(register) self.addSubNode(nodename="registers",subnode=register) def delRegister(self,register_name): #TODO pass
class Interface(WrapperXml): """ Manage components interfaces attributes: registerbaseaddress -- register base address registerslist -- list of register object portslist -- list of port object bus -- bustype """ def __init__(self,parent,**keys): """ Create interface object if node is a node or name. __init__(self,parent,name) __init__(self,parent,node) __init__(self,parent,nodestring) """ if "name" in keys: self.__initname(keys["name"]) elif "node" in keys: self.__initnode(keys["node"]) elif "wxml" in keys: self.__initwxml(keys["wxml"]) else: raise Error("Keys unknown in Interface",0) self.parent = parent self.registerslist = [] self.portslist = [] self.slaveslist = [] self.id = None # each slave bus has unique identifiant num if self.getClass()=="master": self.allocMem = AllocMem(self) if self.getClass()=="slave": self.interfacemaster = None if self.getNode("slaves") != None: for element in self.getSubNodeList("slaves","slave"): self.slaveslist.append(Slave(self,node=element)) if self.getNode("registers") != None: for element in self.getSubNodeList("registers","register"): self.registerslist.append(Register(self,node=element)) if self.getNode("ports") != None: for node in self.getSubNodeList("ports","port"): self.portslist.append(Port(self,node=node)) # set bus if self.getBusName() != None: self.setBus(self.getBusName()) def __initname(self,name): WrapperXml.__init__(self,nodename="interface") self.setAttribute("name",name) def __initnode(self,node): WrapperXml.__init__(self,node=node) def __initwxml(self,nodestring): WrapperXml.__init__(self,nodestring=nodestring) def setMaster(self,masterinterface): if self.getClass() != "slave": raise Error("interface "+self.getName()+" must be slave",0) elif masterinterface.getClass() != "master": raise Error("interface "+masterinterface.getClass()+" must be master",0) self.interfacemaster = masterinterface def getMaster(self): if self.getClass() != "slave": raise Error("Only slave interface could have a master",0) if self.interfacemaster==None: raise Error("Interface "+self.getName()+" is not connected on a master",0) return self.interfacemaster def getClass(self): return self.getAttributeValue("class") def setClass(self,classname): if not classname in INTERFACE_CLASS: raise Error("classname "+classname+" unknown") self.setAttribute("class",classname) def getBase(self): try: base = self.getAttributeValue("base","registers") except AttributeError: raise Error("Base address register not set",0) if base == None: raise Error("Base address register not set",0) else: return base def getBaseInt(self): try: return int(self.getBase(),16) except Error: return 0 def getAddressSize(self): """ Return the size of address port """ try: return int( self.getPortByType( self.bus.getSignalName("slave","address")).getSize()) except Error: return 0 def getMemorySize(self): return ((2**(self.getAddressSize()))*self.regStep()) def setBase(self,baseoffset): """ Set the base offset for this interface baseoffset is an hexadecimal string the interface must be a slave bus """ if self.getBusName() == None: raise Error("Interface is not a bus",1) if self.getClass() != "slave": raise Error("Bus must be slave",1) size = self.getMemorySize() if int(baseoffset,16)%(size)!=0: raise Error("Offset must be a multiple of " + hex(size),1) self.setAttribute("base",baseoffset,"registers") def getBusName(self): return self.getAttributeValue("bus") def getBus(self): return self.bus def setBus(self,attribute): self.bus = Bus(self,name=attribute) self.setAttribute("bus",attribute) def isBus(self): try: self.getBus() except AttributeError: return False return True def getPortsList(self): return self.portslist def getPort(self,portname): for port in self.portslist: if port.getName() == portname: return port raise Error("Port "+portname+" does not exists",1) def getPortByType(self,porttypename): for port in self.portslist: if port.getType() == porttypename: return port raise Error("No port with type "+ str(porttypename),1) def addPort(self,port): port.setParent(self) self.portslist.append(port) self.addSubNode(nodename="ports",subnode=port) def deletePin(self,instancedest,interfacedest=None,portdest=None,\ pindest=None,portsource=None,pinsource=None): """ Delete all interface pins """ if portsource==None: for port in self.getPortsList(): port.deletePin(instancedest=instancedest) else: port = self.getPort(portsource) port.deletePin(instancedest, interfacedest, portdest, pindest, pinsource) def getSlavesList(self): return self.slaveslist def delSlave(self,slave): self.allocMem.delInterfaceSlave(slave.getInterface()) self.slaveslist.remove(slave) self.delSubNode("slaves","slave",{"instancename":slave.getInstanceName(),\ "interfacename":slave.getInterfaceName()}) def deleteBus(self,instanceslavename,interfaceslavename=None): """ delete slave bus connection """ for slave in self.getSlavesList(): if slave.getInstanceName() == instanceslavename: if interfaceslavename==None: self.delSlave(slave) return elif slave.getInterfaceName() == interfaceslavename: self.delSlave(slave) return raise Error("Bus connection "+str(self.getName())+\ " -> "+str(instanceslavename)+"."+\ str(interfaceslavename) +" doesn't exist",0) def connectInterface(self,interface_dest): """ Connect an interface between two components """ if len(interface_dest.getPortsList()) != len(self.getPortsList()): raise Error(self.getParent().getName()+"."+self.getName() +" and " +interface_dest.getParent().getName()+"."+interface_dest.getName() +"are not the same number of ports") for port in self.getPortsList(): if port.getType() == None: raise Error(self.getParent().getName()+"."+self.getName()+"." +port.getName()+" has no type") try: port_dst = interface_dest.getPortByType(port.getType()) except Error,e: raise Error(interface_dest.getParent().getName()+"."+interface_dest.getName() +" have no " +port.getType()+" port") if port_dst.getDir() == port.getDir(): raise Error("Ports "+self.getParent().getName()+"."+self.getName() +"."+port.getName() +" and " +interface_dest.getParent().getName()+"." +interface_dest.getName()+"."+port_dst.getName() +" are the same direction") if port_dst.getDir() == "in" and port_dst.isVoid()!=True: raise Error("Ports "+interface_dest.getParent().getName()+"." +interface_dest.getName()+"."+port_dst.getName() +" is already connected") if port.getDir() == "in" and port.isVoid()!=True: raise Error("Ports "+self.getParent().getName()+"."+self.getName() +"."+port.getName() +" is already connected") for port in self.getPortsList(): port_dst = interface_dest.getPortByType(port.getType()) port.connectPort(port_dst)
class Interface(WrapperXml): """ Manage components interfaces attributes: registerbaseaddress -- register base address registerslist -- list of register object portslist -- list of port object bus -- bustype """ def __init__(self, parent, **keys): """ Create interface object if node is a node or name. __init__(self,parent,name) __init__(self,parent,node) __init__(self,parent,nodestring) """ self._parent = parent if "name" in keys: WrapperXml.__init__(self, nodename="interface") self.name = keys["name"] elif "node" in keys: WrapperXml.__init__(self, node=keys["node"]) elif "wxml" in keys: WrapperXml.__init__(self, nodestring=keys["wxml"]) else: raise PodError("Keys unknown in Interface", 0) self._registerslist = [] self.portslist = [] self._slaveslist = [] self._bus = None if self.interface_class == "master": self.alloc_mem = AllocMem(self) if self.interface_class == "slave": self.interfacemaster = None if self.get_node("slaves") is not None: for element in self.get_subnodes("slaves", "slave"): self._slaveslist.append(Slave(self, node=element)) if self.get_node("registers") is not None: for element in self.get_subnodes("registers", "register"): self._registerslist.append(Register(self, node=element)) if self.get_node("ports") is not None: for node in self.get_subnodes("ports", "port"): self.portslist.append(Port(self, node=node)) # set bus if self.bus_name is not None: self.bus = self.bus_name @property def master(self): """ Get the master bus if exist """ if self.interface_class != "slave": raise PodError("Only slave interface could have a master", 0) if self.interfacemaster is None: raise PodError("Interface " + self.name + " is not connected on a master", 0) return self.interfacemaster @master.setter def master(self, masterinterface): """ set master interface """ if self.interface_class != "slave": raise PodError("interface " + self.name + " must be slave", 0) elif masterinterface.interface_class != "master": raise PodError("interface " + masterinterface.interface_class + " must be master", 0) self.interfacemaster = masterinterface @property def interface_class(self): """ Get the class interface """ return self.get_attr_value("class") @interface_class.setter def interface_class(self, classname): """ Set the class interface """ if classname not in INTERFACE_CLASS: raise PodError("classname " + classname + " unknown") self.set_attr("class", classname) @property def base_addr(self): """ get base address register value """ try: base = self.get_attr_value("base", "registers") if base is None: raise PodError("Base address register not set", 0) return int(base, 16) except AttributeError: raise PodError("Base address register not set", 0) @base_addr.setter def base_addr(self, baseoffset): """ Set the base offset for this interface baseoffset is an hexadecimal string the interface must be a slave bus """ if type(baseoffset) is str: baseoffset = int(baseoffset, 16) if self.bus_name is None: raise PodError("Interface is not a bus", 1) if self.interface_class != "slave": raise PodError("Bus must be slave", 1) size = self.mem_size if (baseoffset % size) != 0: raise PodError("Offset must be a multiple of " + hex(size), 1) self.set_attr("base", hex(baseoffset), "registers") @property def addr_port_size(self): """ How many pin in address port ? """ size = self.get_attr_value("addr_size") if size is not None: return int(size) try: return int( self.get_port_by_type( self.bus.sig_name("slave", "address")).size) except PodError: return 0 @property def mem_size(self): """ Get the memory size """ return int((2 ** self.addr_port_size) * self.regstep) @property def data_size(self): """ Get bus size """ size = self.get_attr_value("data_size") if size is None: return self.bus.data_size else: return size @property def addr_size(self): """ Get bus size """ size = self.get_attr_value("addr_size") if size is None: return int(self.addr_port_size) else: return int(size) @property def bus_name(self): """ Get the bus name """ return self.get_attr_value("bus") @property def bus(self): """ Get the interface bus""" return self._bus @bus.setter def bus(self, attribute): """ Set bus attribute""" self._bus = Bus(self, name=attribute) self.set_attr("bus", attribute) def is_bus(self): """ Test if this interface is a bus """ if self._bus is None: return False return True @property def ports(self): """ get the ports list of interface""" return self.portslist def get_port(self, portname): """ Get port by its name """ for port in self.portslist: if port.name == portname: return port raise PodError("Port " + portname + " does not exists", 1) def add_port(self, port): """ Adding a port """ port.parent = self self.portslist.append(port) self.add_subnode(nodename="ports", subnode=port) def get_port_by_type(self, porttypename): """ Get port using port type name as argument""" for port in self.portslist: if port.porttype == porttypename: return port raise PodError("No port with type " + str(porttypename), 1) def del_pin(self, instancedest, interfacedest=None, portdest=None, pindest=None, portsource=None, pinsource=None): """ Delete all interface pins """ if portsource is None: for port in self.ports: port.del_pin(instancedest=instancedest) else: port = self.get_port(portsource) port.del_pin(instancedest, interfacedest, portdest, pindest, pinsource) @property def slaves(self): """ Get the slaves list of interface""" return self._slaveslist def del_slave(self, slave): """ Delet slave """ self.alloc_mem.del_slave_interface(slave.get_interface()) self._slaveslist.remove(slave) self.del_subnode("slaves", "slave", {"instancename": slave.instancename, "interfacename": slave.interfacename}) def del_bus(self, instanceslavename, interfaceslavename=None): """ delete slave bus connection """ for slave in self.slaves: if slave.instancename == instanceslavename: if interfaceslavename is None: self.del_slave(slave) return elif slave.interfacename == interfaceslavename: self.del_slave(slave) return raise PodError("Bus connection " + str(self.name) + " -> " + str(instanceslavename) + "." + str(interfaceslavename) + " doesn't exist", 0) def connect_interface(self, interface_dest): """ Connect an interface between two components """ if len(interface_dest.ports) != len(self.ports): dest_len = len(interface_dest.ports) src_len = len(self.ports) if dest_len > src_len: for port in interface_dest.ports: if port.is_optional: try: if self.get_port_by_type(port.porttype) is None: pass except PodError: dest_len -= 1 else: for port in self.ports: if port.is_optional: try: if interface_dest.get_port_by_type(port.porttype) is None: pass except PodError: src_len -= 1 if src_len != dest_len : raise PodError(self.parent.name + "." + self.name + " and " + interface_dest.parent.name + "." + interface_dest.name + "are not the same number of ports") for port in self.ports: if port.porttype is None: raise PodError(self.parent.name + "." + self.name + "." + port.name + " has no type") try: port_dst = interface_dest.get_port_by_type(port.porttype) except PodError: if port.is_optional == False: raise PodError(interface_dest.parent.name + "." + interface_dest.name + " have no " + port.porttype + " port") if port_dst.direction == port.direction: raise PodError("Ports " + self.parent.name + "." + self.name + "." + port.name + " and " + interface_dest.parent.name + "." + interface_dest.name + "." + port_dst.name + " are the same direction") if port_dst.direction == "in" and port_dst.isVoid() is not True: raise PodError("Ports " + interface_dest.parent.name + "." + interface_dest.name + "." + port_dst.name + " is already connected") if port.direction == "in" and port.isVoid() is not True: raise PodError("Ports " + self.parent.name + "." + self.name + "." + port.name + " is already connected") for port in self.ports: try: port_dst = interface_dest.get_port_by_type(port.porttype) port.connect_port(port_dst) except PodError as error: if port.is_optional != True: raise error def connect_bus(self, instanceslave, interfaceslavename): """ Connect an interfaceslave to an interface bus master """ interfaceslave = instanceslave.get_interface(interfaceslavename) for slave in self.slaves: if slave.instancename == instanceslave.instancename and\ slave.interfacename == interfaceslavename: raise PodError("Bus connection for " + slave.instancename + "." + slave.interfacename + " already exists", 1) if self.bus_name is None: raise PodError("Interface " + self.name + " must be a bus ") if interfaceslave.bus_name is None: raise PodError("Interface " + interfaceslave.name + " must be a bus ") if self.bus_name != interfaceslave.bus_name: raise PodError("Can't connect " + self.bus_name + " on " + interfaceslave.bus_name, 1) if self.interface_class != "master": raise PodError(self.name + " is not a master", 0) if interfaceslave.bus_name is None: raise PodError(instanceslave.instancename + "." + interfaceslave.name + " is not a bus", 1) if interfaceslave.interface_class != "slave": raise PodError(instanceslave.instancename + "." + interfaceslave.name + " is not a slave", 1) self.add_subnode(nodename="slaves", subnodename="slave", attributedict={ "instancename": instanceslave.instancename, "interfacename": interfaceslavename}) self._slaveslist.append( Slave(self, instancename=instanceslave.instancename, interfacename=interfaceslavename)) self.alloc_mem.add_slave_interface(interfaceslave) interfaceslave.master = self interfaceslave.unique_id = self.alloc_mem.unique_id instanceslave.get_generic(genericname="id").value =\ str(interfaceslave.unique_id) @property def unique_id(self): """ Get the Identifiant number""" try: return self.get_attr_value("unique_id") except PodError: return None @unique_id.setter def unique_id(self, unique_id): """ Set the Identifiant number""" self.set_attr("unique_id", str(unique_id)) def autoconnect_pins(self): """ autoconnect pin """ for port in self.ports: port.autoconnect_pins() def connect_clk_domain(self, instancedestname, interfacedestname): """ Connect clock domain """ for slave in self.slaves: if slave.instancename == instancedestname\ and slave.interfacename == interfacedestname: raise PodError("Clock connection " + instancedestname + "." + interfacedestname + " exists", 1) self.add_subnode(nodename="slaves", subnodename="slave", attributedict={"instancename": instancedestname, "interfacename": interfacedestname}) self._slaveslist.append( Slave(self, instancename=instancedestname, interfacename=interfacedestname)) def get_register(self, registername): """ Get register by name """ for register in self.registers: if register.name == registername: return register raise PodError("No register with name " + registername, 0) @property def parent(self): """ return parent instance """ return self._parent @parent.setter def parent(self, parent): """ set parent instance """ self._parent = parent @property def registers(self): """ return registers list """ return self._registerslist @property def registers_map(self): """ Return the memory mapping for slave interface """ if len(self._registerslist) != 0: listreg = [] # sort registers dict by offset order self._registerslist.sort(key=lambda x: int(x.offset, 16)) # display each register for register in self._registerslist: listreg.append( {"offset": int(register.offset, 16) * self.regstep + self.base_addr, "name": register.name}) return listreg else: return [{"offset": self.base_addr, "name": self.name}] @property def regstep(self): """ Step between two register """ return int(self.data_size) / 8