| 1 |
from os import path |
| 2 |
import sys |
| 3 |
import argparse |
| 4 |
import xilinx_device |
| 5 |
import filters |
| 6 |
import struct |
| 7 |
import parse_sdf |
| 8 |
sys.path.append(path.join(path.dirname(__file__), "../../..")) |
| 9 |
from himbaechel_dbgen.chip import * |
| 10 |
|
| 11 |
def lookup_port_type(t): |
| 12 |
if t == "INPUT": return PinType.INPUT |
| 13 |
elif t == "OUTPUT": return PinType.OUTPUT |
| 14 |
elif t == "BIDIR": return PinType.INOUT |
| 15 |
else: assert False |
| 16 |
|
| 17 |
def gen_bel_name(site, bel_name): |
| 18 |
prim_st = site.primary.site_type() |
| 19 |
if prim_st in ("IOB33M", "IOB33S", "IOB33", "IOB18M", "IOB18S", "IOB18"): |
| 20 |
return f"{site.site_type()}.{bel_name}" |
| 21 |
else: |
| 22 |
return f"{bel_name}" |
| 23 |
|
| 24 |
@dataclass |
| 25 |
class PipClass(Enum): |
| 26 |
TILE_ROUTING = 0 |
| 27 |
SITE_ENTRANCE = 1 |
| 28 |
SITE_EXIT = 2 |
| 29 |
SITE_INTERNAL = 3 |
| 30 |
LUT_PERMUTATION = 4 |
| 31 |
LUT_ROUTETHRU = 5 |
| 32 |
CONST_DRIVER = 6 |
| 33 |
|
| 34 |
@dataclass |
| 35 |
class PipExtraData(BBAStruct): |
| 36 |
site_key: int = -1 |
| 37 |
bel_name: IdString = field(default_factory=IdString) |
| 38 |
pip_config: int = 0 |
| 39 |
|
| 40 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 41 |
pass |
| 42 |
def serialise(self, context: str, bba: BBAWriter): |
| 43 |
bba.u32(self.site_key) |
| 44 |
bba.u32(self.bel_name.index) |
| 45 |
bba.u32(self.pip_config) |
| 46 |
|
| 47 |
@dataclass |
| 48 |
class BelExtraData(BBAStruct): |
| 49 |
name_in_site: IdString |
| 50 |
|
| 51 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 52 |
pass |
| 53 |
def serialise(self, context: str, bba: BBAWriter): |
| 54 |
bba.u32(self.name_in_site.index) |
| 55 |
|
| 56 |
@dataclass |
| 57 |
class SiteInst(BBAStruct): |
| 58 |
name_prefix: IdString |
| 59 |
site_x: int |
| 60 |
site_y: int |
| 61 |
rel_x: int |
| 62 |
rel_y: int |
| 63 |
int_x: int |
| 64 |
int_y: int |
| 65 |
variants: list[IdString] = field(default_factory=list) |
| 66 |
|
| 67 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 68 |
bba.label(f"{context}_variants") |
| 69 |
for i, variant in enumerate(self.variants): |
| 70 |
bba.u32(variant.index) |
| 71 |
def serialise(self, context: str, bba: BBAWriter): |
| 72 |
bba.u32(self.name_prefix.index) |
| 73 |
bba.u16(self.site_x) |
| 74 |
bba.u16(self.site_y) |
| 75 |
bba.u16(self.rel_x) |
| 76 |
bba.u16(self.rel_y) |
| 77 |
bba.u16(self.int_x) |
| 78 |
bba.u16(self.int_y) |
| 79 |
bba.slice(f"{context}_variants", len(self.variants)) |
| 80 |
|
| 81 |
@dataclass |
| 82 |
class TileExtraData(BBAStruct): |
| 83 |
name_prefix: IdString |
| 84 |
tile_x: int |
| 85 |
tile_y: int |
| 86 |
sites: list[SiteInst] = field(default_factory=list) |
| 87 |
|
| 88 |
def serialise_lists(self, context: str, bba: BBAWriter): |
| 89 |
for i, site in enumerate(self.sites): |
| 90 |
site.serialise_lists(f"{context}_si{i}", bba) |
| 91 |
bba.label(f"{context}_sites") |
| 92 |
for i, site in enumerate(self.sites): |
| 93 |
site.serialise(f"{context}_si{i}", bba) |
| 94 |
def serialise(self, context: str, bba: BBAWriter): |
| 95 |
bba.u32(self.name_prefix.index) |
| 96 |
bba.u16(self.tile_x) |
| 97 |
bba.u16(self.tile_y) |
| 98 |
bba.slice(f"{context}_sites", len(self.sites)) |
| 99 |
|
| 100 |
def timing_pip_classs(pip: xilinx_device.PIP): |
| 101 |
return f"{'buf' if pip.is_buffered() else 'sw'}_d{pip.max_delay()}_r{pip.resistance()}_c{pip.capacitance()}" |
| 102 |
|
| 103 |
seen_pip_timings = set() |
| 104 |
seen_node_timings = set() |
| 105 |
|
| 106 |
def import_tiletype(ch: Chip, tile: xilinx_device.Tile): |
| 107 |
tile_type = tile.tile_type() |
| 108 |
if tile.x == 0 and tile.y == 0: |
| 109 |
assert tile_type == "NULL" |
| 110 |
tile_type = "NULL_CORNER" |
| 111 |
tt = ch.create_tile_type(tile_type) |
| 112 |
# import tile wires |
| 113 |
for wire in tile.wires(): |
| 114 |
nw = tt.create_wire(wire.name(), wire.intent()) |
| 115 |
nw.flags = -1 # not a site wire |
| 116 |
if wire.is_gnd(): |
| 117 |
nw.const_value = ch.strs.id("GND") |
| 118 |
if wire.is_vcc(): |
| 119 |
nw.const_value = ch.strs.id("VCC") |
| 120 |
if tile_type == "NULL_CORNER": |
| 121 |
# pseudo ground bels |
| 122 |
tt.create_wire(f"GND", "GND", const_value="GND") |
| 123 |
tt.create_wire(f"VCC", "VCC", const_value="VCC") |
| 124 |
|
| 125 |
gnd = tt.create_bel(f"PSEUDO_GND", f"PSEUDO_GND", z=0) |
| 126 |
gnd.site = -1 |
| 127 |
gnd.extra_data = BelExtraData(name_in_site=ch.strs.id("PSEUDO_GND")) |
| 128 |
gnd.flags |= BEL_FLAG_GLOBAL |
| 129 |
tt.add_bel_pin(gnd, "Y", "GND", PinType.OUTPUT) |
| 130 |
|
| 131 |
vcc = tt.create_bel(f"PSEUDO_VCC", f"PSEUDO_VCC", z=1) |
| 132 |
vcc.site = -1 |
| 133 |
vcc.extra_data = BelExtraData(name_in_site=ch.strs.id("PSEUDO_VCC")) |
| 134 |
vcc.flags |= BEL_FLAG_GLOBAL |
| 135 |
tt.add_bel_pin(vcc, "Y", "VCC", PinType.OUTPUT) |
| 136 |
def add_pip(src_wire, dst_wire, pip_class=PipClass.TILE_ROUTING, timing="", |
| 137 |
site_key=-1, bel_name="", pip_config=0): |
| 138 |
np = tt.create_pip(src_wire, dst_wire, timing) |
| 139 |
np.flags = pip_class.value |
| 140 |
np.extra_data = PipExtraData(site_key=site_key, bel_name=ch.strs.id(bel_name), |
| 141 |
pip_config=pip_config) |
| 142 |
|
| 143 |
def lookup_site_wire(sw): |
| 144 |
canon_name = f"{sw.site.rel_name()}.{sw.name()}" |
| 145 |
if not tt.has_wire(canon_name): |
| 146 |
nw = tt.create_wire(name=canon_name, |
| 147 |
type="INTENT_SITE_GND" if sw.name() == "GND_WIRE" else "INTENT_SITE_WIRE") |
| 148 |
nw.flags = sw.site.primary.index |
| 149 |
return canon_name |
| 150 |
|
| 151 |
def add_site_io_pip(pin): |
| 152 |
pn = pin.name() |
| 153 |
s = pin.site |
| 154 |
site_key = (s.index << 8) |
| 155 |
if pin.tile_wire() is None: |
| 156 |
return None |
| 157 |
# TODO: timing class |
| 158 |
if pin.dir() in ("OUTPUT", "BIDIR"): |
| 159 |
if s.primary.site_type() == "IPAD" and pn == "O": |
| 160 |
return None |
| 161 |
# if s.rel_xy()[0] == 0 and s.primary.site_type() == "SLICEL" and pin.site_wire().name() == "A": |
| 162 |
# # Add ground pip |
| 163 |
# # self.add_pseudo_pip(self.row_gnd_wire_index, self.sitewire_to_tilewire(pin.site_wire()), |
| 164 |
# # pip_type=NextpnrPipType.CONST_DRIVER) |
| 165 |
# pass |
| 166 |
add_pip(lookup_site_wire(pin.site_wire()), pin.tile_wire().name(), |
| 167 |
pip_class=PipClass.SITE_EXIT, timing="SITE_NULL") |
| 168 |
else: |
| 169 |
if s.site_type() in ("SLICEL", "SLICEM"): |
| 170 |
# Add permuation pseudo-pips for LUT inputs |
| 171 |
swn = pin.site_wire().name() |
| 172 |
if len(swn) == 2 and swn[0] in "ABCDEFGH" and swn[1] in "123456": |
| 173 |
i = int(swn[1]) |
| 174 |
for j in range(1, 7): |
| 175 |
if (i == 6) != (j == 6): |
| 176 |
continue # don't allow permutation of input 6 |
| 177 |
pip_config = ("ABCDEFGH".index(swn[0]) << 8) | ((j - 1) << 4) | (i - 1) |
| 178 |
if s.rel_xy()[0] == 1: |
| 179 |
pip_config |= (4 << 8) |
| 180 |
add_pip(s.pin(f"{swn[0]}{j}").tile_wire().name(), lookup_site_wire(pin.site_wire()), |
| 181 |
pip_class=PipClass.LUT_PERMUTATION, |
| 182 |
pip_config=pip_config, |
| 183 |
site_key=(s.index << 8), |
| 184 |
timing="SITE_NULL" |
| 185 |
) |
| 186 |
return |
| 187 |
add_pip(pin.tile_wire().name(), lookup_site_wire(pin.site_wire()), |
| 188 |
pip_class=PipClass.SITE_ENTRANCE, timing="SITE_NULL") |
| 189 |
|
| 190 |
# TODO: ground/vcc |
| 191 |
tile_wire_count = len(tt.wires) |
| 192 |
for site in tile.sites(): |
| 193 |
seen_pins = set() |
| 194 |
for variant_idx, variant in enumerate(site.available_variants()): |
| 195 |
if variant in ("FIFO36E1", ): #unsupported atm |
| 196 |
continue |
| 197 |
sv = site.variant(variant) |
| 198 |
variant_key = (site.index << 8) | (variant_idx & 0xFF) |
| 199 |
# Import site bels |
| 200 |
for bel in sv.bels(): |
| 201 |
z = filters.get_bel_z_override(bel, len(tt.bels)) |
| 202 |
# Overriden z of -1 means we skip this bel |
| 203 |
if z == -1: |
| 204 |
continue |
| 205 |
bel_name = gen_bel_name(sv, bel.name()) |
| 206 |
nb = tt.create_bel(name=f"{site.rel_name()}.{bel_name}", type=filters.get_bel_type_override(bel.bel_type()), z=z) |
| 207 |
nb.site = variant_key |
| 208 |
nb.extra_data = BelExtraData(name_in_site=ch.strs.id(bel_name)) |
| 209 |
if bel.bel_class() == "RBEL": nb.flags |= 2 |
| 210 |
if filters.is_global_bel(bel): |
| 211 |
nb.flags |= BEL_FLAG_GLOBAL |
| 212 |
# TODO: extra data (site etc) |
| 213 |
for pin in bel.pins(): |
| 214 |
tt.add_bel_pin(nb, pin.name, lookup_site_wire(pin.site_wire()), lookup_port_type(pin.dir())) |
| 215 |
# Import site pins |
| 216 |
for pin in sv.pins(): |
| 217 |
pin_key = (pin.name(), pin.site_wire().name()) |
| 218 |
if pin_key not in seen_pins: |
| 219 |
add_site_io_pip(pin) |
| 220 |
seen_pins.add(pin_key) |
| 221 |
# Import site pips |
| 222 |
for site_pip in sv.pips(): |
| 223 |
if "LUT" in site_pip.bel().bel_type(): |
| 224 |
continue # ignore site LUT route-throughs |
| 225 |
bel_name = site_pip.bel().name() |
| 226 |
bel_pin = site_pip.bel_input() |
| 227 |
if (bel_name == "ADI1MUX" and bel_pin == "BDI1") or \ |
| 228 |
(bel_name == "BDI1MUX" and bel_pin == "DI") or \ |
| 229 |
(bel_name == "CDI1MUX" and bel_pin == "DI") or \ |
| 230 |
(bel_name.startswith("TFBUSED")) or \ |
| 231 |
(bel_name == "OMUX"): |
| 232 |
continue |
| 233 |
add_pip(lookup_site_wire(site_pip.src_wire()), |
| 234 |
lookup_site_wire(site_pip.dst_wire()), |
| 235 |
pip_class=PipClass.SITE_INTERNAL, |
| 236 |
site_key=variant_key, |
| 237 |
bel_name=bel_name, |
| 238 |
pip_config=ch.strs.id(bel_pin).index, |
| 239 |
timing="SITE_NULL" |
| 240 |
) |
| 241 |
# Import tile pips |
| 242 |
for pip in tile.pips(): |
| 243 |
if not filters.include_pip(tile.tile_type(), pip): |
| 244 |
continue |
| 245 |
tcls = timing_pip_classs(pip) |
| 246 |
if tcls not in seen_pip_timings: |
| 247 |
ch.timing.set_pip_class(f"DEFAULT", tcls, |
| 248 |
delay=TimingValue(int(pip.min_delay()*1000), int(pip.max_delay()*1000)), # ps |
| 249 |
in_cap=TimingValue(int(pip.capacitance()*1000)), # fF |
| 250 |
out_res=TimingValue(int(pip.resistance())), # mohm |
| 251 |
is_buffered=pip.is_buffered()) |
| 252 |
seen_pip_timings.add(tcls) |
| 253 |
add_pip(pip.src_wire().name(), pip.dst_wire().name(), pip_class=PipClass.TILE_ROUTING, timing=tcls, |
| 254 |
pip_config=1 if pip.is_route_thru() else 0) |
| 255 |
# TODO: extra data, route-through flag |
| 256 |
if pip.is_bidi(): |
| 257 |
add_pip(pip.dst_wire().name(), pip.src_wire().name(), pip_class=PipClass.TILE_ROUTING, timing=tcls, |
| 258 |
pip_config=1 if pip.is_route_thru() else 0) |
| 259 |
|
| 260 |
def import_sdf_timings(variant, sdfcell): |
| 261 |
# TODO: anything other than comb |
| 262 |
for entry in sdfcell.entries: |
| 263 |
if isinstance(entry, parse_sdf.IOPath): |
| 264 |
variant.add_comb_arc(entry.from_pin, entry.to_pin, |
| 265 |
TimingValue(int(min(entry.rising.minv, entry.falling.minv)*1000), |
| 266 |
int(max(entry.rising.maxv, entry.falling.maxv)*1000))) |
| 267 |
|
| 268 |
def import_bram_timings(timing, sdf): |
| 269 |
def import_bus_sethold(cell, port, width, clock, entry): |
| 270 |
for i in range(width): |
| 271 |
cell.add_setup_hold(clock, f"{port}{i}", ClockEdge.RISING, TimingValue(int(entry.setup.minv*1000), int(entry.setup.maxv*1000)), |
| 272 |
TimingValue(int(entry.hold.minv*1000), int(entry.hold.maxv*1000))) |
| 273 |
|
| 274 |
def import_bus_clkq(cell, port, width, clock, entry): |
| 275 |
for i in range(width): |
| 276 |
cell.add_clock_out(clock, f"{port}{i}", ClockEdge.RISING, TimingValue(int(min(entry.rising.minv, entry.falling.minv)*1000), |
| 277 |
int(max(entry.rising.maxv, entry.falling.maxv)*1000))) |
| 278 |
|
| 279 |
|
| 280 |
def import_pin_sethold(cell, port, clock, entry): |
| 281 |
cell.add_setup_hold(clock, f"{port}", ClockEdge.RISING, TimingValue(int(entry.setup.minv*1000), int(entry.setup.maxv*1000)), |
| 282 |
TimingValue(int(entry.hold.minv*1000), int(entry.hold.maxv*1000))) |
| 283 |
|
| 284 |
for wsdp, rsdp in ((False, False), (False, True), (True, False), (True, True)): |
| 285 |
bram18 = timing.add_cell_variant("DEFAULT", f"RAMB18E1_RAMB18E1_{'WSDP' if wsdp else 'WTDP'}_{'RSDP' if rsdp else 'RTDP'}") |
| 286 |
|
| 287 |
for entry in sdf.cells[("RAMBFIFO36E1", "RAMBFIFO36E1")].entries: |
| 288 |
if isinstance(entry, parse_sdf.SetupHoldCheck): |
| 289 |
if entry.pin == "ADDRAU": import_bus_sethold(bram18, "ADDRARDADDR", 14, "CLKARDCLK", entry) |
| 290 |
if entry.pin == "ADDRBU": import_bus_sethold(bram18, "ADDRBWRADDR", 14, "CLKBWRCLK", entry) |
| 291 |
if entry.pin == "WEAU": import_bus_sethold(bram18, "WEA", 4, "CLKARDCLK", entry) |
| 292 |
if entry.pin == "WEBU": import_bus_sethold(bram18, "WEBWE", 8, "CLKBWRCLK", entry) |
| 293 |
for entry in sdf.cells[("RAMBFIFO36E1_ISFIFO_FALSE", "RAMBFIFO36E1")].entries: |
| 294 |
if isinstance(entry, parse_sdf.SetupHoldCheck): |
| 295 |
if entry.pin == "ENARDENU": import_pin_sethold(bram18, "ENARDEN", "CLKARDCLK", entry) |
| 296 |
if entry.pin == "ENBWRENU": import_pin_sethold(bram18, "ENBWREN", "CLKBWRCLK", entry) |
| 297 |
if entry.pin == "RSTRAMAU": import_pin_sethold(bram18, "RSTRAMARSTRAM", "CLKARDCLK", entry) |
| 298 |
if entry.pin == "RSTRAMBU": import_pin_sethold(bram18, "RSTRAMB", "CLKBWRCLK", entry) |
| 299 |
for entry in sdf.cells[("RAMBFIFO36E1RAM_MODE_RAMB18TDP_U_WRITE_MODE_U_NC_EN_ECC_READ_FALSE_EN_ECC_WRITE_FALSE", "RAMBFIFO36E1")].entries: |
| 300 |
if isinstance(entry, parse_sdf.SetupHoldCheck): |
| 301 |
if entry.pin == "DIADIU": import_bus_sethold(bram18, "DIADI", 16, "CLKBWRCLK" if wsdp else "CLKARDCLK", entry) |
| 302 |
if entry.pin == "DIBDIU": import_bus_sethold(bram18, "DIBDI", 16, "CLKBWRCLK", entry) |
| 303 |
if entry.pin == "DIPADIPU": import_bus_sethold(bram18, "DIPADIP", 2, "CLKBWRCLK" if wsdp else "CLKARDCLK", entry) |
| 304 |
if entry.pin == "DIPBDIPU": import_bus_sethold(bram18, "DIPBDIP", 2, "CLKBWRCLK", entry) |
| 305 |
for entry in sdf.cells[("RAMBFIFO36E1RAM_MODE_U_RAMB18SDP_U_DOA_REG_U_0_EN_ECC_READ_FALSE", "RAMBFIFO36E1")].entries: |
| 306 |
if isinstance(entry, parse_sdf.IOPath): |
| 307 |
if entry.to_pin == "DOADOU": import_bus_clkq(bram18, "DOADO", 16, "CLKARDCLK", entry) |
| 308 |
if entry.to_pin == "DOPADOPU": import_bus_clkq(bram18, "DOPADOP", 2, "CLKARDCLK", entry) |
| 309 |
for entry in sdf.cells[("RAMBFIFO36E1RAM_MODE_U_RAMB18TDP_U_DOB_REG_U_0_EN_ECC_READ_FALSE", "RAMBFIFO36E1")].entries: |
| 310 |
if isinstance(entry, parse_sdf.IOPath): |
| 311 |
if entry.to_pin == "DOBDOU": import_bus_clkq(bram18, "DOBDO", 16, "CLKARDCLK" if rsdp else "CLKBWRCLK", entry) |
| 312 |
if entry.to_pin == "DOPBDOPU": import_bus_clkq(bram18, "DOPBDOP", 2, "CLKARDCLK" if rsdp else "CLKBWRCLK", entry) |
| 313 |
|
| 314 |
bram36 = timing.add_cell_variant("DEFAULT", f"RAMB36E1_RAMB36E1_{'WSDP' if wsdp else 'WTDP'}_{'RSDP' if rsdp else 'RTDP'}") |
| 315 |
|
| 316 |
for u in ('L', 'U'): |
| 317 |
for entry in sdf.cells[("RAMBFIFO36E1", "RAMBFIFO36E1")].entries: |
| 318 |
if isinstance(entry, parse_sdf.SetupHoldCheck): |
| 319 |
if entry.pin == "ADDRAU": import_bus_sethold(bram36, f"ADDRARDADDR{u}", 15 if u == 'L' else 14, "CLKARDCLK", entry) |
| 320 |
if entry.pin == "ADDRBU": import_bus_sethold(bram36, f"ADDRBWRADDR{u}", 15 if u == 'L' else 14, "CLKBWRCLK", entry) |
| 321 |
if entry.pin == "WEAU": import_bus_sethold(bram36, f"WEA{u}", 4, f"CLKARDCLK{u}", entry) |
| 322 |
if entry.pin == "WEBU": import_bus_sethold(bram36, f"WEBWE{u}", 8, f"CLKBWRCLK{u}", entry) |
| 323 |
for entry in sdf.cells[("RAMBFIFO36E1_ISFIFO_FALSE", "RAMBFIFO36E1")].entries: |
| 324 |
if isinstance(entry, parse_sdf.SetupHoldCheck): |
| 325 |
if entry.pin == "ENARDENU": import_pin_sethold(bram36, f"ENARDEN{u}", f"CLKARDCLK{u}", entry) |
| 326 |
if entry.pin == "ENBWRENU": import_pin_sethold(bram36, f"ENBWREN{u}", f"CLKBWRCLK{u}", entry) |
| 327 |
if entry.pin == "RSTRAMAU": import_pin_sethold(bram36, f"RSTRAMARSTRAM{u}", f"CLKARDCLK{u}", entry) |
| 328 |
if entry.pin == "RSTRAMBU": import_pin_sethold(bram36, f"RSTRAMB{u}", f"CLKBWRCLK{u}", entry) |
| 329 |
for entry in sdf.cells[("RAMBFIFO36E1RAM_MODE_RAMB18TDP_U_WRITE_MODE_U_NC_EN_ECC_READ_FALSE_EN_ECC_WRITE_FALSE", "RAMBFIFO36E1")].entries: |
| 330 |
if isinstance(entry, parse_sdf.SetupHoldCheck): |
| 331 |
if entry.pin == "DIADIU": import_bus_sethold(bram36, "DIADI", 32, "CLKBWRCLK" if wsdp else "CLKARDCLK", entry) |
| 332 |
if entry.pin == "DIBDIU": import_bus_sethold(bram36, "DIBDI", 32, "CLKBWRCLK", entry) |
| 333 |
if entry.pin == "DIPADIPU": import_bus_sethold(bram36, "DIPADIP", 4, "CLKBWRCLK" if wsdp else "CLKARDCLK", entry) |
| 334 |
if entry.pin == "DIPBDIPU": import_bus_sethold(bram36, "DIPBDIP", 4, "CLKBWRCLK", entry) |
| 335 |
for entry in sdf.cells[("RAMBFIFO36E1RAM_MODE_U_RAMB18SDP_U_DOA_REG_U_0_EN_ECC_READ_FALSE", "RAMBFIFO36E1")].entries: |
| 336 |
if isinstance(entry, parse_sdf.IOPath): |
| 337 |
if entry.to_pin == "DOADOU": import_bus_clkq(bram36, "DOADO", 32, "CLKARDCLK", entry) |
| 338 |
if entry.to_pin == "DOPADOPU": import_bus_clkq(bram36, "DOPADOP", 4, "CLKARDCLK", entry) |
| 339 |
for entry in sdf.cells[("RAMBFIFO36E1RAM_MODE_U_RAMB18TDP_U_DOB_REG_U_0_EN_ECC_READ_FALSE", "RAMBFIFO36E1")].entries: |
| 340 |
if isinstance(entry, parse_sdf.IOPath): |
| 341 |
if entry.to_pin == "DOBDOU": import_bus_clkq(bram36, "DOBDO", 32, "CLKARDCLK" if rsdp else "CLKBWRCLK", entry) |
| 342 |
if entry.to_pin == "DOPBDOPU": import_bus_clkq(bram36, "DOPBDOP", 4, "CLKARDCLK" if rsdp else "CLKBWRCLK", entry) |
| 343 |
|
| 344 |
def main(): |
| 345 |
xlbase = path.join(path.dirname(path.realpath(__file__)), "..") |
| 346 |
|
| 347 |
parser = argparse.ArgumentParser() |
| 348 |
parser.add_argument("--xray", help="Project X-Ray device database path for current family (e.g. ../prjxray-db/artix7)", type=str, required=True) |
| 349 |
parser.add_argument("--metadata", help="nextpnr-xilinx site metadata root", type=str, default=path.join(xlbase, "meta", "artix7")) |
| 350 |
parser.add_argument("--device", help="name of device to export", type=str, required=True) |
| 351 |
parser.add_argument("--constids", help="name of nextpnr constids file to read", type=str, default=path.join(xlbase, "constids.inc")) |
| 352 |
parser.add_argument("--bba", help="bba file to write", type=str, required=True) |
| 353 |
args = parser.parse_args() |
| 354 |
|
| 355 |
# Init database paths |
| 356 |
metadata_root = args.metadata |
| 357 |
xraydb_root = args.xray |
| 358 |
if "xc7z" in args.device: |
| 359 |
metadata_root = metadata_root.replace("artix7", "zynq7") |
| 360 |
xraydb_root = xraydb_root.replace("artix7", "zynq7") |
| 361 |
if "xc7k" in args.device: |
| 362 |
metadata_root = metadata_root.replace("artix7", "kintex7") |
| 363 |
xraydb_root = xraydb_root.replace("artix7", "kintex7") |
| 364 |
if "xc7s" in args.device: |
| 365 |
metadata_root = metadata_root.replace("artix7", "spartan7") |
| 366 |
xraydb_root = xraydb_root.replace("artix7", "spartan7") |
| 367 |
# Load prjxray device data |
| 368 |
d = xilinx_device.import_device(args.device, xraydb_root, metadata_root) |
| 369 |
# Init constant ids |
| 370 |
ch = Chip("xilinx", args.device, d.width, d.height) |
| 371 |
ch.strs.read_constids(path.join(path.dirname(__file__), args.constids)) |
| 372 |
ch.set_speed_grades(["DEFAULT", ]) # TODO: figure out how speed grades are supposed to work in prjxray |
| 373 |
# Import tile types |
| 374 |
for tile in d.tiles: |
| 375 |
tile_type = tile.tile_type() |
| 376 |
if tile.x == 0 and tile.y == 0: |
| 377 |
assert tile_type == "NULL" |
| 378 |
# location for pseudo gnd/vcc bels |
| 379 |
tile_type = "NULL_CORNER" |
| 380 |
if tile_type not in ch.tile_type_idx: |
| 381 |
import_tiletype(ch, tile) |
| 382 |
ti = ch.set_tile_type(tile.x, tile.y, tile_type) |
| 383 |
prefix, tx, ty = tile.split_name() |
| 384 |
ti.extra_data = TileExtraData(ch.strs.id(prefix), tx, ty) |
| 385 |
for site in tile.sites(): |
| 386 |
ti.extra_data.sites.append(SiteInst( |
| 387 |
name_prefix=ch.strs.id(site.prefix), |
| 388 |
site_x=site.grid_xy[0], site_y=site.grid_xy[1], |
| 389 |
rel_x=site.rel_xy()[0], rel_y=site.rel_xy()[1], |
| 390 |
int_x=tile.interconn_xy[0], int_y=tile.interconn_xy[1], |
| 391 |
variants=[ch.strs.id(v) for v in site.available_variants()] |
| 392 |
)) |
| 393 |
# Import nodes |
| 394 |
seen_nodes = set() |
| 395 |
tt_used_wires = {} |
| 396 |
print("Processing nodes...") |
| 397 |
for row in range(d.height): |
| 398 |
# TODO: GND and VCC row connectivity... |
| 399 |
for col in range(d.width): |
| 400 |
t = d.tiles_by_xy[col, row] |
| 401 |
for w in t.wires(): |
| 402 |
n = w.node() |
| 403 |
uid = n.unique_index() |
| 404 |
if uid in seen_nodes: |
| 405 |
continue |
| 406 |
if len(n.wires) > 1: |
| 407 |
node_wires = [] |
| 408 |
node_cap = 0 |
| 409 |
node_res = 0 |
| 410 |
# Add interconnect tiles first for better delay estimates in nextpnr |
| 411 |
for j in range(2): |
| 412 |
for w in n.wires: |
| 413 |
if (w.tile.tile_type() in ("INT", "INT_L", "INT_R")) != (j == 0): |
| 414 |
continue |
| 415 |
if w.tile.tile_type() not in tt_used_wires: |
| 416 |
tt_used_wires[w.tile.tile_type()] = w.tile.used_wire_indices() |
| 417 |
node_cap += int(w.capacitance() * 1000) |
| 418 |
node_res += int(w.resistance()) |
| 419 |
# prune wires from nodes that just pass through a tile without connecting to |
| 420 |
# bels/pips, because nextpnr doesn't care about these |
| 421 |
if w.index not in tt_used_wires[w.tile.tile_type()]: |
| 422 |
continue |
| 423 |
node_wires.append(NodeWire(w.tile.x, w.tile.y, w.index)) |
| 424 |
if len(node_wires) > 1: |
| 425 |
timing_class = f"node_c{node_cap}_c{node_res}" |
| 426 |
ch.add_node(node_wires, timing_class=timing_class) |
| 427 |
if timing_class not in seen_node_timings: |
| 428 |
ch.timing.set_node_class("DEFAULT", timing_class, delay=TimingValue(0), cap=TimingValue(node_cap), res=TimingValue(node_res)) |
| 429 |
seen_node_timings.add(timing_class) |
| 430 |
del node_wires |
| 431 |
seen_nodes.add(uid) |
| 432 |
# Stub timing class |
| 433 |
ch.timing.set_pip_class("DEFAULT", "SITE_NULL", delay=TimingValue(20)) |
| 434 |
# Stub bel timings |
| 435 |
lut = ch.timing.add_cell_variant("DEFAULT", "SLICE_LUTX") |
| 436 |
for i in range(1, 6+1): |
| 437 |
lut.add_comb_arc(f"A{i}", "O6", TimingValue(100, 125)) |
| 438 |
if i <= 5: lut.add_comb_arc(f"A{i}", "O5", TimingValue(120, 150)) |
| 439 |
for i in range(1, 8+1): |
| 440 |
lut.add_setup_hold("CLK", f"WA{i}", ClockEdge.RISING, TimingValue(100, 500), TimingValue(100, 200)) |
| 441 |
lut.add_setup_hold("CLK", "WE", ClockEdge.RISING, TimingValue(100, 600), TimingValue(100, 100)) |
| 442 |
lut.add_setup_hold("CLK", "DI1", ClockEdge.RISING, TimingValue(100, 100), TimingValue(100, 100)) |
| 443 |
ff = ch.timing.add_cell_variant("DEFAULT", "SLICE_FFX") |
| 444 |
ff.add_setup_hold("CK", "CE", ClockEdge.RISING, TimingValue(100, 100), TimingValue(0, 0)) |
| 445 |
ff.add_setup_hold("CK", "SR", ClockEdge.RISING, TimingValue(100, 100), TimingValue(0, 0)) |
| 446 |
ff.add_setup_hold("CK", "D", ClockEdge.RISING, TimingValue(100, 100), TimingValue(200, 200)) |
| 447 |
ff.add_clock_out("CK", "Q", ClockEdge.RISING, TimingValue(300, 350)) |
| 448 |
|
| 449 |
# Load SDF for carry and mux |
| 450 |
timings_root = xraydb_root |
| 451 |
if "kintex7" in xraydb_root: # TODO: missing |
| 452 |
timings_root = xraydb_root.replace("kintex7", "artix7") |
| 453 |
slicem_sdf = parse_sdf.parse_sdf_file(path.join(timings_root, "timings", "slicem.sdf")) |
| 454 |
mux = ch.timing.add_cell_variant("DEFAULT", "SELMUX2_1") |
| 455 |
import_sdf_timings(mux, slicem_sdf.cells[("SELMUX2_1", "SLICEM/F7BMUX")]) |
| 456 |
carry = ch.timing.add_cell_variant("DEFAULT", "CARRY4") |
| 457 |
import_sdf_timings(carry, slicem_sdf.cells[("CARRY4", "SLICEM")]) |
| 458 |
|
| 459 |
import_bram_timings(ch.timing, parse_sdf.parse_sdf_file(path.join(timings_root, "timings", "BRAM_L.sdf"))) |
| 460 |
|
| 461 |
# Import package pins |
| 462 |
for package_name, package in sorted(d.packages.items(), key=lambda x:x[0]): |
| 463 |
pkg = ch.create_package(package_name) |
| 464 |
for pin, site in sorted(package.pin_map.items(), key=lambda x:x[0]): |
| 465 |
site_data = d.sites_by_name[site] |
| 466 |
bel_name = gen_bel_name(site_data, "PAD") |
| 467 |
tile_type = ch.tile_type_at(site_data.tile.x, site_data.tile.y) |
| 468 |
pkg.create_pad(pin, f"X{site_data.tile.x}Y{site_data.tile.y}", |
| 469 |
f"{site_data.rel_name()}.{bel_name}", |
| 470 |
"", 0) # TODO: bank |
| 471 |
ch.write_bba(args.bba) |
| 472 |
|
| 473 |
if __name__ == '__main__': |
| 474 |
main() |