From: Luke Kenneth Casson Leighton Date: Sat, 11 May 2019 04:16:06 +0000 (+0100) Subject: add helper routine for creating latched registers X-Git-Tag: ls180-24jan2020~1001 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9caed89157be10585ebe5f7734cb479fbacb4240;p=ieee754fpu.git add helper routine for creating latched registers --- diff --git a/src/nmutil/latch.py b/src/nmutil/latch.py index d845a954..6cf5ab7e 100644 --- a/src/nmutil/latch.py +++ b/src/nmutil/latch.py @@ -21,6 +21,15 @@ always @ (posedge c) endmodule """ +def latchregister(m, incoming, outgoing, settrue): + reg = Signal.like(incoming) # make register same as input. reset is OK. + with m.If(settrue): + 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) + + class SRLatch(Elaboratable): def __init__(self, sync=True): self.sync = sync