diff --git a/transactron/lib/fifo.py b/transactron/lib/fifo.py index 92ac0f7..24cacfa 100644 --- a/transactron/lib/fifo.py +++ b/transactron/lib/fifo.py @@ -13,6 +13,9 @@ class BasicFifo(Elaboratable): read: Method Reads from the FIFO. Accepts an empty argument, returns a structure. Ready only if the FIFO is not empty. + peek: Method + Returns the element at the front (but not delete). Ready only if the FIFO + is not empty. The method is nonexclusive. write: Method Writes to the FIFO. Accepts a structure, returns empty result. Ready only if the FIFO is not full. @@ -40,6 +43,7 @@ def __init__(self, layout: MethodLayout, depth: int, *, src_loc: int | SrcLoc = src_loc = get_src_loc(src_loc) self.read = Method(o=self.layout, src_loc=src_loc) + self.peek = Method(o=self.layout, nonexclusive=True, src_loc=src_loc) self.write = Method(i=self.layout, src_loc=src_loc) self.clear = Method(src_loc=src_loc) self.head = Signal(from_method_layout(layout)) @@ -93,6 +97,10 @@ def _() -> ValueLike: m.d.sync += self.read_idx.eq(next_read_idx) return self.head + @def_method(m, self.peek, self.read_ready) + def _() -> ValueLike: + return self.head + @def_method(m, self.clear) def _() -> None: m.d.sync += self.read_idx.eq(0) diff --git a/transactron/lib/reqres.py b/transactron/lib/reqres.py index f9aeb6e..a3f6e29 100644 --- a/transactron/lib/reqres.py +++ b/transactron/lib/reqres.py @@ -1,7 +1,7 @@ from amaranth import * from ..core import * from ..utils import SrcLoc, get_src_loc, MethodLayout -from .connectors import Forwarder, FIFO +from .connectors import Forwarder from transactron.lib import BasicFifo from amaranth.utils import * @@ -39,6 +39,8 @@ class ArgumentsToResultsZipper(Elaboratable): Attributes ---------- + peek_arg: Method + A nonexclusive method to read (but not delete) the head of the arg queue. write_args: Method Method to write arguments with `args_layout` format to 2-FIFO. write_results: Method @@ -65,6 +67,7 @@ def __init__(self, args_layout: MethodLayout, results_layout: MethodLayout, src_ self.args_layout = args_layout self.output_layout = [("args", self.args_layout), ("results", results_layout)] + self.peek_arg = Method(o=self.args_layout, nonexclusive=True, src_loc=self.src_loc) self.write_args = Method(i=self.args_layout, src_loc=self.src_loc) self.write_results = Method(i=self.results_layout, src_loc=self.src_loc) self.read = Method(o=self.output_layout, src_loc=self.src_loc) @@ -72,7 +75,7 @@ def __init__(self, args_layout: MethodLayout, results_layout: MethodLayout, src_ def elaborate(self, platform): m = TModule() - fifo = FIFO(self.args_layout, depth=2, src_loc=self.src_loc) + fifo = BasicFifo(self.args_layout, depth=2, src_loc=self.src_loc) forwarder = Forwarder(self.results_layout, src_loc=self.src_loc) m.submodules.fifo = fifo @@ -92,6 +95,8 @@ def _(): results = forwarder.read(m) return {"args": args, "results": results} + self.peek_arg.proxy(m, fifo.peek) + return m