litex/litesata/test/command_tb.py

95 lines
2.8 KiB
Python
Raw Normal View History

2015-01-16 17:52:41 -05:00
from litesata.common import *
from litesata.core import LiteSATACore
2015-01-16 17:52:41 -05:00
from litesata.test.hdd import *
from litesata.test.common import *
2014-12-14 06:49:35 -05:00
class CommandTXPacket(list):
def __init__(self, write=0, read=0, sector=0, count=0, data=[]):
2014-12-14 06:49:35 -05:00
self.ongoing = False
self.done = False
self.write = write
self.read = read
self.sector = sector
self.count = count
2014-12-14 06:49:35 -05:00
for d in data:
self.append(d)
class CommandStreamer(PacketStreamer):
2014-12-14 06:49:35 -05:00
def __init__(self):
PacketStreamer.__init__(self, command_tx_description(32), CommandTXPacket)
2014-12-14 06:49:35 -05:00
def do_simulation(self, selfp):
PacketStreamer.do_simulation(self, selfp)
2014-12-14 06:49:35 -05:00
selfp.source.write = self.packet.write
selfp.source.read = self.packet.read
selfp.source.sector = self.packet.sector
selfp.source.count = self.packet.count
2014-12-14 06:49:35 -05:00
class CommandRXPacket(list):
def __init__(self):
self.ongoing = False
self.done = False
self.write = 0
self.read = 0
self.failed = 0
class CommandLogger(PacketLogger):
2014-12-14 06:49:35 -05:00
def __init__(self):
PacketLogger.__init__(self, command_rx_description(32), CommandRXPacket)
2014-12-14 06:49:35 -05:00
def do_simulation(self, selfp):
selfp.sink.ack = 1
if selfp.sink.stb == 1 and selfp.sink.sop == 1:
self.packet = CommandRXPacket()
self.packet.write = selfp.sink.write
self.packet.read = selfp.sink.read
2014-12-14 06:59:02 -05:00
self.packet.failed = selfp.sink.failed
2014-12-14 06:49:35 -05:00
self.packet.append(selfp.sink.data)
elif selfp.sink.stb:
self.packet.append(selfp.sink.data)
if selfp.sink.stb == 1 and selfp.sink.eop == 1:
2014-12-14 06:49:35 -05:00
self.packet.done = True
class TB(Module):
def __init__(self):
self.submodules.hdd = HDD(
link_debug=False, link_random_level=50,
2014-12-14 10:20:22 -05:00
transport_debug=False, transport_loopback=False,
2014-12-14 14:30:21 -05:00
hdd_debug=True)
self.submodules.core = LiteSATACore(self.hdd.phy, buffer_depth=512)
self.submodules.streamer = CommandStreamer()
self.submodules.streamer_randomizer = Randomizer(command_tx_description(32), level=50)
self.submodules.logger = CommandLogger()
self.submodules.logger_randomizer = Randomizer(command_rx_description(32), level=50)
self.submodules.pipeline = Pipeline(
self.streamer,
self.streamer_randomizer,
2015-01-16 17:52:41 -05:00
self.core,
self.logger_randomizer,
self.logger
)
2014-12-14 06:49:35 -05:00
def gen_simulation(self, selfp):
hdd = self.hdd
hdd.malloc(0, 64)
2015-01-06 10:48:19 -05:00
write_data = [i for i in range(sectors2dwords(2))]
write_len = dwords2sectors(len(write_data))
write_packet = CommandTXPacket(write=1, sector=2, count=write_len, data=write_data)
2014-12-14 10:20:22 -05:00
yield from self.streamer.send(write_packet)
yield from self.logger.receive()
read_packet = CommandTXPacket(read=1, sector=2, count=write_len)
2014-12-14 10:20:22 -05:00
yield from self.streamer.send(read_packet)
2014-12-14 06:49:35 -05:00
yield from self.logger.receive()
2014-12-14 10:20:22 -05:00
read_data = self.logger.packet
# check results
s, l, e = check(write_data, read_data)
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
if __name__ == "__main__":
run_simulation(TB(), ncycles=2048, vcd_name="my.vcd", keep_files=True)