serwb/scrambler: add flow control

This commit is contained in:
Florent Kermarrec 2018-04-07 14:51:17 +02:00
parent 2f8bd022f7
commit 9d0e8c27ff
1 changed files with 30 additions and 18 deletions

View File

@ -11,6 +11,7 @@ def K(x, y):
@ResetInserter() @ResetInserter()
@CEInserter()
class _Scrambler(Module): class _Scrambler(Module):
def __init__(self, n_io, n_state=23, taps=[17, 22]): def __init__(self, n_io, n_state=23, taps=[17, 22]):
self.i = Signal(n_io) self.i = Signal(n_io)
@ -38,26 +39,35 @@ class Scrambler(Module):
if enable: if enable:
# scrambler # scrambler
scrambler = _Scrambler(32) self.submodules.scrambler = scrambler = _Scrambler(32)
self.submodules += scrambler
self.comb += scrambler.i.eq(sink.data)
# insert K.29.7 as sync character # insert K.29.7 as sync character
# every sync_interval cycles # every sync_interval cycles
count = Signal(max=sync_interval) count = Signal(max=sync_interval)
self.sync += count.eq(count + 1) self.submodules.fsm = fsm = FSM(reset_state="SYNC")
self.comb += [ fsm.act("SYNC",
If(count == 0, scrambler.reset.eq(1),
scrambler.reset.eq(1), source.stb.eq(1),
source.stb.eq(1), source.k[0].eq(1),
source.k[0].eq(1), source.d[:8].eq(K(29, 7)),
source.d[:8].eq(K(29, 7)) NextValue(count, 0),
).Else( If(source.ack,
sink.ack.eq(source.ack), NextState("DATA")
source.stb.eq(sink.stb),
source.d.eq(scrambler.o)
) )
] )
fsm.act("DATA",
scrambler.i.eq(sink.data),
sink.ack.eq(source.ack),
source.stb.eq(1),
source.d.eq(scrambler.o),
If(source.stb & source.ack,
scrambler.ce.eq(1),
NextValue(count, count + 1),
If(count == (sync_interval - 1),
NextState("SYNC")
)
)
)
else: else:
self.comb += [ self.comb += [
sink.connect(source, omit={"data"}), sink.connect(source, omit={"data"}),
@ -75,8 +85,7 @@ class Descrambler(Module):
if enable: if enable:
# descrambler # descrambler
descrambler = _Scrambler(32) self.submodules.descrambler = descrambler = _Scrambler(32)
self.submodules += descrambler
self.comb += descrambler.i.eq(sink.d) self.comb += descrambler.i.eq(sink.d)
# detect K29.7 and synchronize descrambler # detect K29.7 and synchronize descrambler
@ -89,7 +98,10 @@ class Descrambler(Module):
).Else( ).Else(
sink.ack.eq(source.ack), sink.ack.eq(source.ack),
source.stb.eq(sink.stb), source.stb.eq(sink.stb),
source.data.eq(descrambler.o) source.data.eq(descrambler.o),
If(source.stb & source.ack,
descrambler.ce.eq(1)
)
) )
] ]
else: else: