''' Example plugin to extend functionality '''importtypingimportspydrnetassdnfromspydrnet.ir.wireimportWireasWireBasefromspydrnet.ir.outerpinimportOuterPinfromspydrnet.ir.innerpinimportInnerPinfromspydrnet.ir.portimportPortiftyping.TYPE_CHECKING:fromspydrnet.ir.wireimportWireasWireSDNfromspydrnet_physical.ir.elementimportElementasElementPhyWireBase=type("WireBase",(WireSDN,ElementPhy),{})
[docs]classWire(WireBase):''' This class extends the default Wire class '''def_bundle(self):''' Overrides the _bundle method from element class '''returnself._cable
[docs]defindex(self):""" if this wire is in a cable, returns the index number of the wire in the parent cable, respects down_to and lower_index parameters """assertself.cableisnotNone,"Wire does not belong to any cable"assertselfinself.cable.wires,"Decrepancy in cable and wire mapping"indx=self.cable.wires.index(self)size=self.cable.size-1ifself.cable.is_downto:return(size-indx)+self.cable.lower_indexelse:returnindx+self.cable.lower_index
[docs]defget_driver(self):''' returns the driver(s) of the wire '''drivers=[]forpininself._pins:ifpin.__class__issdn.InnerPin:ifpin.port.directionissdn.IN:drivers.append(pin)else:ifpin.inner_pin.port.directionissdn.OUT:drivers.append(pin)returndrivers
[docs]defassign_wire(self,wire,reverse=False,assign_instance_name=None):''' Perform single bit assignement of self to given wire '''assertself.cableisnotNone,"Wire do not have cable assigned"assign_lib=self.cable.definition._get_assignment_library()assign_def=self.cable.definition._get_assignment_definition(assign_lib,1)ifassign_instance_nameisNone:assign_instance_name=f"{self.cable.name}_{self.index()}_{wire.cable.name}_{wire.index()}_assign"instance=self.cable.definition.create_child(assign_instance_name,reference=assign_def)i_pin=next(instance.get_port_pins("i"))o_pin=next(instance.get_port_pins("o"))self.connect_pin(o_pinifreverseelsei_pin)wire.connect_pin(i_pinifreverseelseo_pin)
[docs]defisload(self,pin):''' '''assertpininself.pins,"Pin is not connected to wire"return(isinstance(pin,OuterPin)andpin.port.direction==Port.Direction.IN)or \
(isinstance(pin,InnerPin)andpin.port.direction==Port.Direction.OUT)