Skip to content

Instantly share code, notes, and snippets.

@tzechienchu
Created December 30, 2022 05:01
Show Gist options
  • Save tzechienchu/7daa662469d1283f45b81b919abef4e2 to your computer and use it in GitHub Desktop.
Save tzechienchu/7daa662469d1283f45b81b919abef4e2 to your computer and use it in GitHub Desktop.
ECP5 IO Define
# ECP5 AsyncResetSynchronizer ----------------------------------------------------------------------
class LatticeECP5AsyncResetSynchronizerImpl(Module):
def __init__(self, cd, async_reset):
rst1 = Signal()
self.specials += [
Instance("FD1S3BX",
i_D = 0,
i_PD = async_reset,
i_CK = cd.clk,
o_Q = rst1
),
Instance("FD1S3BX",
i_D = rst1,
i_PD = async_reset,
i_CK = cd.clk,
o_Q = cd.rst)
]
class LatticeECP5AsyncResetSynchronizer:
@staticmethod
def lower(dr):
return LatticeECP5AsyncResetSynchronizerImpl(dr.cd, dr.async_reset)
# ECP5 SDR Input -----------------------------------------------------------------------------------
class LatticeECP5SDRInputImpl(Module):
def __init__(self, i, o, clk):
self.specials += Instance("IFS1P3BX",
i_SCLK = clk,
i_PD = 0,
i_SP = 1,
i_D = i,
o_Q = o,
)
class LatticeECP5SDRInput:
@staticmethod
def lower(dr):
return LatticeECP5SDRInputImpl(dr.i, dr.o, dr.clk)
# ECP5 SDR Output ----------------------------------------------------------------------------------
class LatticeECP5SDROutputImpl(Module):
def __init__(self, i, o, clk):
self.specials += Instance("OFS1P3BX",
i_SCLK = clk,
i_PD = 0,
i_SP = 1,
i_D = i,
o_Q = o,
)
class LatticeECP5SDROutput:
@staticmethod
def lower(dr):
return LatticeECP5SDROutputImpl(dr.i, dr.o, dr.clk)
# ECP5 DDR Input -----------------------------------------------------------------------------------
class LatticeECP5DDRInputImpl(Module):
def __init__(self, i, o1, o2, clk):
self.specials += Instance("IDDRX1F",
i_SCLK = clk,
i_D = i,
o_Q0 = o1,
o_Q1 = o2,
)
class LatticeECP5DDRInput:
@staticmethod
def lower(dr):
return LatticeECP5DDRInputImpl(dr.i, dr.o1, dr.o2, dr.clk)
# ECP5 DDR Output ----------------------------------------------------------------------------------
class LatticeECP5DDROutputImpl(Module):
def __init__(self, i1, i2, o, clk):
self.specials += Instance("ODDRX1F",
i_SCLK = clk,
i_D0 = i1,
i_D1 = i2,
o_Q = o,
)
class LatticeECP5DDROutput:
@staticmethod
def lower(dr):
return LatticeECP5DDROutputImpl(dr.i1, dr.i2, dr.o, dr.clk)
# ECP5 Differential Input --------------------------------------------------------------------------
class LatticeECP5DifferentialInputImpl(Module):
def __init__(self, i_p, i_n, o):
self.specials += Instance("ILVDS",
i_A = i_p,
i_AN = i_n,
o_Z = o,
)
class LatticeECP5DifferentialInput:
@staticmethod
def lower(dr):
return LatticeECP5DifferentialInputImpl(dr.i_p, dr.i_n, dr.o)
# ECP5 Differential Output -------------------------------------------------------------------------
class LatticeECP5DifferentialOutputImpl(Module):
def __init__(self, i, o_p, o_n):
self.specials += Instance("OLVDS",
i_A = i,
o_Z = o_p,
o_ZN = o_n,
)
class LatticeECP5DifferentialOutput:
@staticmethod
def lower(dr):
return LatticeECP5DifferentialOutputImpl(dr.i, dr.o_p, dr.o_n)
# ECP5 Special Overrides ---------------------------------------------------------------------------
lattice_ecp5_special_overrides = {
AsyncResetSynchronizer: LatticeECP5AsyncResetSynchronizer,
SDRInput: LatticeECP5SDRInput,
SDROutput: LatticeECP5SDROutput,
DDRInput: LatticeECP5DDRInput,
DDROutput: LatticeECP5DDROutput,
DifferentialInput: LatticeECP5DifferentialInput,
DifferentialOutput: LatticeECP5DifferentialOutput,
}
# ECP5 Trellis Tristate ----------------------------------------------------------------------------
class LatticeECP5TrellisTristateImpl(Module):
def __init__(self, io, o, oe, i):
nbits, sign = value_bits_sign(io)
for bit in range(nbits):
self.specials += Instance("TRELLIS_IO",
p_DIR = "BIDIR",
i_B = io[bit] if nbits > 1 else io,
i_I = o[bit] if nbits > 1 else o,
o_O = i[bit] if nbits > 1 else i,
i_T = ~oe
)
class LatticeECP5TrellisTristate(Module):
@staticmethod
def lower(dr):
return LatticeECP5TrellisTristateImpl(dr.target, dr.o, dr.oe, dr.i)
# ECP5 Trellis Special Overrides -------------------------------------------------------------------
lattice_ecp5_trellis_special_overrides = {
AsyncResetSynchronizer: LatticeECP5AsyncResetSynchronizer,
Tristate: LatticeECP5TrellisTristate,
SDRInput: LatticeECP5SDRInput,
SDROutput: LatticeECP5SDROutput,
DDRInput: LatticeECP5DDRInput,
DDROutput: LatticeECP5DDROutput,
DifferentialInput: LatticeECP5DifferentialInput,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment