serwb/scrambler: dynamic enable/disable

This commit is contained in:
Florent Kermarrec 2018-04-17 19:20:06 +02:00
parent 816a6f2ec7
commit ebfac36223
1 changed files with 62 additions and 60 deletions

View File

@ -31,20 +31,27 @@ class _Scrambler(Module):
class Scrambler(Module):
def __init__(self, sync_interval=1024, enable=True):
def __init__(self, sync_interval=1024):
self.enable = Signal()
self.sink = sink = stream.Endpoint([("data", 32)])
self.source = source = stream.Endpoint([("d", 32), ("k", 4)])
# # #
if enable:
# scrambler
self.submodules.scrambler = scrambler = _Scrambler(32)
# insert K.29.7 as sync character
# every sync_interval cycles
count = Signal(max=sync_interval)
self.submodules.fsm = fsm = FSM(reset_state="SYNC")
self.submodules.fsm = fsm = ResetInserter()(FSM(reset_state="DISABLE"))
self.comb += fsm.reset.eq(~self.enable)
fsm.act("DISABLE",
sink.connect(source, omit={"data"}),
source.k.eq(0b0000),
source.d.eq(sink.data),
NextState("SYNC")
)
fsm.act("SYNC",
scrambler.reset.eq(1),
source.stb.eq(1),
@ -68,29 +75,29 @@ class Scrambler(Module):
)
)
)
else:
self.comb += [
sink.connect(source, omit={"data"}),
source.k.eq(0b0000),
source.d.eq(sink.data)
]
class Descrambler(Module):
def __init__(self, enable=True):
def __init__(self):
self.enable = Signal()
self.sink = sink = stream.Endpoint([("d", 32), ("k", 4)])
self.source = source = stream.Endpoint([("data", 32)])
# # #
if enable:
# descrambler
self.submodules.descrambler = descrambler = _Scrambler(32)
self.comb += descrambler.i.eq(sink.d)
# detect K29.7 and synchronize descrambler
self.comb += [
descrambler.reset.eq(0),
self.submodules.fsm = fsm = ResetInserter()(FSM(reset_state="DISABLE"))
self.comb += fsm.reset.eq(~self.enable)
fsm.act("DISABLE",
sink.connect(source, omit={"d", "k"}),
source.data.eq(sink.d),
NextState("SYNC_DATA")
)
fsm.act("SYNC_DATA",
If((sink.k[0] == 1) &
(sink.d[:8] == K(29,7)),
sink.ack.eq(1),
@ -103,9 +110,4 @@ class Descrambler(Module):
descrambler.ce.eq(1)
)
)
]
else:
self.comb += [
sink.connect(source, omit={"d", "k"}),
source.data.eq(sink.d)
]
)