2013-05-22 11:10:13 -04:00
|
|
|
from migen.fhdl.std import *
|
2013-03-17 09:43:10 -04:00
|
|
|
from migen.genlib.cdc import MultiReg
|
|
|
|
from migen.bank.description import *
|
|
|
|
|
2013-03-30 12:28:15 -04:00
|
|
|
class Clocking(Module, AutoCSR):
|
2013-03-26 12:57:17 -04:00
|
|
|
def __init__(self, pads):
|
2013-03-30 12:28:15 -04:00
|
|
|
self._r_pll_reset = CSRStorage()
|
|
|
|
self._r_locked = CSRStatus()
|
2013-03-17 09:43:10 -04:00
|
|
|
|
|
|
|
self.locked = Signal()
|
|
|
|
self.serdesstrobe = Signal()
|
2013-03-17 10:41:50 -04:00
|
|
|
self.clock_domains._cd_pix = ClockDomain()
|
|
|
|
self.clock_domains._cd_pix5x = ClockDomain()
|
2013-04-25 14:19:49 -04:00
|
|
|
self.clock_domains._cd_pix10x = ClockDomain(reset_less=True)
|
|
|
|
self.clock_domains._cd_pix20x = ClockDomain(reset_less=True)
|
2013-03-17 09:43:10 -04:00
|
|
|
|
|
|
|
###
|
|
|
|
|
|
|
|
clkfbout = Signal()
|
|
|
|
pll_locked = Signal()
|
|
|
|
pll_clk0 = Signal()
|
|
|
|
pll_clk1 = Signal()
|
|
|
|
pll_clk2 = Signal()
|
2013-03-20 19:46:29 -04:00
|
|
|
pll_clk3 = Signal()
|
2013-03-17 09:43:10 -04:00
|
|
|
self.specials += Instance("PLL_BASE",
|
2013-03-20 19:46:29 -04:00
|
|
|
Instance.Parameter("CLKIN_PERIOD", 26.7),
|
2013-03-17 09:43:10 -04:00
|
|
|
Instance.Parameter("CLKFBOUT_MULT", 20),
|
2013-03-17 10:41:50 -04:00
|
|
|
Instance.Parameter("CLKOUT0_DIVIDE", 1), # pix20x
|
2013-03-17 09:43:10 -04:00
|
|
|
Instance.Parameter("CLKOUT1_DIVIDE", 4), # pix5x
|
2013-03-17 10:41:50 -04:00
|
|
|
Instance.Parameter("CLKOUT2_DIVIDE", 20), # pix
|
2013-03-20 19:46:29 -04:00
|
|
|
Instance.Parameter("CLKOUT3_DIVIDE", 2), # pix10x
|
2013-03-17 09:43:10 -04:00
|
|
|
Instance.Parameter("COMPENSATION", "INTERNAL"),
|
|
|
|
|
|
|
|
Instance.Output("CLKFBOUT", clkfbout),
|
2013-03-20 19:46:29 -04:00
|
|
|
# WARNING: Do not touch the order of those clocks, or PAR fails.
|
2013-03-17 09:43:10 -04:00
|
|
|
Instance.Output("CLKOUT0", pll_clk0),
|
|
|
|
Instance.Output("CLKOUT1", pll_clk1),
|
|
|
|
Instance.Output("CLKOUT2", pll_clk2),
|
2013-03-20 19:46:29 -04:00
|
|
|
Instance.Output("CLKOUT3", pll_clk3),
|
2013-03-17 09:43:10 -04:00
|
|
|
Instance.Output("LOCKED", pll_locked),
|
|
|
|
Instance.Input("CLKFBIN", clkfbout),
|
2013-05-30 15:38:45 -04:00
|
|
|
Instance.Input("CLKIN", pads.clk),
|
|
|
|
Instance.Input("RST", self._r_pll_reset.storage)
|
2013-03-17 09:43:10 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
locked_async = Signal()
|
|
|
|
self.specials += Instance("BUFPLL",
|
|
|
|
Instance.Parameter("DIVIDE", 4),
|
2013-03-17 10:41:50 -04:00
|
|
|
Instance.Input("PLLIN", pll_clk0),
|
2013-03-18 14:03:17 -04:00
|
|
|
Instance.Input("GCLK", ClockSignal("pix5x")),
|
2013-03-17 09:43:10 -04:00
|
|
|
Instance.Input("LOCKED", pll_locked),
|
|
|
|
Instance.Output("IOCLK", self._cd_pix20x.clk),
|
|
|
|
Instance.Output("LOCK", locked_async),
|
|
|
|
Instance.Output("SERDESSTROBE", self.serdesstrobe)
|
|
|
|
)
|
2013-03-17 10:41:50 -04:00
|
|
|
self.specials += Instance("BUFG",
|
|
|
|
Instance.Input("I", pll_clk1), Instance.Output("O", self._cd_pix5x.clk))
|
|
|
|
self.specials += Instance("BUFG",
|
|
|
|
Instance.Input("I", pll_clk2), Instance.Output("O", self._cd_pix.clk))
|
2013-03-20 19:46:29 -04:00
|
|
|
self.specials += Instance("BUFG",
|
|
|
|
Instance.Input("I", pll_clk3), Instance.Output("O", self._cd_pix10x.clk))
|
2013-03-18 14:03:17 -04:00
|
|
|
self.specials += MultiReg(locked_async, self.locked, "sys")
|
2013-03-30 12:28:15 -04:00
|
|
|
self.comb += self._r_locked.status.eq(self.locked)
|
2013-03-18 15:31:59 -04:00
|
|
|
|
2013-03-21 14:02:04 -04:00
|
|
|
# sychronize pix+pix5x reset
|
|
|
|
pix_rst_n = 1
|
|
|
|
for i in range(2):
|
|
|
|
new_pix_rst_n = Signal()
|
2013-03-18 15:31:59 -04:00
|
|
|
self.specials += Instance("FDCE",
|
2013-03-21 14:02:04 -04:00
|
|
|
Instance.Input("D", pix_rst_n),
|
2013-03-18 15:31:59 -04:00
|
|
|
Instance.Input("CE", 1),
|
2013-03-21 14:02:04 -04:00
|
|
|
Instance.Input("C", ClockSignal("pix")),
|
2013-03-18 15:31:59 -04:00
|
|
|
Instance.Input("CLR", ~locked_async),
|
2013-03-21 14:02:04 -04:00
|
|
|
Instance.Output("Q", new_pix_rst_n)
|
2013-03-18 15:31:59 -04:00
|
|
|
)
|
2013-03-21 14:02:04 -04:00
|
|
|
pix_rst_n = new_pix_rst_n
|
|
|
|
self.comb += self._cd_pix.rst.eq(~pix_rst_n)
|
|
|
|
self.comb += self._cd_pix5x.rst.eq(~pix_rst_n)
|