2014-08-06 07:26:00 -04:00
|
|
|
import os
|
2015-06-18 18:30:22 -04:00
|
|
|
import sys
|
2014-08-06 07:26:00 -04:00
|
|
|
from distutils.version import StrictVersion
|
|
|
|
|
2014-06-07 06:24:19 -04:00
|
|
|
from migen.fhdl.std import *
|
2014-08-06 07:26:00 -04:00
|
|
|
from migen.fhdl.specials import SynthesisDirective
|
|
|
|
from migen.genlib.cdc import *
|
2015-03-14 05:45:11 -04:00
|
|
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
|
|
|
from migen.genlib.io import *
|
2014-08-06 07:26:00 -04:00
|
|
|
from mibuild import tools
|
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:26:00 -04:00
|
|
|
def settings(path, ver=None, sub=None):
|
2015-04-13 14:07:07 -04:00
|
|
|
vers = list(tools.versions(path))
|
|
|
|
if ver is None:
|
|
|
|
ver = max(vers)
|
|
|
|
else:
|
|
|
|
ver = StrictVersion(ver)
|
|
|
|
assert ver in vers
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
full = os.path.join(path, str(ver))
|
|
|
|
if sub:
|
|
|
|
full = os.path.join(full, sub)
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
search = [64, 32]
|
|
|
|
if tools.arch_bits() == 32:
|
|
|
|
search.reverse()
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-06-18 18:30:22 -04:00
|
|
|
if sys.platform == "win32" or sys.platform == "cygwin":
|
|
|
|
script_ext = "bat"
|
|
|
|
else:
|
|
|
|
script_ext = "sh"
|
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
for b in search:
|
2015-06-18 18:30:22 -04:00
|
|
|
settings = os.path.join(full, "settings{0}.{1}".format(b, script_ext))
|
2015-04-13 14:07:07 -04:00
|
|
|
if os.path.exists(settings):
|
|
|
|
return settings
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
raise OSError("no settings file found")
|
2014-06-07 06:24:19 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:26:00 -04:00
|
|
|
class XilinxNoRetimingImpl(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, reg):
|
|
|
|
self.specials += SynthesisDirective("attribute register_balancing of {r} is no", r=reg)
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:26:00 -04:00
|
|
|
class XilinxNoRetiming:
|
2015-04-13 14:07:07 -04:00
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
return XilinxNoRetimingImpl(dr.reg)
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:26:00 -04:00
|
|
|
class XilinxMultiRegImpl(MultiRegImpl):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
MultiRegImpl.__init__(self, *args, **kwargs)
|
|
|
|
self.specials += [SynthesisDirective("attribute shreg_extract of {r} is no", r=r)
|
|
|
|
for r in self.regs]
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:26:00 -04:00
|
|
|
class XilinxMultiReg:
|
2015-04-13 14:07:07 -04:00
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
return XilinxMultiRegImpl(dr.i, dr.o, dr.odomain, dr.n)
|
2014-08-06 07:26:00 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:38:37 -04:00
|
|
|
class XilinxAsyncResetSynchronizerImpl(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, cd, async_reset):
|
|
|
|
rst1 = Signal()
|
|
|
|
self.specials += [
|
|
|
|
Instance("FDPE", p_INIT=1, i_D=0, i_PRE=async_reset,
|
|
|
|
i_CE=1, i_C=cd.clk, o_Q=rst1),
|
|
|
|
Instance("FDPE", p_INIT=1, i_D=rst1, i_PRE=async_reset,
|
|
|
|
i_CE=1, i_C=cd.clk, o_Q=cd.rst)
|
|
|
|
]
|
2014-08-06 07:38:37 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2014-08-06 07:38:37 -04:00
|
|
|
class XilinxAsyncResetSynchronizer:
|
2015-04-13 14:07:07 -04:00
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
return XilinxAsyncResetSynchronizerImpl(dr.cd, dr.async_reset)
|
2014-08-06 07:38:37 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-03-12 13:32:49 -04:00
|
|
|
class XilinxDifferentialInputImpl(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, i_p, i_n, o):
|
|
|
|
self.specials += Instance("IBUFDS", i_I=i_p, i_IB=i_n, o_O=o)
|
2015-03-12 13:32:49 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-03-12 13:32:49 -04:00
|
|
|
class XilinxDifferentialInput:
|
2015-04-13 14:07:07 -04:00
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
return XilinxDifferentialInputImpl(dr.i_p, dr.i_n, dr.o)
|
2015-03-12 13:32:49 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-03-12 14:30:57 -04:00
|
|
|
class XilinxDifferentialOutputImpl(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, i, o_p, o_n):
|
|
|
|
self.specials += Instance("OBUFDS", i_I=i, o_O=o_p, o_OB=o_n)
|
2015-03-12 14:30:57 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-03-12 14:30:57 -04:00
|
|
|
class XilinxDifferentialOutput:
|
2015-04-13 14:07:07 -04:00
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
return XilinxDifferentialOutputImpl(dr.i, dr.o_p, dr.o_n)
|
2015-03-14 05:45:11 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-03-16 17:53:05 -04:00
|
|
|
class XilinxDDROutputImpl(Module):
|
2015-07-02 03:32:33 -04:00
|
|
|
def __init__(self, i1, i2, o, clk):
|
|
|
|
self.specials += Instance("ODDR2",
|
|
|
|
p_DDR_ALIGNMENT="NONE", p_INIT=0, p_SRTYPE="SYNC",
|
|
|
|
i_C0=clk, i_C1=~clk, i_CE=1, i_S=0, i_R=0,
|
|
|
|
i_D0=i1, i_D1=i2, o_Q=o,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class XilinxDDROutput:
|
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
return XilinxDDROutputImpl(dr.i1, dr.i2, dr.o, dr.clk)
|
|
|
|
|
|
|
|
|
|
|
|
xilinx_special_overrides = {
|
|
|
|
NoRetiming: XilinxNoRetiming,
|
|
|
|
MultiReg: XilinxMultiReg,
|
|
|
|
AsyncResetSynchronizer: XilinxAsyncResetSynchronizer,
|
|
|
|
DifferentialInput: XilinxDifferentialInput,
|
|
|
|
DifferentialOutput: XilinxDifferentialOutput,
|
|
|
|
DDROutput: XilinxDDROutput
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class XilinxDDROutputImplS7(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self, i1, i2, o, clk):
|
|
|
|
self.specials += Instance("ODDR",
|
|
|
|
p_DDR_CLK_EDGE="SAME_EDGE",
|
|
|
|
i_C=clk, i_CE=1, i_S=0, i_R=0,
|
|
|
|
i_D1=i1, i_D2=i2, o_Q=o,
|
|
|
|
)
|
2015-03-16 17:53:05 -04:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2015-07-02 03:32:33 -04:00
|
|
|
class XilinxDDROutputS7:
|
2015-04-13 14:07:07 -04:00
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
2015-07-02 03:32:33 -04:00
|
|
|
return XilinxDDROutputImplS7(dr.i1, dr.i2, dr.o, dr.clk)
|
2015-03-16 17:53:05 -04:00
|
|
|
|
2015-07-02 03:32:33 -04:00
|
|
|
|
|
|
|
xilinx_s7_special_overrides = {
|
|
|
|
DDROutput: XilinxDDROutputS7
|
2015-03-14 05:45:11 -04:00
|
|
|
}
|