litex/milkymist/m1crg/__init__.py

48 lines
944 B
Python
Raw Normal View History

2012-02-16 12:02:37 -05:00
from fractions import Fraction
from migen.fhdl.structure import *
class M1CRG:
def __init__(self, infreq, outfreq1x):
self.clkin = Signal()
self.trigger_reset = Signal()
generated = []
for name in [
"sys_clk",
"sys_rst",
"ac97_rst_n",
"videoin_rst_n",
"flash_rst_n",
2012-02-20 17:55:20 -05:00
"clk2x_270",
2012-02-19 12:43:42 -05:00
"clk4x_wr",
"clk4x_wr_strb",
"clk4x_rd",
2012-05-19 18:30:03 -04:00
"clk4x_rd_strb",
2012-06-17 07:41:26 -04:00
"phy_clk",
"vga_clk",
"vga_clk_pad"
]:
2012-02-16 12:02:37 -05:00
s = Signal(name=name)
setattr(self, name, s)
generated.append((name, s))
ratio = Fraction(outfreq1x)/Fraction(infreq)
in_period = float(Fraction(1000000000)/Fraction(infreq))
self._inst = Instance("m1crg",
generated,
[
("clkin", self.clkin),
("trigger_reset", self.trigger_reset)
2012-02-19 12:43:42 -05:00
],
parameters=[
2012-02-16 12:02:37 -05:00
("in_period", in_period),
("f_mult", ratio.numerator),
("f_div", ratio.denominator)
]
)
def get_fragment(self):
return Fragment(instances=[self._inst])