Skip to content

Commit

Permalink
Merge pull request #1833 from trabucayre/tangMega138k
Browse files Browse the repository at this point in the history
Tang mega138k
  • Loading branch information
enjoy-digital authored Nov 9, 2023
2 parents f9dc8e8 + 93ce42f commit d2441c6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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

0 comments on commit d2441c6

Please sign in to comment.