Skip to content

Commit

Permalink
build/gowin/common.py: re-add tristate impl and SDRxxx for GW5A/Arora…
Browse files Browse the repository at this point in the history
… family (required for SDRAM use)
  • Loading branch information
trabucayre committed Aug 4, 2024
1 parent f855417 commit 3cd8209
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 12 deletions.
90 changes: 78 additions & 12 deletions litex/build/gowin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,19 @@ class GowinDifferentialOutput:
def lower(dr):
return GowinDifferentialOutputImpl(dr.i, dr.o_p, dr.o_n)

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

gowin_special_overrides = {
AsyncResetSynchronizer: GowinAsyncResetSynchronizer,
DDRInput: GowinDDRInput,
DDROutput: GowinDDROutput,
DifferentialInput: GowinDifferentialInput,
DifferentialOutput: GowinDifferentialOutput,
}

class GowinTristateImpl(Module):
# Gw5A Tristate ------------------------------------------------------------------------------------

class Gw5ATristateImpl(Module):
def __init__(self, io, o, oe, i):
nbits, _ = value_bits_sign(io)
for bit in range(nbits):
Expand All @@ -113,18 +123,74 @@ def __init__(self, io, o, oe, i):
i_OEN = ~oe,
)

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

# Gw5A SDROutput -----------------------------------------------------------------------------------

class Gw5ASDROutputImpl(Module):
def __init__(self, i, o, clk):
self.specials += Instance("DFFSE",
i_D = i,
o_Q = o,
i_CLK = clk,
i_SET = Constant(0,1),
i_CE = Constant(1,1),
)

# Gowin Special Overrides --------------------------------------------------------------------------
class Gw5ASDROutput:
@staticmethod
def lower(dr):
return Gw5ASDROutputImpl(dr.i, dr.o, dr.clk)

# Gw5A SDRInput ------------------------------------------------------------------------------------

class Gw5ASDRInputImpl(Module):
def __init__(self, i, o, clk):
self.specials += Instance("DFFSE",
i_D = i,
o_Q = o,
i_CLK = clk,
i_SET = Constant(0,1),
i_CE = Constant(1,1),
)

gowin_special_overrides = {
AsyncResetSynchronizer: GowinAsyncResetSynchronizer,
DDRInput: GowinDDRInput,
DDROutput: GowinDDROutput,
DifferentialInput: GowinDifferentialInput,
DifferentialOutput: GowinDifferentialOutput,
#Tristate: GowinTristate, # FIXME: issue with tangNano9k hyperram
class Gw5ASDRInput:
@staticmethod
def lower(dr):
return Gw5ASDRInputImpl(dr.i, dr.o, dr.clk)

# Gw5A SDRTristate ---------------------------------------------------------------------------------

class Gw5ASDRTristateImpl(Module):
def __init__(self, io, o, oe, i, clk):
_o = Signal()
_oe_n = Signal()
_i = Signal()
self.specials += [
SDROutput(o, _o, clk),
SDROutput(~oe, _oe_n, clk),
SDRInput(_i, i, clk),
Instance("IOBUF",
io_IO = io,
o_O = _i,
i_I = _o,
i_OEN = _oe_n,
),
]

class Gw5ASDRTristate:
@staticmethod
def lower(dr):
return Gw5ASDRTristateImpl(dr.io, dr.o, dr.oe, dr.i, dr.clk)

# Gw5A Special Overrides ---------------------------------------------------------------------------

gw5a_special_overrides = {
SDRTristate: Gw5ASDRTristate,
SDROutput: Gw5ASDROutput,
SDRInput: Gw5ASDRInput,
Tristate: Gw5ATristate,
}
2 changes: 2 additions & 0 deletions litex/build/gowin/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(self, device, *args, toolchain="gowin", devicename=None, **kwargs):

def get_verilog(self, *args, special_overrides=dict(), **kwargs):
so = dict(common.gowin_special_overrides)
if self.device[:4] == "GW5A":
so.update(common.gw5a_special_overrides)
so.update(special_overrides)
return GenericPlatform.get_verilog(self, *args,
special_overrides = so,
Expand Down

0 comments on commit 3cd8209

Please sign in to comment.