From: Florent Kermarrec Date: Thu, 12 Jan 2017 03:15:33 +0000 (+0100) Subject: gen/genlib/cdc: add GrayDecoder from misoc X-Git-Tag: 24jan2021_ls180~1914 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f0202db90f3cf66f2c9c7934fd27083916a41bc7;p=litex.git gen/genlib/cdc: add GrayDecoder from misoc --- diff --git a/litex/gen/genlib/cdc.py b/litex/gen/genlib/cdc.py index 7f72b471..6bac9e00 100644 --- a/litex/gen/genlib/cdc.py +++ b/litex/gen/genlib/cdc.py @@ -142,6 +142,20 @@ class GrayCounter(Module): ] +class GrayDecoder(Module): + def __init__(self, width): + self.i = Signal(width) + self.o = Signal(width) + + # # # + + o_comb = Signal(width) + self.comb += o_comb[-1].eq(self.i[-1]) + for i in reversed(range(width-1)): + self.comb += o_comb[i].eq(o_comb[i+1] ^ self.i[i]) + self.sync += self.o.eq(o_comb) + + class ElasticBuffer(Module): def __init__(self, width, depth, idomain, odomain): self.din = Signal(width)