litex/misoclib/mem/litesata/test/cont_tb.py

100 lines
3.1 KiB
Python
Raw Normal View History

from misoclib.mem.litesata.common import *
from misoclib.mem.litesata.core.link.cont import LiteSATACONTInserter, LiteSATACONTRemover
2014-12-19 05:15:01 -05:00
from misoclib.mem.litesata.test.common import *
2014-12-19 05:15:01 -05:00
2015-04-13 09:12:39 -04:00
2014-12-19 05:15:01 -05:00
class ContPacket(list):
def __init__(self, data=[]):
self.ongoing = False
self.done = False
for d in data:
self.append(d)
2014-12-19 05:15:01 -05:00
2015-04-13 09:12:39 -04:00
2014-12-19 05:15:01 -05:00
class ContStreamer(PacketStreamer):
def __init__(self):
PacketStreamer.__init__(self, phy_description(32), ContPacket)
2014-12-19 05:15:01 -05:00
def do_simulation(self, selfp):
PacketStreamer.do_simulation(self, selfp)
selfp.source.charisk = 0
# Note: for simplicity we generate charisk by detecting
# primitives in data
for k, v in primitives.items():
try:
if self.source_data == v:
selfp.source.charisk = 0b0001
except:
pass
2014-12-19 05:15:01 -05:00
2015-04-13 09:12:39 -04:00
2014-12-19 05:15:01 -05:00
class ContLogger(PacketLogger):
def __init__(self):
PacketLogger.__init__(self, phy_description(32), ContPacket)
2014-12-19 05:15:01 -05:00
2015-04-13 09:12:39 -04:00
2014-12-19 05:15:01 -05:00
class TB(Module):
def __init__(self):
self.submodules.streamer = ContStreamer()
self.submodules.streamer_randomizer = Randomizer(phy_description(32), level=50)
self.submodules.inserter = LiteSATACONTInserter(phy_description(32))
self.submodules.remover = LiteSATACONTRemover(phy_description(32))
self.submodules.logger_randomizer = Randomizer(phy_description(32), level=50)
self.submodules.logger = ContLogger()
self.submodules.pipeline = Pipeline(
self.streamer,
self.streamer_randomizer,
self.inserter,
self.remover,
self.logger_randomizer,
self.logger
)
2014-12-19 05:15:01 -05:00
def gen_simulation(self, selfp):
test_packet = ContPacket([
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["ALIGN"],
primitives["ALIGN"],
primitives["SYNC"],
primitives["SYNC"],
#primitives["SYNC"],
0x00000000,
0x00000001,
0x00000002,
0x00000003,
0x00000004,
0x00000005,
0x00000006,
0x00000007,
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["ALIGN"],
primitives["ALIGN"],
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"],
primitives["SYNC"]]*4
)
streamer_packet = ContPacket(test_packet)
yield from self.streamer.send(streamer_packet)
yield from self.logger.receive(len(test_packet))
#for d in self.logger.packet:
2015-04-13 09:55:22 -04:00
# print("{:08}".format(d))
2014-12-19 05:15:01 -05:00
# check results
s, l, e = check(streamer_packet, self.logger.packet)
2015-04-13 09:44:04 -04:00
print("shift " + str(s) + " / length " + str(l) + " / errors " + str(e))
2014-12-19 05:15:01 -05:00
if __name__ == "__main__":
run_simulation(TB(), ncycles=1024, vcd_name="my.vcd", keep_files=True)