From: Luke Kenneth Casson Leighton Date: Thu, 2 Jul 2020 21:30:43 +0000 (+0100) Subject: use Mux in latchregister, try to break "loops" X-Git-Tag: 24jan2021_ls180~46 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0bc469afb6c9a7739de1cb7f2add2881c44bf3ff;p=nmutil.git use Mux in latchregister, try to break "loops" --- diff --git a/src/nmutil/latch.py b/src/nmutil/latch.py index 1c22483..813ad64 100644 --- a/src/nmutil/latch.py +++ b/src/nmutil/latch.py @@ -1,6 +1,6 @@ from nmigen.compat.sim import run_simulation from nmigen.cli import verilog, rtlil -from nmigen import Record, Signal, Module, Const, Elaboratable +from nmigen import Record, Signal, Module, Const, Elaboratable, Mux """ jk latch @@ -21,6 +21,7 @@ always @ (posedge c) endmodule """ + def latchregister(m, incoming, outgoing, settrue, name=None): """latchregister @@ -36,17 +37,17 @@ def latchregister(m, incoming, outgoing, settrue, name=None): reg = Record.like(incoming, name=name) else: reg = Signal.like(incoming, name=name) + m.d.comb += outgoing.eq(Mux(settrue, incoming, reg)) with m.If(settrue): # pass in some kind of expression/condition here m.d.sync += reg.eq(incoming) # latch input into register - m.d.comb += outgoing.eq(incoming) # return input (combinatorial) - with m.Else(): - m.d.comb += outgoing.eq(reg) # return input (combinatorial) + def mkname(prefix, suffix): if suffix is None: return prefix return "%s_%s" % (prefix, suffix) + class SRLatch(Elaboratable): def __init__(self, sync=True, llen=1, name=None): self.sync = sync