litex/lib/sata/test/scrambler_tb.py

52 lines
1.2 KiB
Python
Raw Normal View History

import subprocess
2014-11-04 05:40:43 -05:00
from migen.fhdl.std import *
from lib.sata.std import *
from lib.sata.link.scrambler import *
2014-12-05 11:48:01 -05:00
from lib.sata.test.common import *
2014-11-04 05:40:43 -05:00
class TB(Module):
def __init__(self, length):
2014-12-05 19:23:03 -05:00
self.submodules.scrambler = InsertReset(Scrambler())
self.length = length
2014-11-04 05:40:43 -05:00
def get_c_values(self, length):
stdin = "0x%08x" %length
with subprocess.Popen("./scrambler", stdin=subprocess.PIPE, stdout=subprocess.PIPE) as process:
process.stdin.write(stdin.encode("ASCII"))
out, err = process.communicate()
return [int(e, 16) for e in out.decode("ASCII").split("\n")[:-1]]
2014-11-04 05:40:43 -05:00
def gen_simulation(self, selfp):
# init CRC
2014-11-04 05:40:43 -05:00
selfp.scrambler.ce = 1
selfp.scrambler.reset = 1
yield
selfp.scrambler.reset = 0
# log results
2014-11-04 05:40:43 -05:00
yield
sim_values = []
for i in range(self.length):
sim_values.append(selfp.scrambler.value)
2014-11-04 05:40:43 -05:00
yield
# stop
selfp.scrambler.ce = 0
for i in range(32):
yield
# get C code reference
c_values = self.get_c_values(self.length)
# check results
s, l, e = check(c_values, sim_values)
2014-11-04 05:40:43 -05:00
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
if __name__ == "__main__":
from migen.sim.generic import run_simulation
length = 8192
run_simulation(TB(length), ncycles=length+100, vcd_name="my.vcd")