2012-02-16 12:02:37 -05:00
|
|
|
from fractions import Fraction
|
|
|
|
|
|
|
|
from migen.fhdl.structure import *
|
2013-02-24 07:07:25 -05:00
|
|
|
from migen.fhdl.specials import Instance
|
2013-03-10 14:32:38 -04:00
|
|
|
from migen.fhdl.module import Module
|
2012-02-16 12:02:37 -05:00
|
|
|
|
2013-03-15 14:17:05 -04:00
|
|
|
class M1CRG(Module):
|
2012-02-16 12:02:37 -05:00
|
|
|
def __init__(self, infreq, outfreq1x):
|
2013-02-11 12:23:06 -05:00
|
|
|
self.clk50_pad = Signal()
|
2012-02-16 12:02:37 -05:00
|
|
|
self.trigger_reset = Signal()
|
|
|
|
|
2013-02-11 12:23:06 -05:00
|
|
|
self.eth_rx_clk_pad = Signal()
|
|
|
|
self.eth_tx_clk_pad = Signal()
|
|
|
|
|
2013-03-15 14:17:05 -04:00
|
|
|
self.clock_domains.cd_sys = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys2x_270 = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys4x_wr = ClockDomain()
|
|
|
|
self.clock_domains.cd_sys4x_rd = ClockDomain()
|
|
|
|
self.clock_domains.cd_eth_rx = ClockDomain()
|
|
|
|
self.clock_domains.cd_eth_tx = ClockDomain()
|
|
|
|
self.clock_domains.cd_vga = ClockDomain()
|
2012-09-10 17:47:06 -04:00
|
|
|
|
|
|
|
ratio = Fraction(outfreq1x)/Fraction(infreq)
|
|
|
|
in_period = float(Fraction(1000000000)/Fraction(infreq))
|
|
|
|
|
|
|
|
inst_items = [
|
|
|
|
Instance.Parameter("in_period", in_period),
|
|
|
|
Instance.Parameter("f_mult", ratio.numerator),
|
|
|
|
Instance.Parameter("f_div", ratio.denominator),
|
2013-02-11 12:23:06 -05:00
|
|
|
Instance.Input("clk50_pad", self.clk50_pad),
|
2012-09-10 17:47:06 -04:00
|
|
|
Instance.Input("trigger_reset", self.trigger_reset),
|
|
|
|
|
2013-02-11 12:23:06 -05:00
|
|
|
Instance.Input("eth_rx_clk_pad", self.eth_rx_clk_pad),
|
|
|
|
Instance.Input("eth_tx_clk_pad", self.eth_tx_clk_pad),
|
|
|
|
|
2012-09-10 17:47:06 -04:00
|
|
|
Instance.Output("sys_clk", self.cd_sys.clk),
|
2012-09-10 18:21:07 -04:00
|
|
|
Instance.Output("sys_rst", self.cd_sys.rst),
|
|
|
|
Instance.Output("clk2x_270", self.cd_sys2x_270.clk),
|
|
|
|
Instance.Output("clk4x_wr", self.cd_sys4x_wr.clk),
|
|
|
|
Instance.Output("clk4x_rd", self.cd_sys4x_rd.clk),
|
2013-02-11 12:23:06 -05:00
|
|
|
Instance.Output("eth_rx_clk", self.cd_eth_rx.clk),
|
|
|
|
Instance.Output("eth_tx_clk", self.cd_eth_tx.clk),
|
2012-09-10 18:21:07 -04:00
|
|
|
Instance.Output("vga_clk", self.cd_vga.clk)
|
2012-09-10 17:47:06 -04:00
|
|
|
]
|
|
|
|
|
2012-02-16 12:02:37 -05:00
|
|
|
for name in [
|
2013-02-11 12:23:06 -05:00
|
|
|
"norflash_rst_n",
|
2012-02-19 12:43:42 -05:00
|
|
|
"clk4x_wr_strb",
|
2012-05-19 18:30:03 -04:00
|
|
|
"clk4x_rd_strb",
|
2013-02-11 12:23:06 -05:00
|
|
|
"ddr_clk_pad_p",
|
|
|
|
"ddr_clk_pad_n",
|
|
|
|
"eth_phy_clk_pad",
|
2012-06-17 07:41:26 -04:00
|
|
|
"vga_clk_pad"
|
2012-02-17 05:04:44 -05:00
|
|
|
]:
|
2012-02-16 12:02:37 -05:00
|
|
|
s = Signal(name=name)
|
|
|
|
setattr(self, name, s)
|
2012-09-10 17:47:06 -04:00
|
|
|
inst_items.append(Instance.Output(name, s))
|
2012-02-16 12:02:37 -05:00
|
|
|
|
2013-03-10 14:32:38 -04:00
|
|
|
self.specials += Instance("m1crg", *inst_items)
|