| 1 |
from write_fasm import * |
| 2 |
import re |
| 3 |
from apycula import codegen |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
param_map = { |
| 8 |
("GENERIC_SLICE", "K"): ParameterConfig(write=False), |
| 9 |
("GENERIC_SLICE", "INIT"): ParameterConfig(write=True, numeric=True, width=2**4), |
| 10 |
("GENERIC_SLICE", "FF_USED"): ParameterConfig(write=True, numeric=True, width=1), |
| 11 |
|
| 12 |
("GENERIC_IOB", "INPUT_USED"): ParameterConfig(write=True, numeric=True, width=1), |
| 13 |
("GENERIC_IOB", "OUTPUT_USED"): ParameterConfig(write=True, numeric=True, width=1), |
| 14 |
("GENERIC_IOB", "ENABLE_USED"): ParameterConfig(write=True, numeric=True, width=1), |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
def write_posp(f): |
| 20 |
belre = re.compile(r"R(\d+)C(\d+)_(SLICE|IOB)(\w)") |
| 21 |
namere = re.compile(r"\W+") |
| 22 |
for name, cell in ctx.cells: |
| 23 |
row, col, typ, idx = belre.match(cell.bel).groups() |
| 24 |
row = int(row) |
| 25 |
col = int(col) |
| 26 |
name = namere.sub('_', name) |
| 27 |
if typ == 'SLICE': |
| 28 |
idx = int(idx) |
| 29 |
cls = idx//2 |
| 30 |
side = ['A', 'B'][idx%2] |
| 31 |
lutname = name + "_LUT" |
| 32 |
f.write(f"{lutname} PLACE_R{row}C{col}[{cls}][{side}]\n") |
| 33 |
|
| 34 |
lut = codegen.Primitive("LUT4", lutname) |
| 35 |
|
| 36 |
lut.portmap['F'] = f"R{row}C{col}_F{idx}" |
| 37 |
lut.portmap['I0'] = f"R{row}C{col}_A{idx}" |
| 38 |
lut.portmap['I1'] = f"R{row}C{col}_B{idx}" |
| 39 |
lut.portmap['I2'] = f"R{row}C{col}_C{idx}" |
| 40 |
lut.portmap['I3'] = f"R{row}C{col}_D{idx}" |
| 41 |
mod.wires.update(lut.portmap.values()) |
| 42 |
mod.primitives[lutname] = lut |
| 43 |
|
| 44 |
if int(cell.params['FF_USED'], 2): |
| 45 |
dffname = name + "_DFF" |
| 46 |
f.write(f"{dffname} PLACE_R{row}C{col}[{cls}][{side}]\n") |
| 47 |
|
| 48 |
lut = codegen.Primitive("DFF", dffname) |
| 49 |
lut.portmap['D'] = f"R{row}C{col}_F{idx}" |
| 50 |
lut.portmap['Q'] = f"R{row}C{col}_Q{idx}" |
| 51 |
lut.portmap['CLK'] = f"R{row}C{col}_CLK{idx}" |
| 52 |
mod.wires.update(lut.portmap.values()) |
| 53 |
mod.primitives[dffname] = lut |
| 54 |
elif typ == 'IOB': |
| 55 |
if row == 1: |
| 56 |
edge = 'T' |
| 57 |
num = col |
| 58 |
elif col == 1: |
| 59 |
edge = 'L' |
| 60 |
num = row |
| 61 |
elif col == 47: |
| 62 |
edge = 'R' |
| 63 |
num = row |
| 64 |
else: |
| 65 |
edge = 'B' |
| 66 |
num = col |
| 67 |
f.write(f"{name} PLACE_IO{edge}{num}[{idx}]\n") |
| 68 |
|
| 69 |
iob = codegen.Primitive("IOBUF", name) |
| 70 |
iob.portmap['I'] = f"R{row}C{col}_I{idx}" |
| 71 |
iob.portmap['O'] = f"R{row}C{col}_O{idx}" |
| 72 |
iob.portmap['IO'] = f"R{row}C{col}_IO{idx}" |
| 73 |
iob.portmap['OEN'] = f"R{row}C{col}_OEN{idx}" |
| 74 |
mod.wires.update(iob.portmap.values()) |
| 75 |
mod.inouts.add(f"R{row}C{col}_IO{idx}") |
| 76 |
mod.primitives[name] = iob |
| 77 |
|
| 78 |
|
| 79 |
with open("blinky.fasm", "w") as f: |
| 80 |
write_fasm(ctx, param_map, f) |
| 81 |
|
| 82 |
mod = codegen.Module() |
| 83 |
with open("blinky.posp", "w") as f: |
| 84 |
write_posp(f) |
| 85 |
|
| 86 |
with open("blinky.vm", "w") as f: |
| 87 |
mod.write(f) |
| 88 |
|
| 89 |
|