+class ExampleAddStage:
+ """ an example of how to use the buffered pipeline, as a class instance
+ """
+
+ def ispec(self):
+ """ returns a tuple of input signals which will be the incoming data
+ """
+ return (Signal(16), Signal(16))
+
+ def ospec(self):
+ """ returns an output signal which will happen to contain the sum
+ of the two inputs
+ """
+ return Signal(16)
+
+ def process(self, i):
+ """ process the input data (sums the values in the tuple) and returns it
+ """
+ return i[0] + i[1]
+
+
+class ExampleBufPipeAdd(BufferedPipeline):
+ """ an example of how to use the buffered pipeline, using a class instance
+ """
+
+ def __init__(self):
+ addstage = ExampleAddStage()
+ BufferedPipeline.__init__(self, addstage)
+
+
+class ExampleStage:
+ """ an example of how to use the buffered pipeline, in a static class
+ fashion
+ """
+
+ def ispec():
+ return Signal(16)
+
+ def ospec():
+ return Signal(16)
+
+ def process(i):
+ """ process the input data and returns it (adds 1)
+ """
+ return i + 1
+
+
+class ExampleBufPipe(BufferedPipeline):
+ """ an example of how to use the buffered pipeline.
+ """
+
+ def __init__(self):
+ BufferedPipeline.__init__(self, ExampleStage)
+
+
+class CombPipe:
+ """A simple pipeline stage containing combinational logic that can execute
+ completely in one clock cycle.
+
+ Parameters:
+ -----------
+ input_shape : int or tuple or None
+ the shape of ``input.data`` and ``comb_input``
+ output_shape : int or tuple or None
+ the shape of ``output.data`` and ``comb_output``
+ name : str
+ the name
+
+ Attributes:
+ -----------
+ input : StageInput
+ The pipeline input
+ output : StageOutput
+ The pipeline output
+ comb_input : Signal, input_shape
+ The input to the combinatorial logic
+ comb_output: Signal, output_shape
+ The output of the combinatorial logic
+ """
+
+ def __init__(self, stage):
+ self.stage = stage
+ self._data_valid = Signal()
+ # set up input and output IO ACK (prev/next ready/valid)
+ self.i = IOAckIn()
+ self.o = IOAckOut()
+
+ # set up the input and output data
+ self.i.data = stage.ispec() # input type
+ self.r_data = stage.ispec() # input type
+ self.o_comb = stage.ospec() # output data
+ self.o.data = stage.ospec() # output type
+ self.o.data.name = "outdata"
+
+ def elaborate(self, platform):
+ m = Module()
+ m.d.comb += eq(self.o_comb, self.stage.process(self.r_data))
+ m.d.comb += self.o.n_valid.eq(self._data_valid)
+ m.d.comb += self.o.p_ready.eq(~self._data_valid | self.i.n_ready)
+ m.d.sync += self._data_valid.eq(self.i.p_valid | \
+ (~self.i.n_ready & self._data_valid))
+ with m.If(self.i.p_valid & self.o.p_ready):
+ m.d.sync += eq(self.r_data, self.i.data)
+ m.d.comb += eq(self.o.data, self.o_comb)
+ return m
+
+ def ports(self):
+ return [self.i.data, self.o.data]
+
+
+class ExampleCombPipe(CombPipe):
+ """ an example of how to use the combinatorial pipeline.
+ """
+
+ def __init__(self):
+ CombPipe.__init__(self, ExampleStage)
+
+