link_tb: use LinkTXPacket and LinkRXPacket from bfm
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 5 Dec 2014 17:00:02 +0000 (18:00 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 5 Dec 2014 17:00:02 +0000 (18:00 +0100)
lib/sata/test/bfm.py
lib/sata/test/link_tb.py

index af7a2685796176f93fd1a8034160c4cefc65b267..5f09028822ed6eee3b67b09d2f2f3f6ae03b6798 100644 (file)
@@ -79,9 +79,12 @@ class PHYLayer(Module):
                return receiving + sending
 
 class LinkPacket(list):
-       def __init__(self):
+       def __init__(self, init=[]):
                self.ongoing = False
+               self.done = False
                self.scrambled_datas = self.import_scrambler_datas()
+               for dword in init:
+                       self.append(dword)
 
        def import_scrambler_datas(self):
                with subprocess.Popen(["./scrambler"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) as process:
index 3260034fed5f1e1ed2d4c42e3c67e8686912e490..f2d63ce68f74ad423fefc3b2b3630ab01e5ce438 100644 (file)
@@ -10,18 +10,12 @@ from lib.sata.link import SATALinkLayer
 from lib.sata.test.bfm import *
 from lib.sata.test.common import *
 
-class LinkPacket():
-       def __init__(self, d=[]):
-               self.d = d
-               self.start = 1
-               self.done = 0
-
 class LinkStreamer(Module):
        def __init__(self, dw):
                self.source = Source(link_layout(dw))
                ###
                self.packets = []
-               self.packet = LinkPacket()
+               self.packet = LinkTXPacket()
                self.packet.done = 1
 
        def send(self, packet, blocking=True):
@@ -33,17 +27,17 @@ class LinkStreamer(Module):
        def do_simulation(self, selfp):
                if len(self.packets) and self.packet.done:
                        self.packet = self.packets.pop(0)
-               if self.packet.start and not self.packet.done:
+               if not self.packet.ongoing and not self.packet.done:
                        selfp.source.stb = 1
                        selfp.source.sop = 1
-                       selfp.source.d = self.packet.d.pop(0)
-                       self.packet.start = 0
+                       selfp.source.d = self.packet.pop(0)
+                       self.packet.ongoing = True
                elif selfp.source.stb == 1 and selfp.source.ack == 1:
                        selfp.source.sop = 0
-                       selfp.source.eop = (len(self.packet.d) == 1)
-                       if len(self.packet.d) > 0:
+                       selfp.source.eop = (len(self.packet) == 1)
+                       if len(self.packet) > 0:
                                selfp.source.stb = 1
-                               selfp.source.d = self.packet.d.pop(0)
+                               selfp.source.d = self.packet.pop(0)
                        else:
                                self.packet.done = 1
                                selfp.source.stb = 0
@@ -52,7 +46,7 @@ class LinkLogger(Module):
        def __init__(self, dw):
                self.sink = Sink(link_layout(dw))
                ###
-               self.packet = LinkPacket()
+               self.packet = LinkRXPacket()
 
        def receive(self):
                self.packet.done = 0
@@ -60,16 +54,14 @@ class LinkLogger(Module):
                        yield
 
        def do_simulation(self, selfp):
-               self.packet.done = 0
                selfp.sink.ack = 1
                if selfp.sink.stb == 1 and selfp.sink.sop == 1:
-                       self.packet.start = 1
-                       self.packet.d = [selfp.sink.d]
+                       self.packet = LinkRXPacket()
+                       self.packet.append(selfp.sink.d)
                elif selfp.sink.stb:
-                       self.packet.start = 0
-                       self.packet.d.append(selfp.sink.d)
+                       self.packet.append(selfp.sink.d)
                if (selfp.sink.stb ==1 and selfp.sink.eop ==1):
-                       self.packet.done = 1
+                       self.packet.done = True
 
 class TB(Module):
        def __init__(self):
@@ -90,7 +82,7 @@ class TB(Module):
                for i in range(200):
                        yield
                for i in range(8):
-                       yield from self.streamer.send(LinkPacket([i for i in range(16)]))
+                       yield from self.streamer.send(LinkTXPacket([i for i in range(16)]))
 
 if __name__ == "__main__":
        run_simulation(TB(), ncycles=512, vcd_name="my.vcd", keep_files=True)