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):
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
def __init__(self, dw):
self.sink = Sink(link_layout(dw))
###
- self.packet = LinkPacket()
+ self.packet = LinkRXPacket()
def receive(self):
self.packet.done = 0
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):
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)