litex/lib/sata/test/link_tb.py

48 lines
1.6 KiB
Python
Raw Normal View History

from lib.sata.common import *
2014-12-12 08:35:48 -05:00
from lib.sata.link import SATALink
2014-11-11 12:47:34 -05:00
2014-12-05 11:48:01 -05:00
from lib.sata.test.common import *
from lib.sata.test.hdd import *
2014-11-11 12:47:34 -05:00
class LinkStreamer(PacketStreamer):
2014-12-05 14:26:09 -05:00
def __init__(self):
PacketStreamer.__init__(self, link_description(32), LinkTXPacket)
2014-11-11 12:47:34 -05:00
class LinkLogger(PacketLogger):
2014-12-05 14:26:09 -05:00
def __init__(self):
PacketLogger.__init__(self, link_description(32), LinkRXPacket)
2014-11-11 12:47:34 -05:00
class TB(Module):
def __init__(self):
2014-12-14 10:20:22 -05:00
self.submodules.hdd = HDD(
2014-12-15 14:00:19 -05:00
link_debug=False, link_random_level=50,
2014-12-14 10:20:22 -05:00
transport_debug=False, transport_loopback=True)
self.submodules.link = SATALink(self.hdd.phy)
2014-11-11 12:47:34 -05:00
2014-12-05 14:26:09 -05:00
self.submodules.streamer = LinkStreamer()
2014-12-14 04:52:56 -05:00
streamer_ack_randomizer = AckRandomizer(link_description(32), level=50)
2014-12-02 15:34:16 -05:00
self.submodules += streamer_ack_randomizer
2014-12-05 14:26:09 -05:00
self.submodules.logger = LinkLogger()
2014-12-14 04:52:56 -05:00
logger_ack_randomizer = AckRandomizer(link_description(32), level=50)
2014-12-05 15:27:26 -05:00
self.submodules += logger_ack_randomizer
2014-11-11 12:47:34 -05:00
self.comb += [
2014-12-02 15:34:16 -05:00
Record.connect(self.streamer.source, streamer_ack_randomizer.sink),
2014-12-12 08:35:48 -05:00
Record.connect(streamer_ack_randomizer.source, self.link.sink),
Record.connect(self.link.source, logger_ack_randomizer.sink),
2014-12-05 15:27:26 -05:00
Record.connect(logger_ack_randomizer.source, self.logger.sink)
2014-11-11 12:47:34 -05:00
]
def gen_simulation(self, selfp):
2014-11-12 12:20:34 -05:00
for i in range(8):
2014-12-06 08:35:18 -05:00
streamer_packet = LinkTXPacket([i for i in range(64)])
2014-12-14 10:20:22 -05:00
yield from self.streamer.send(streamer_packet)
2014-12-05 14:26:09 -05:00
yield from self.logger.receive()
2014-12-06 08:35:18 -05:00
# check results
s, l, e = check(streamer_packet, self.logger.packet)
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
2014-12-05 14:26:09 -05:00
2014-11-11 12:47:34 -05:00
if __name__ == "__main__":
2014-12-05 15:27:26 -05:00
run_simulation(TB(), ncycles=2048, vcd_name="my.vcd", keep_files=True)