2019-09-12 07:48:24 -06:00
|
|
|
import warnings
|
|
|
|
|
2019-01-19 19:29:08 -07:00
|
|
|
from ...tools import deprecated
|
2019-09-12 07:48:24 -06:00
|
|
|
from ...lib.cdc import MultiReg as NativeMultiReg
|
2019-01-19 19:29:08 -07:00
|
|
|
from ...hdl.ast import *
|
|
|
|
from ..fhdl.module import CompatModule
|
2019-01-19 20:03:48 -07:00
|
|
|
from ..fhdl.structure import If
|
2018-12-14 08:59:49 -07:00
|
|
|
|
|
|
|
|
2019-01-19 19:29:08 -07:00
|
|
|
__all__ = ["MultiReg", "GrayCounter", "GrayDecoder"]
|
|
|
|
|
|
|
|
|
2019-09-12 07:48:24 -06:00
|
|
|
class MultiReg(NativeMultiReg):
|
|
|
|
def __init__(self, i, o, odomain="sync", n=2, reset=0):
|
|
|
|
if odomain != "sync":
|
|
|
|
warnings.warn("instead of `MultiReg(..., odomain={!r})`, "
|
|
|
|
"use `MultiReg(..., o_domain={!r})`"
|
|
|
|
.format(odomain, odomain),
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
super().__init__(i, o, o_domain=odomain, n=n, reset=reset)
|
2019-09-12 07:54:48 -06:00
|
|
|
self.odomain = odomain
|
2019-09-12 07:48:24 -06:00
|
|
|
|
|
|
|
|
2019-01-19 19:29:08 -07:00
|
|
|
@deprecated("instead of `migen.genlib.cdc.GrayCounter`, use `nmigen.lib.coding.GrayEncoder`")
|
|
|
|
class GrayCounter(CompatModule):
|
|
|
|
def __init__(self, width):
|
|
|
|
self.ce = Signal()
|
|
|
|
self.q = Signal(width)
|
|
|
|
self.q_next = Signal(width)
|
|
|
|
self.q_binary = Signal(width)
|
|
|
|
self.q_next_binary = Signal(width)
|
|
|
|
|
|
|
|
###
|
|
|
|
|
|
|
|
self.comb += [
|
|
|
|
If(self.ce,
|
|
|
|
self.q_next_binary.eq(self.q_binary + 1)
|
|
|
|
).Else(
|
|
|
|
self.q_next_binary.eq(self.q_binary)
|
|
|
|
),
|
|
|
|
self.q_next.eq(self.q_next_binary ^ self.q_next_binary[1:])
|
|
|
|
]
|
|
|
|
self.sync += [
|
|
|
|
self.q_binary.eq(self.q_next_binary),
|
|
|
|
self.q.eq(self.q_next)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@deprecated("instead of `migen.genlib.cdc.GrayDecoder`, use `nmigen.lib.coding.GrayDecoder`")
|
|
|
|
class GrayDecoder(CompatModule):
|
|
|
|
def __init__(self, width):
|
|
|
|
self.i = Signal(width)
|
|
|
|
self.o = Signal(width, reset_less=True)
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
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)
|