Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tang mega138k #1833

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions litex/build/gowin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ class GowinDifferentialOutput:
def lower(dr):
return GowinDifferentialOutputImpl(dr.i, dr.o_p, dr.o_n)

# Gowin Tristate -----------------------------------------------------------------------------------

class GowinTristateImpl(Module):
def __init__(self, io, o, oe, i):
nbits, _ = value_bits_sign(io)
for bit in range(nbits):
self.specials += Instance("IOBUF",
io_IO = io[bit] if nbits > 1 else io,
o_O = i[bit] if nbits > 1 else i,
i_I = o[bit] if nbits > 1 else o,
i_OEN = ~oe,
)

class GowinTristate:
@staticmethod
def lower(dr):
print(dr)
return GowinTristateImpl(dr.target, dr.o, dr.oe, dr.i)

# Gowin Special Overrides --------------------------------------------------------------------------

gowin_special_overrides = {
Expand All @@ -104,4 +123,5 @@ def lower(dr):
DDROutput: GowinDDROutput,
DifferentialInput: GowinDifferentialInput,
DifferentialOutput: GowinDifferentialOutput,
Tristate: GowinTristate,
}
30 changes: 28 additions & 2 deletions litex/build/gowin/gowin.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,41 @@ def build_io_constraints(self):
else:
flat_sc.append((name, pins[0], other))

def _search_pin_entry(pin_lst, pin_name):
for name, pin, other in pin_lst:
if pin_name == name:
return (name, pin, other)
return (None, None, None)

for name, pin, other in flat_sc:
if pin != "X":
t_name = name.split('[') # avoid index pins
tmp_name = t_name[0]
if tmp_name[-2:] == "_p":
pn = tmp_name[:-2] + "_n"
if len(t_name) > 1:
pn += '[' + t_name[1]
(_, n_pin, _) = _search_pin_entry(flat_sc, pn)
if n_pin is not None:
pin = f"{pin},{n_pin}"
elif tmp_name[-2:] == "_n":
pp = tmp_name[:-2] + "_p"
if len(t_name) > 1:
pp += '[' + t_name[1]
(p_name, _, _) = _search_pin_entry(flat_sc, pp)
if p_name is not None:
continue
cst.append(f"IO_LOC \"{name}\" {pin};")

other_cst = []
for c in other:
if isinstance(c, IOStandard):
cst.append(f"IO_PORT \"{name}\" IO_TYPE={c.name};")
other_cst.append(f"IO_TYPE={c.name}")
elif isinstance(c, Misc):
cst.append(f"IO_PORT \"{name}\" {c.misc};")
other_cst.append(f"{c.misc}")
if len(other_cst):
t = " ".join(other_cst)
cst.append(f"IO_PORT \"{name}\" {t};")

if self.named_pc:
cst.extend(self.named_pc)
Expand Down
Loading