From d6961125bc2c093e3185a994b60777ac5db97242 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Tue, 8 Oct 2019 08:33:43 +0200 Subject: [PATCH] scrambler: rename to scrambling, add Descrambler list features that still needs to be implemented --- .../{test_scrambler.py => test_scrambling.py} | 2 +- usb3_pipe/{scrambler.py => scrambling.py} | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) rename test/{test_scrambler.py => test_scrambling.py} (97%) rename usb3_pipe/{scrambler.py => scrambling.py} (77%) diff --git a/test/test_scrambler.py b/test/test_scrambling.py similarity index 97% rename from test/test_scrambler.py rename to test/test_scrambling.py index 1d526be..2b19128 100644 --- a/test/test_scrambler.py +++ b/test/test_scrambling.py @@ -5,7 +5,7 @@ import unittest from migen import * -from usb3_pipe.scrambler import Scrambler +from usb3_pipe.scrambling import Scrambler scrambler_ref = [ 0x8dbf6dbe, 0xe6a740be, 0xb2e2d32c, 0x2a770207, diff --git a/usb3_pipe/scrambler.py b/usb3_pipe/scrambling.py similarity index 77% rename from usb3_pipe/scrambler.py rename to usb3_pipe/scrambling.py index 71d90d9..904ed8b 100644 --- a/usb3_pipe/scrambler.py +++ b/usb3_pipe/scrambling.py @@ -8,6 +8,14 @@ from migen import * from litex.soc.interconnect import stream +# FIXME: +# - LFSR shall be advanced for each symbol except for SKP. +# - All 8b10b D-cores should be scrambled (except Training Sequence Ordered Sets). +# - K codes shall not be scrambled. +# - Allow enabling/disabling scrambling. + +# Scrambler Unit ----------------------------------------------------------------------------------- + @CEInserter() class ScramblerUnit(Module): def __init__(self): @@ -71,11 +79,31 @@ class ScramblerUnit(Module): ] self.sync += cur.eq(new) +# Scrambler ---------------------------------------------------------------------------------------- + @ResetInserter() class Scrambler(Module): def __init__(self): - self.sink = sink = stream.Endpoint([("data", 32)]) - self.source = source = stream.Endpoint([("data", 32)]) + self.sink = sink = stream.Endpoint([("data", 32), ("ctrl", 4)]) + self.source = source = stream.Endpoint([("data", 32), ("ctrl", 4)]) + + # # # + + scrambler = ScramblerUnit() + self.submodules += scrambler + self.comb += [ + scrambler.ce.eq(sink.valid & sink.ready), + sink.connect(source), + source.data.eq(sink.data ^ scrambler.value) + ] + +# Descrambler -------------------------------------------------------------------------------------- + +@ResetInserter() +class Descrambler(Module): + def __init__(self): + self.sink = sink = stream.Endpoint([("data", 32), ("ctrl", 4)]) + self.source = source = stream.Endpoint([("data", 32), ("ctrl", 4)]) # # #