mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
verilog: user-definable reset and clock
This commit is contained in:
parent
c7b9dfc203
commit
ee6ca729a2
1 changed files with 20 additions and 14 deletions
|
@ -117,11 +117,15 @@ def _printinstances(ns, i, clk, rst):
|
||||||
r += ");\n\n"
|
r += ");\n\n"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def Convert(f, ios=set(), name="top", clkname="sys_clk", rstname="sys_rst", ns=None):
|
def Convert(f, ios=set(), name="top", clk_signal=None, rst_signal=None, ns=None):
|
||||||
if ns is None: ns = Namespace()
|
if clk_signal is None:
|
||||||
|
clk_signal = Signal(name="sys_clk")
|
||||||
clks = Signal(name=clkname)
|
ios.add(clk_signal)
|
||||||
rsts = Signal(name=rstname)
|
if rst_signal is None:
|
||||||
|
rst_signal = Signal(name="sys_rst")
|
||||||
|
ios.add(rst_signal)
|
||||||
|
if ns is None:
|
||||||
|
ns = Namespace()
|
||||||
|
|
||||||
ios |= f.pads
|
ios |= f.pads
|
||||||
|
|
||||||
|
@ -131,15 +135,17 @@ def Convert(f, ios=set(), name="top", clkname="sys_clk", rstname="sys_rst", ns=N
|
||||||
|
|
||||||
r = "/* Machine-generated using Migen */\n"
|
r = "/* Machine-generated using Migen */\n"
|
||||||
r += "module " + name + "(\n"
|
r += "module " + name + "(\n"
|
||||||
r += "\tinput " + ns.get_name(clks) + ",\n"
|
firstp = True
|
||||||
r += "\tinput " + ns.get_name(rsts)
|
|
||||||
for sig in ios:
|
for sig in ios:
|
||||||
|
if not firstp:
|
||||||
|
r += ",\n"
|
||||||
|
firstp = False
|
||||||
if sig in targets:
|
if sig in targets:
|
||||||
r += ",\n\toutput reg " + _printsig(ns, sig)
|
r += "\toutput reg " + _printsig(ns, sig)
|
||||||
elif sig in instouts:
|
elif sig in instouts:
|
||||||
r += ",\n\toutput " + _printsig(ns, sig)
|
r += "\toutput " + _printsig(ns, sig)
|
||||||
else:
|
else:
|
||||||
r += ",\n\tinput " + _printsig(ns, sig)
|
r += "\tinput " + _printsig(ns, sig)
|
||||||
r += "\n);\n\n"
|
r += "\n);\n\n"
|
||||||
for sig in sigs - ios:
|
for sig in sigs - ios:
|
||||||
if sig in instouts:
|
if sig in instouts:
|
||||||
|
@ -153,10 +159,10 @@ def Convert(f, ios=set(), name="top", clkname="sys_clk", rstname="sys_rst", ns=N
|
||||||
r += _printnode(ns, 1, f.comb)
|
r += _printnode(ns, 1, f.comb)
|
||||||
r += "end\n\n"
|
r += "end\n\n"
|
||||||
if f.sync.l:
|
if f.sync.l:
|
||||||
r += "always @(posedge " + ns.get_name(clks) + ") begin\n"
|
r += "always @(posedge " + ns.get_name(clk_signal) + ") begin\n"
|
||||||
r += _printnode(ns, 1, insert_reset(rsts, f.sync))
|
r += _printnode(ns, 1, insert_reset(rst_signal, f.sync))
|
||||||
r += "end\n\n"
|
r += "end\n\n"
|
||||||
r += _printinstances(ns, f.instances, clks, rsts)
|
r += _printinstances(ns, f.instances, clk_signal, rst_signal)
|
||||||
|
|
||||||
r += "endmodule\n"
|
r += "endmodule\n"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue