link_tb: use LinkTXPacket and LinkRXPacket from bfm
This commit is contained in:
parent
e900b9031c
commit
b238c41b26
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue