From: Florent Kermarrec Date: Fri, 5 Dec 2014 17:00:02 +0000 (+0100) Subject: link_tb: use LinkTXPacket and LinkRXPacket from bfm X-Git-Tag: 24jan2021_ls180~2572^2~149 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b238c41b266449e5c8be1aa1de7479acaeb890e6;p=litex.git link_tb: use LinkTXPacket and LinkRXPacket from bfm --- diff --git a/lib/sata/test/bfm.py b/lib/sata/test/bfm.py index af7a2685..5f090288 100644 --- a/lib/sata/test/bfm.py +++ b/lib/sata/test/bfm.py @@ -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: diff --git a/lib/sata/test/link_tb.py b/lib/sata/test/link_tb.py index 3260034f..f2d63ce6 100644 --- a/lib/sata/test/link_tb.py +++ b/lib/sata/test/link_tb.py @@ -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)