1 """ Pipeline and BufferedHandshake examples
4 from nmutil
.nmoperator
import eq
5 from nmutil
.iocontrol
import (PrevControl
, NextControl
)
6 from nmutil
.singlepipe
import (PrevControl
, NextControl
, ControlBase
,
7 StageCls
, Stage
, StageChain
,
8 BufferedHandshake
, UnbufferedPipeline
)
10 from nmigen
import Signal
, Module
11 from nmigen
.cli
import verilog
, rtlil
14 class ExampleAddStage(StageCls
):
15 """ an example of how to use the buffered pipeline, as a class instance
19 """ returns a tuple of input signals which will be the incoming data
21 return (Signal(16), Signal(16))
24 """ returns an output signal which will happen to contain the sum
30 """ process the input data (sums the values in the tuple) and returns it
35 class ExampleBufPipeAdd(BufferedHandshake
):
36 """ an example of how to use the buffered pipeline, using a class instance
40 addstage
= ExampleAddStage()
41 BufferedHandshake
.__init
__(self
, addstage
)
44 class ExampleStage(Stage
):
45 """ an example of how to use the buffered pipeline, in a static class
50 return Signal(16, name
="example_input_signal")
53 return Signal(16, name
="example_output_signal")
56 """ process the input data and returns it (adds 1)
61 class ExampleStageCls(StageCls
):
62 """ an example of how to use the buffered pipeline, in a static class
67 return Signal(16, name
="example_input_signal")
70 return Signal(16, name
="example_output_signal")
73 """ process the input data and returns it (adds 1)
78 class ExampleBufPipe(BufferedHandshake
):
79 """ an example of how to use the buffered pipeline.
83 BufferedHandshake
.__init
__(self
, ExampleStage
)
86 class ExamplePipeline(UnbufferedPipeline
):
87 """ an example of how to use the unbuffered pipeline.
91 UnbufferedPipeline
.__init
__(self
, ExampleStage
)
94 if __name__
== '__main__':
95 dut
= ExampleBufPipe()
96 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
97 with
open("test_bufpipe.il", "w") as f
:
100 dut
= ExamplePipeline()
101 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
102 with
open("test_combpipe.il", "w") as f
: