1 """ Pipeline and BufferedPipeline examples
4 from singlepipe
import (PrevControl
, NextControl
, ControlBase
,
5 StageCls
, Stage
, StageChain
,
6 BufferedPipeline
, UnbufferedPipeline
, eq
)
8 from nmigen
import Signal
, Cat
, Const
, Mux
, Module
9 from nmigen
.cli
import verilog
, rtlil
10 from nmigen
.hdl
.rec
import Record
, Layout
12 from abc
import ABCMeta
, abstractmethod
13 from collections
.abc
import Sequence
16 class ExampleAddStage(StageCls
):
17 """ an example of how to use the buffered pipeline, as a class instance
21 """ returns a tuple of input signals which will be the incoming data
23 return (Signal(16), Signal(16))
26 """ returns an output signal which will happen to contain the sum
32 """ process the input data (sums the values in the tuple) and returns it
37 class ExampleBufPipeAdd(BufferedPipeline
):
38 """ an example of how to use the buffered pipeline, using a class instance
42 addstage
= ExampleAddStage()
43 BufferedPipeline
.__init
__(self
, addstage
)
46 class ExampleStage(Stage
):
47 """ an example of how to use the buffered pipeline, in a static class
52 return Signal(16, name
="example_input_signal")
55 return Signal(16, name
="example_output_signal")
58 """ process the input data and returns it (adds 1)
63 class ExampleStageCls(StageCls
):
64 """ an example of how to use the buffered pipeline, in a static class
69 return Signal(16, name
="example_input_signal")
72 return Signal(16, name
="example_output_signal")
75 """ process the input data and returns it (adds 1)
80 class ExampleBufPipe(BufferedPipeline
):
81 """ an example of how to use the buffered pipeline.
85 BufferedPipeline
.__init
__(self
, ExampleStage
)
88 class ExamplePipeline(UnbufferedPipeline
):
89 """ an example of how to use the unbuffered pipeline.
93 UnbufferedPipeline
.__init
__(self
, ExampleStage
)
96 if __name__
== '__main__':
97 dut
= ExampleBufPipe()
98 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
99 with
open("test_bufpipe.il", "w") as f
:
102 dut
= ExamplePipeline()
103 vl
= rtlil
.convert(dut
, ports
=dut
.ports())
104 with
open("test_combpipe.il", "w") as f
: