test: create generic PacketStreamer/PacketLogger and use it in link_tb/command_tb
This commit is contained in:
parent
bcc0be10ee
commit
9ba9470974
|
@ -1,4 +1,4 @@
|
||||||
import random, copy
|
import random
|
||||||
|
|
||||||
from migen.fhdl.std import *
|
from migen.fhdl.std import *
|
||||||
from migen.genlib.record import *
|
from migen.genlib.record import *
|
||||||
|
@ -24,48 +24,18 @@ class CommandTXPacket(list):
|
||||||
for d in data:
|
for d in data:
|
||||||
self.append(d)
|
self.append(d)
|
||||||
|
|
||||||
class CommandStreamer(Module):
|
class CommandStreamer(PacketStreamer):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.source = Source(command_tx_description(32))
|
PacketStreamer.__init__(self, command_tx_description(32), CommandTXPacket)
|
||||||
###
|
|
||||||
self.packets = []
|
|
||||||
self.packet = CommandTXPacket()
|
|
||||||
self.packet.done = 1
|
|
||||||
self.length = 0
|
|
||||||
|
|
||||||
def send(self, packet, blocking=True):
|
|
||||||
packet = copy.deepcopy(packet)
|
|
||||||
self.packets.append(packet)
|
|
||||||
if blocking:
|
|
||||||
while packet.done == 0:
|
|
||||||
yield
|
|
||||||
|
|
||||||
def do_simulation(self, selfp):
|
def do_simulation(self, selfp):
|
||||||
if len(self.packets) and self.packet.done:
|
PacketStreamer.do_simulation(self, selfp)
|
||||||
self.packet = self.packets.pop(0)
|
|
||||||
|
|
||||||
selfp.source.write = self.packet.write
|
selfp.source.write = self.packet.write
|
||||||
selfp.source.read = self.packet.read
|
selfp.source.read = self.packet.read
|
||||||
selfp.source.identify = self.packet.identify
|
selfp.source.identify = self.packet.identify
|
||||||
selfp.source.sector = self.packet.sector
|
selfp.source.sector = self.packet.sector
|
||||||
selfp.source.count = self.packet.count
|
selfp.source.count = self.packet.count
|
||||||
|
|
||||||
if not self.packet.ongoing and not self.packet.done:
|
|
||||||
selfp.source.stb = 1
|
|
||||||
selfp.source.sop = 1
|
|
||||||
if len(self.packet) > 0:
|
|
||||||
selfp.source.data = 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) == 1)
|
|
||||||
if len(self.packet) > 0:
|
|
||||||
selfp.source.stb = 1
|
|
||||||
selfp.source.data = self.packet.pop(0)
|
|
||||||
else:
|
|
||||||
self.packet.done = 1
|
|
||||||
selfp.source.stb = 0
|
|
||||||
|
|
||||||
class CommandRXPacket(list):
|
class CommandRXPacket(list):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ongoing = False
|
self.ongoing = False
|
||||||
|
@ -76,16 +46,9 @@ class CommandRXPacket(list):
|
||||||
self.success = 0
|
self.success = 0
|
||||||
self.failed = 0
|
self.failed = 0
|
||||||
|
|
||||||
class CommandLogger(Module):
|
class CommandLogger(PacketLogger):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sink = Sink(command_rx_description(32))
|
PacketLogger.__init__(self, command_rx_description(32), CommandRXPacket)
|
||||||
###
|
|
||||||
self.packet = CommandRXPacket()
|
|
||||||
|
|
||||||
def receive(self):
|
|
||||||
self.packet.done = 0
|
|
||||||
while self.packet.done == 0:
|
|
||||||
yield
|
|
||||||
|
|
||||||
def do_simulation(self, selfp):
|
def do_simulation(self, selfp):
|
||||||
selfp.sink.ack = 1
|
selfp.sink.ack = 1
|
||||||
|
@ -99,7 +62,7 @@ class CommandLogger(Module):
|
||||||
self.packet.append(selfp.sink.data)
|
self.packet.append(selfp.sink.data)
|
||||||
elif selfp.sink.stb:
|
elif selfp.sink.stb:
|
||||||
self.packet.append(selfp.sink.data)
|
self.packet.append(selfp.sink.data)
|
||||||
if (selfp.sink.stb == 1 and selfp.sink.eop == 1):
|
if selfp.sink.stb == 1 and selfp.sink.eop == 1:
|
||||||
self.packet.done = True
|
self.packet.done = True
|
||||||
|
|
||||||
class TB(Module):
|
class TB(Module):
|
||||||
|
|
|
@ -32,6 +32,70 @@ def check(p1, p2):
|
||||||
def randn(max_n):
|
def randn(max_n):
|
||||||
return random.randint(0, max_n-1)
|
return random.randint(0, max_n-1)
|
||||||
|
|
||||||
|
class PacketStreamer(Module):
|
||||||
|
def __init__(self, description, packet_class):
|
||||||
|
self.source = Source(description)
|
||||||
|
###
|
||||||
|
self.packets = []
|
||||||
|
self.packet = packet_class()
|
||||||
|
self.packet.done = 1
|
||||||
|
|
||||||
|
def send(self, packet, blocking=True):
|
||||||
|
packet = copy.deepcopy(packet)
|
||||||
|
self.packets.append(packet)
|
||||||
|
if blocking:
|
||||||
|
while packet.done == 0:
|
||||||
|
yield
|
||||||
|
|
||||||
|
def do_simulation(self, selfp):
|
||||||
|
if len(self.packets) and self.packet.done:
|
||||||
|
self.packet = self.packets.pop(0)
|
||||||
|
if not self.packet.ongoing and not self.packet.done:
|
||||||
|
selfp.source.stb = 1
|
||||||
|
selfp.source.sop = 1
|
||||||
|
if len(self.packet) > 0:
|
||||||
|
if hasattr(selfp.source, "data"):
|
||||||
|
selfp.source.data = self.packet.pop(0)
|
||||||
|
else:
|
||||||
|
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) == 1)
|
||||||
|
if len(self.packet) > 0:
|
||||||
|
selfp.source.stb = 1
|
||||||
|
if hasattr(selfp.source, "data"):
|
||||||
|
selfp.source.data = self.packet.pop(0)
|
||||||
|
else:
|
||||||
|
selfp.source.d = self.packet.pop(0)
|
||||||
|
else:
|
||||||
|
self.packet.done = 1
|
||||||
|
selfp.source.stb = 0
|
||||||
|
|
||||||
|
class PacketLogger(Module):
|
||||||
|
def __init__(self, description, packet_class):
|
||||||
|
self.sink = Sink(description)
|
||||||
|
###
|
||||||
|
self.packet_class = packet_class
|
||||||
|
self.packet = packet_class()
|
||||||
|
|
||||||
|
def receive(self):
|
||||||
|
self.packet.done = 0
|
||||||
|
while self.packet.done == 0:
|
||||||
|
yield
|
||||||
|
|
||||||
|
def do_simulation(self, selfp):
|
||||||
|
selfp.sink.ack = 1
|
||||||
|
if selfp.sink.stb == 1 and selfp.sink.sop == 1:
|
||||||
|
self.packet = self.packet_class()
|
||||||
|
if selfp.sink.stb:
|
||||||
|
if hasattr(selfp.sink, "data"):
|
||||||
|
self.packet.append(selfp.sink.data)
|
||||||
|
else:
|
||||||
|
self.packet.append(selfp.sink.d)
|
||||||
|
if selfp.sink.stb == 1 and selfp.sink.eop == 1:
|
||||||
|
self.packet.done = True
|
||||||
|
|
||||||
class AckRandomizer(Module):
|
class AckRandomizer(Module):
|
||||||
def __init__(self, description, level=0):
|
def __init__(self, description, level=0):
|
||||||
self.level = level
|
self.level = level
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import random, copy
|
import random
|
||||||
|
|
||||||
from migen.fhdl.std import *
|
from migen.fhdl.std import *
|
||||||
from migen.genlib.record import *
|
from migen.genlib.record import *
|
||||||
|
@ -7,62 +7,16 @@ from migen.sim.generic import run_simulation
|
||||||
from lib.sata.common import *
|
from lib.sata.common import *
|
||||||
from lib.sata.link import SATALink
|
from lib.sata.link import SATALink
|
||||||
|
|
||||||
from lib.sata.test.hdd import *
|
|
||||||
from lib.sata.test.common import *
|
from lib.sata.test.common import *
|
||||||
|
from lib.sata.test.hdd import *
|
||||||
|
|
||||||
class LinkStreamer(Module):
|
class LinkStreamer(PacketStreamer):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.source = Source(link_description(32))
|
PacketStreamer.__init__(self, link_description(32), LinkTXPacket)
|
||||||
###
|
|
||||||
self.packets = []
|
|
||||||
self.packet = LinkTXPacket()
|
|
||||||
self.packet.done = 1
|
|
||||||
|
|
||||||
def send(self, packet, blocking=True):
|
class LinkLogger(PacketLogger):
|
||||||
packet = copy.deepcopy(packet)
|
|
||||||
self.packets.append(packet)
|
|
||||||
if blocking:
|
|
||||||
while packet.done == 0:
|
|
||||||
yield
|
|
||||||
|
|
||||||
def do_simulation(self, selfp):
|
|
||||||
if len(self.packets) and self.packet.done:
|
|
||||||
self.packet = self.packets.pop(0)
|
|
||||||
if not self.packet.ongoing and not self.packet.done:
|
|
||||||
selfp.source.stb = 1
|
|
||||||
selfp.source.sop = 1
|
|
||||||
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) == 1)
|
|
||||||
if len(self.packet) > 0:
|
|
||||||
selfp.source.stb = 1
|
|
||||||
selfp.source.d = self.packet.pop(0)
|
|
||||||
else:
|
|
||||||
self.packet.done = 1
|
|
||||||
selfp.source.stb = 0
|
|
||||||
|
|
||||||
class LinkLogger(Module):
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sink = Sink(link_description(32))
|
PacketLogger.__init__(self, link_description(32), LinkRXPacket)
|
||||||
###
|
|
||||||
self.packet = LinkRXPacket()
|
|
||||||
|
|
||||||
def receive(self):
|
|
||||||
self.packet.done = 0
|
|
||||||
while self.packet.done == 0:
|
|
||||||
yield
|
|
||||||
|
|
||||||
def do_simulation(self, selfp):
|
|
||||||
selfp.sink.ack = 1
|
|
||||||
if selfp.sink.stb == 1 and selfp.sink.sop == 1:
|
|
||||||
self.packet = LinkRXPacket()
|
|
||||||
self.packet.append(selfp.sink.d)
|
|
||||||
elif selfp.sink.stb:
|
|
||||||
self.packet.append(selfp.sink.d)
|
|
||||||
if (selfp.sink.stb ==1 and selfp.sink.eop ==1):
|
|
||||||
self.packet.done = True
|
|
||||||
|
|
||||||
class TB(Module):
|
class TB(Module):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue