2015-03-12 13:32:49 -04:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
from migen.fhdl.specials import Special
|
|
|
|
from migen.fhdl.tools import list_signals
|
|
|
|
|
|
|
|
class DifferentialInput(Special):
|
|
|
|
def __init__(self, i_p, i_n, o):
|
|
|
|
Special.__init__(self)
|
|
|
|
self.i_p = i_p
|
|
|
|
self.i_n = i_n
|
|
|
|
self.o = o
|
|
|
|
|
|
|
|
def iter_expressions(self):
|
|
|
|
yield self, "i_p", SPECIAL_INPUT
|
|
|
|
yield self, "i_n", SPECIAL_INPUT
|
|
|
|
yield self, "o", SPECIAL_OUTPUT
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
2015-03-12 13:49:49 -04:00
|
|
|
raise NotImplementedError("Attempted to use a differential input, but platform does not support them")
|
2015-03-12 14:30:57 -04:00
|
|
|
|
|
|
|
class DifferentialOutput(Special):
|
|
|
|
def __init__(self, i, o_p, o_n):
|
|
|
|
Special.__init__(self)
|
|
|
|
self.i = i
|
|
|
|
self.o_p = o_p
|
|
|
|
self.o_n = o_n
|
|
|
|
|
|
|
|
def iter_expressions(self):
|
|
|
|
yield self, "i", SPECIAL_INPUT
|
|
|
|
yield self, "o_p", SPECIAL_OUTPUT
|
|
|
|
yield self, "o_n", SPECIAL_OUTPUT
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
raise NotImplementedError("Attempted to use a differential output, but platform does not support them")
|
2015-03-13 19:10:08 -04:00
|
|
|
|
|
|
|
class CRG(Module):
|
2015-03-18 09:41:43 -04:00
|
|
|
def __init__(self, clk, rst=0):
|
2015-03-13 19:10:08 -04:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
self.clock_domains.cd_por = ClockDomain(reset_less=True)
|
|
|
|
|
|
|
|
if hasattr(clk, "p"):
|
|
|
|
clk_se = Signal()
|
|
|
|
self.specials += DifferentialInput(clk.p, clk.n, clk_se)
|
|
|
|
clk = clk_se
|
|
|
|
|
|
|
|
# Power on Reset (vendor agnostic)
|
|
|
|
rst_n = Signal()
|
2015-03-17 11:22:22 -04:00
|
|
|
self.sync.por += rst_n.eq(1 & ~rst)
|
2015-03-13 19:10:08 -04:00
|
|
|
self.comb += [
|
|
|
|
self.cd_sys.clk.eq(clk),
|
|
|
|
self.cd_por.clk.eq(clk),
|
|
|
|
self.cd_sys.rst.eq(~rst_n)
|
|
|
|
]
|
2015-03-16 17:47:13 -04:00
|
|
|
|
|
|
|
class DDRInput(Special):
|
|
|
|
def __init__(self, i, o1, o2, clk=ClockSignal()):
|
|
|
|
Special.__init__(self)
|
|
|
|
self.i = i
|
|
|
|
self.o1 = o1
|
|
|
|
self.o2 = o2
|
|
|
|
self.clk = clk
|
|
|
|
|
|
|
|
def iter_expressions(self):
|
|
|
|
yield self, "i", SPECIAL_INPUT
|
|
|
|
yield self, "o1", SPECIAL_OUTPUT
|
|
|
|
yield self, "o2", SPECIAL_OUTPUT
|
|
|
|
yield self, "clk", SPECIAL_INPUT
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
raise NotImplementedError("Attempted to use a DDR input, but platform does not support them")
|
|
|
|
|
|
|
|
class DDROutput(Special):
|
|
|
|
def __init__(self, i1, i2, o, clk=ClockSignal()):
|
|
|
|
Special.__init__(self)
|
|
|
|
self.i1 = i1
|
|
|
|
self.i2 = i2
|
|
|
|
self.o = o
|
|
|
|
self.clk = clk
|
|
|
|
|
|
|
|
def iter_expressions(self):
|
|
|
|
yield self, "i1", SPECIAL_INPUT
|
|
|
|
yield self, "i2", SPECIAL_INPUT
|
|
|
|
yield self, "o", SPECIAL_OUTPUT
|
|
|
|
yield self, "clk", SPECIAL_INPUT
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def lower(dr):
|
|
|
|
raise NotImplementedError("Attempted to use a DDR output, but platform does not support them")
|
|
|
|
|