From 9caed89157be10585ebe5f7734cb479fbacb4240 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 11 May 2019 05:16:06 +0100 Subject: [PATCH] add helper routine for creating latched registers --- src/nmutil/latch.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 2.30.2