1 """ Pipeline and BufferedHandshake examples
4 from nmoperator
import eq
5 from singlepipe
import (PrevControl
, NextControl
, ControlBase
,
6 StageCls
, Stage
, StageChain
,
7 BufferedHandshake
, UnbufferedPipeline
)
9 from nmigen
import Signal
, Module
10 from nmigen
.cli
import verilog
, rtlil
13 class ExampleAddStage(StageCls
):
14 """ an example of how to use the buffered pipeline, as a class instance
18 """ returns a tuple of input signals which will be the incoming data
20 return (Signal(16), Signal(16))
23 """ returns an output signal which will happen to contain the sum
29 """ process the input data (sums the values in the tuple) and returns it
34 class ExampleBufPipeAdd(BufferedHandshake
):
35 """ an example of how to use the buffered pipeline, using a class instance
39 addstage
= ExampleAddStage()
40 BufferedHandshake
.__init
__(self
, addstage
)
43 class ExampleStage(Stage
):
44 """ an example of how to use the buffered pipeline, in a static class
49 return Signal(16, name
="example_input_signal")
52 return Signal(16, name
="example_output_signal")
55 """ process the input data and returns it (adds 1)
60 class ExampleStageCls(StageCls
):
61 """ an example of how to use the buffered pipeline, in a static class
66 return Signal(16, name
="example_input_signal")
69 return Signal(16, name
="example_output_signal")
72 """ process the input data and returns it (adds 1)
77 class ExampleBufPipe(BufferedHandshake
):
78 """ an example of how to use the buffered pipeline.
82 BufferedHandshake
.__init
__(self
, ExampleStage
)
85 class ExamplePipeline(UnbufferedPipeline
):
86 """ an example of how to use the unbuffered pipeline.
90 UnbufferedPipeline
.__init
__(self
, ExampleStage
)
93 if __name__
== '__main__':
94 dut
= ExampleBufPipe()
95 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
96 with
open("test_bufpipe.il", "w") as f
:
99 dut
= ExamplePipeline()
100 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
101 with
open("test_combpipe.il", "w") as f
: