From a6acfb9a37e121f5458fd1bf6139f85e7114e503 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 7 Sep 2022 08:58:51 +0200 Subject: [PATCH] stream/Buffer: Integrate PipeValid/PipeReady (both configurable) and add tests. Allow selecting pipelining of valid/data or/and ready and creating a full Skid Buffer (Pipeline of both valid/data and ready). --- litex/soc/interconnect/stream.py | 27 ++++++++++++++++++++++++++- test/test_stream.py | 12 ++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/litex/soc/interconnect/stream.py b/litex/soc/interconnect/stream.py index 1543cdfaa..dde5e23be 100644 --- a/litex/soc/interconnect/stream.py +++ b/litex/soc/interconnect/stream.py @@ -766,7 +766,32 @@ class PipeReady(Module): # Buffer ------------------------------------------------------------------------------------------- -class Buffer(PipeValid): pass # FIXME: Replace Buffer with PipeValid in codebase? +class Buffer(Module): + """Pipe valid/payload and/or ready to cut timing path""" + def __init__(self, layout, pipe_valid=True, pipe_ready=False): + self.sink = sink = Endpoint(layout) + self.source = source = Endpoint(layout) + + # # # + + pipeline = [] + + # Pipe Valid (Optional). + if pipe_valid: + self.submodules.pipe_valid = PipeValid(layout) + pipeline.append(self.pipe_valid) + + # Pipe Ready (Optional). + if pipe_ready: + self.submodules.pipe_ready = PipeReady(layout) + pipeline.append(self.pipe_ready) + + # Buffer Pipeline. + self.submodules.pipeline = Pipeline( + sink, + *pipeline, + source + ) # Cast --------------------------------------------------------------------------------------------- diff --git a/test/test_stream.py b/test/test_stream.py index 7da893850..d2865b7d5 100644 --- a/test/test_stream.py +++ b/test/test_stream.py @@ -50,3 +50,15 @@ class TestStream(unittest.TestCase): def test_pipe_ready(self): dut = PipeReady([("data", 8)]) self.pipe_test(dut) + + def test_buffer_valid(self): + dut = Buffer([("data", 8)], pipe_valid=True, pipe_ready=False) + self.pipe_test(dut) + + def test_buffer_ready(self): + dut = Buffer([("data", 8)], pipe_valid=False, pipe_ready=True) + self.pipe_test(dut) + + def test_buffer_valid_ready(self): + dut = Buffer([("data", 8)], pipe_valid=True, pipe_ready=True) + self.pipe_test(dut)