X-Git-Url: https://git.libre-soc.org/?p=ieee754fpu.git;a=blobdiff_plain;f=src%2Fnmutil%2Flatch.py;h=41a8df9442920e67336fd9a35604ae64442ec008;hp=dbdb23e55b76e660cec8a2c2b7ec80393147da7f;hb=91c103fd5d1e3cb88d053b093aef61a98d6b4fc1;hpb=ed27bdbe04891087ab837a7f4d124f499685adcf diff --git a/src/nmutil/latch.py b/src/nmutil/latch.py index dbdb23e5..41a8df94 100644 --- a/src/nmutil/latch.py +++ b/src/nmutil/latch.py @@ -4,7 +4,8 @@ from nmigen import Signal, Module, Elaboratable class SRLatch(Elaboratable): - def __init__(self): + def __init__(self, sync=True): + self.sync = sync self.s = Signal(reset_less=True) self.r = Signal(reset_less=True) self.q = Signal(reset_less=True) @@ -14,13 +15,25 @@ class SRLatch(Elaboratable): m = Module() q_int = Signal(reset_less=True) - with m.If(self.s): - m.d.sync += q_int.eq(1) - with m.Elif(self.r): - m.d.sync += q_int.eq(0) - - m.d.comb += self.q.eq(q_int) - m.d.comb += self.qn.eq(~q_int) + if self.sync: + with m.If(self.s): + m.d.sync += q_int.eq(1) + with m.Elif(self.r): + m.d.sync += q_int.eq(0) + m.d.comb += self.q.eq(q_int) + m.d.comb += self.qn.eq(~q_int) + else: + with m.If(self.s): + m.d.sync += q_int.eq(1) + m.d.comb += self.q.eq(1) + m.d.comb += self.qn.eq(0) + with m.Elif(self.r): + m.d.sync += q_int.eq(0) + m.d.comb += self.q.eq(0) + m.d.comb += self.qn.eq(1) + with m.Else(): + m.d.comb += self.q.eq(q_int) + m.d.comb += self.qn.eq(~q_int) return m