move connect_out function to NextControl
[ieee754fpu.git] / src / add / example_buf_pipe.py
index 6d42c1cc6411d7440922bd5f6a6d19c12dff9f41..568c7c692b901c69ef592708fa1d7f57bed2a052 100644 (file)
@@ -59,6 +59,15 @@ class PrevControl:
         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)
@@ -79,6 +88,15 @@ class NextControl:
                 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):
@@ -142,7 +160,6 @@ class BufferedPipeline:
 
     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 self.n.connect_to_next(nxt.p)
 
@@ -150,19 +167,13 @@ class BufferedPipeline:
         """ 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