| 1 |
import sys |
| 2 |
import os |
| 3 |
from itertools import chain |
| 4 |
import re |
| 5 |
import code |
| 6 |
import pickle |
| 7 |
import importlib.resources |
| 8 |
sys.path.append(os.path.join(sys.path[0], '..')) |
| 9 |
from apycula import chipdb |
| 10 |
from apycula.wirenames import wirenames |
| 11 |
|
| 12 |
device = os.getenv("DEVICE") |
| 13 |
if not device: |
| 14 |
raise Exception("DEVICE not set") |
| 15 |
|
| 16 |
with importlib.resources.open_binary("apycula", f"{device}.pickle") as f: |
| 17 |
db = pickle.load(f) |
| 18 |
|
| 19 |
timing_class = "C6/I5" |
| 20 |
timing = db.timing[timing_class] |
| 21 |
|
| 22 |
def addWire(row, col, wire): |
| 23 |
gname = chipdb.wire2global(row, col, db, wire) |
| 24 |
|
| 25 |
try: |
| 26 |
ctx.addWire(name=gname, type=wire, y=row, x=col) |
| 27 |
except AssertionError: |
| 28 |
pass |
| 29 |
|
| 30 |
|
| 31 |
belre = re.compile(r"(IOB|LUT|DFF|BANK|CFG)(\w*)") |
| 32 |
for row, rowdata in enumerate(db.grid, 1): |
| 33 |
for col, tile in enumerate(rowdata, 1): |
| 34 |
|
| 35 |
wires = set(chain( |
| 36 |
tile.pips.keys(), |
| 37 |
tile.clock_pips.keys(), |
| 38 |
*tile.pips.values(), |
| 39 |
*tile.clock_pips.values(), |
| 40 |
)) |
| 41 |
for wire in wires: |
| 42 |
addWire(row, col, wire) |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
for name, bel in tile.bels.items(): |
| 47 |
typ, idx = belre.match(name).groups() |
| 48 |
if typ == "DFF": |
| 49 |
z = int(idx) |
| 50 |
belname = f"R{row}C{col}_SLICE{z}" |
| 51 |
clkname = f"R{row}C{col}_CLK{z//2}" |
| 52 |
fname = f"R{row}C{col}_F{z}" |
| 53 |
qname = f"R{row}C{col}_Q{z}" |
| 54 |
|
| 55 |
ctx.addBel(name=belname, type="GENERIC_SLICE", loc=Loc(col, row, z), gb=False) |
| 56 |
ctx.addBelInput(bel=belname, name="CLK", wire=clkname) |
| 57 |
for k, n in [('A', 'I[0]'), ('B', 'I[1]'), |
| 58 |
('C', 'I[2]'), ('D', 'I[3]')]: |
| 59 |
inpname = f"R{row}C{col}_{k}{z}" |
| 60 |
ctx.addBelInput(bel=belname, name=n, wire=inpname) |
| 61 |
ctx.addBelOutput(bel=belname, name="Q", wire=qname) |
| 62 |
ctx.addBelOutput(bel=belname, name="F", wire=fname) |
| 63 |
|
| 64 |
elif typ == "IOB": |
| 65 |
z = ord(idx)-ord('A') |
| 66 |
belname = f"R{row}C{col}_IOB{idx}" |
| 67 |
inp = bel.portmap['I'] |
| 68 |
outp = bel.portmap['O'] |
| 69 |
oe = bel.portmap['OE'] |
| 70 |
iname = f"R{row}C{col}_{inp}" |
| 71 |
oname = f"R{row}C{col}_{outp}" |
| 72 |
oename = f"R{row}C{col}_{oe}" |
| 73 |
|
| 74 |
ctx.addBel(name=belname, type="GENERIC_IOB", loc=Loc(col, row, z), gb=False) |
| 75 |
ctx.addBelInput(bel=belname, name="I", wire=iname) |
| 76 |
ctx.addBelInput(bel=belname, name="EN", wire=oename) |
| 77 |
ctx.addBelOutput(bel=belname, name="O", wire=oname) |
| 78 |
|
| 79 |
|
| 80 |
wlens = {0: 'X0', 1: 'FX1', 2: 'X2', 8: 'X8'} |
| 81 |
def wiredelay(wire): |
| 82 |
m = re.match(r"[NESWX]+([0128])", wire) |
| 83 |
if m: |
| 84 |
wlen = int(m.groups()[0]) |
| 85 |
name = wlens.get(wlen) |
| 86 |
return ctx.getDelayFromNS(max(timing['wire'][name])) |
| 87 |
elif wire.startswith("UNK"): |
| 88 |
return ctx.getDelayFromNS(max(timing['glbsrc']['PIO_CENT_PCLK'])) |
| 89 |
elif wire.startswith("SPINE"): |
| 90 |
return ctx.getDelayFromNS(max(timing['glbsrc']['CENT_SPINE_PCLK'])) |
| 91 |
elif wire.startswith("GT"): |
| 92 |
return ctx.getDelayFromNS(max(timing['glbsrc']['SPINE_TAP_PCLK'])) |
| 93 |
elif wire.startswith("GBO"): |
| 94 |
return ctx.getDelayFromNS(max(timing['glbsrc']['TAP_BRANCH_PCLK'])) |
| 95 |
elif wire.startswith("GB"): |
| 96 |
return ctx.getDelayFromNS(max(timing['glbsrc']['BRANCH_PCLK'])) |
| 97 |
else: |
| 98 |
return ctx.getDelayFromNS(0) |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
def addPip(row, col, srcname, destname): |
| 103 |
gsrcname = chipdb.wire2global(row, col, db, srcname) |
| 104 |
gdestname = chipdb.wire2global(row, col, db, destname) |
| 105 |
|
| 106 |
pipname = f"R{row}C{col}_{srcname}_{destname}" |
| 107 |
|
| 108 |
try: |
| 109 |
|
| 110 |
ctx.addPip( |
| 111 |
name=pipname, type=destname, srcWire=gsrcname, dstWire=gdestname, |
| 112 |
delay=wiredelay(destname), loc=Loc(col, row, 0)) |
| 113 |
except IndexError: |
| 114 |
pass |
| 115 |
|
| 116 |
except AssertionError: |
| 117 |
pass |
| 118 |
|
| 119 |
|
| 120 |
def addAlias(row, col, srcname, destname): |
| 121 |
gsrcname = chipdb.wire2global(row, col, db, srcname) |
| 122 |
gdestname = chipdb.wire2global(row, col, db, destname) |
| 123 |
|
| 124 |
pipname = f"R{row}C{col}_{srcname}_{destname}" |
| 125 |
|
| 126 |
ctx.addPip( |
| 127 |
name=pipname+"_ALIAS", type=destname, srcWire=gsrcname, dstWire=gdestname, |
| 128 |
delay=ctx.getDelayFromNS(0), loc=Loc(col, row, 0)) |
| 129 |
|
| 130 |
|
| 131 |
for row, rowdata in enumerate(db.grid, 1): |
| 132 |
for col, tile in enumerate(rowdata, 1): |
| 133 |
for dest, srcs in tile.pips.items(): |
| 134 |
for src in srcs.keys(): |
| 135 |
addPip(row, col, src, dest) |
| 136 |
for dest, srcs in tile.clock_pips.items(): |
| 137 |
for src in srcs.keys(): |
| 138 |
addPip(row, col, src, dest) |
| 139 |
for dest, src in tile.aliases.items(): |
| 140 |
addAlias(row, col, src, dest) |
| 141 |
|
| 142 |
for (row, col, pip), (srow, scol, spip) in db.aliases.items(): |
| 143 |
dest = f"R{row+1}C{col+1}_{pip}" |
| 144 |
src = f"R{srow+1}C{scol+1}_{spip}" |
| 145 |
name = f"{src}_{dest}_ALIAS" |
| 146 |
ctx.addPip( |
| 147 |
name=name, type=dest, srcWire=src, dstWire=dest, |
| 148 |
delay=ctx.getDelayFromNS(0), loc=Loc(row+1, col+1, 0)) |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
ctx.setDelayScaling(0.1, 0.7) |
| 153 |
|
| 154 |
|