Simple framework for physical chip design (place & route) based on KLayout.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
3.1 KiB

<?xml version="1.0" encoding="utf-8"?>
<klayout-macro>
<description/>
<version/>
<category>pymacros</category>
<prolog/>
<epilog/>
<doc/>
<autorun>false</autorun>
<autorun-early>false</autorun-early>
<shortcut/>
<show-in-menu>false</show-in-menu>
<group-name/>
<menu-path/>
<interpreter>python</interpreter>
<dsl-interpreter-name/>
<text>"""
Signal routing is not yet implemented.
Instead the routing connections are just highlighted with direct lines.
"""
from kpnr.router.airwire_router import AirwireRouter
# === PREPARE for routing ===
# Draw layout of routing terminals, i.e. pin shapes of cells and macros.
# Create flat structure of routing terminals.
# Plot pin shapes and net names.
routing_terminal_layer = layout.layer(db.LayerInfo(21, 0, 'routing_terminal'))
routing_terminal_cell = layout.create_cell("routing_terminals")
top_cell.insert(db.CellInstArray(routing_terminal_cell.cell_index(), db.Trans(0, 0)))
pin_shapes_by_net = collections.defaultdict(set)
terminal_ids = itertools.count(1)
for net in design.top_circuit.each_net():
assert isinstance(net, db.Net)
net_pins = net.each_subcircuit_pin()
for p in net_pins:
subcircuit_id = p.subcircuit().id()
if subcircuit_id not in design.cell_instances_by_subcircuit_id:
logger.warning('No cell instance for subcircuit {}'.format(p.subcircuit().name))
else:
cell_inst = design.cell_instances_by_subcircuit_id[subcircuit_id]
assert isinstance(cell_inst, db.Instance)
assert cell_inst.is_valid()
cell = cell_inst.cell
cell_name = cell.name
transf = cell_inst.trans
# Get the name of the pin.
pin_name = p.pin().name()
# Get the associated pin shapes.
pin_shapes = cell_pin_shapes[cell_name][pin_name]
# Move the pin shapes to the location of the cell.
placed_pin_shapes = db.Shapes()
placed_pin_shapes.insert(pin_shapes.transformed(transf))
# Insert shapes and plot net names.
for s in placed_pin_shapes.each():
s = routing_terminal_cell.shapes(routing_terminal_layer).insert(s)
label_text = net.name
s.set_property('net_name', net.name)
s.set_property('terminal_id', next(terminal_ids))
pin_shapes_by_net[net].add(s)
text_position = polygon_label.find_polygon_label_position(s.polygon, label_text)
routing_terminal_cell.shapes(routing_terminal_layer).insert(db.Text(label_text, text_position))
# === Sketch pin connections ===
# Create layer for air wires.
airwire_layer = layout.layer(db.LayerInfo(1000, 1, 'air_wires'))
airwire_router = AirwireRouter(airwire_layer=(1000, 1))
logger.info("Draw air-wires for visualization.")
# Call the AirwireRouter.
airwire_router.route(
netlist=design.top_circuit,
layout=design.layout,
core_area=design.core_area,
top_cell=design.top_cell,
routing_terminals=routing_terminal_cell
)
logger.info("Air-wire visualization done.")
# Make sure all layers are displayed.
cell_view.view().add_missing_layers()</text>
</klayout-macro>