class PrevControl:
+ """ contains signals that come *from* the previous stage (both in and out)
+ * i_valid: input from previous stage indicating incoming data is valid
+ * o_ready: output to next stage indicating readiness to accept data
+ * i_data : an input - added by the user of this class
+ """
def __init__(self):
self.i_valid = Signal(name="p_i_valid") # >>in
self.o_ready = Signal(name="p_o_ready") # <<out
+ def connect_in(self, prev):
+ """ helper function to connect stage to an input source. do not
+ use to connect stage-to-stage!
+ """
+ return [self.i_valid.eq(prev.i_valid),
+ prev.o_ready.eq(self.o_ready),
+ eq(self.data, prev.data),
+ ]
+
class NextControl:
-
+ """ contains the signals that go *to* the next stage (both in and out)
+ * o_valid: output indicating to next stage that data is valid
+ * i_ready: input from next stage indicating that it can accept data
+ * o_data : an output - added by the user of this class
+ """
def __init__(self):
self.o_valid = Signal(name="n_o_valid") # out>>
self.i_ready = Signal(name="n_i_ready") # <<in
+ def connect_to_next(self, nxt):
+ """ helper function to connect to the next stage data/valid/ready.
+ data/valid is passed *TO* nxt, and ready comes *IN* from nxt.
+ """
+ return [nxt.i_valid.eq(self.o_valid),
+ self.i_ready.eq(nxt.o_ready),
+ eq(nxt.data, self.data),
+ ]
+
+ def connect_out(self, nxt):
+ """ helper function to connect stage to an output source. do not
+ use to connect stage-to-stage!
+ """
+ return [nxt.o_valid.eq(self.o_valid),
+ self.i_ready.eq(nxt.i_ready),
+ eq(nxt.data, self.data),
+ ]
+
def eq(o, i):
if not isinstance(o, Sequence):
self.result = stage.ospec()
self.n.data = stage.ospec()
- def connect_next(self, nxt):
+ def connect_to_next(self, nxt):
""" helper function to connect to the next stage data/valid/ready.
- data/valid is passed *TO* nxt, and ready comes *IN* from nxt.
"""
- return [nxt.p.i_valid.eq(self.n.o_valid),
- self.n.i_ready.eq(nxt.p.o_ready),
- eq(nxt.p.data, self.n.data),
- ]
+ return self.n.connect_to_next(nxt.p)
def connect_in(self, prev):
""" helper function to connect stage to an input source. do not
use to connect stage-to-stage!
"""
- return [self.p.i_valid.eq(prev.p.i_valid),
- prev.p.o_ready.eq(self.p.o_ready),
- eq(self.p.data, prev.p.data),
- ]
+ return self.p.connect_in(prev.p)
def connect_out(self, nxt):
""" helper function to connect stage to an output source. do not
use to connect stage-to-stage!
"""
- return [nxt.n.o_valid.eq(self.n.o_valid),
- self.n.i_ready.eq(nxt.n.i_ready),
- eq(nxt.n.data, self.n.data),
- ]
+ return self.n.connect_out(nxt.n)
def set_input(self, i):
""" helper function to set the input data