2014-11-04 11:06:03 -05:00
|
|
|
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-11-04 11:06:03 -05:00
|
|
|
from lib.sata.link.test.common import check
|
2014-11-04 05:40:43 -05:00
|
|
|
|
|
|
|
class TB(Module):
|
2014-11-04 11:06:03 -05:00
|
|
|
def __init__(self, length):
|
2014-11-11 10:15:28 -05:00
|
|
|
self.submodules.scrambler = Scrambler()
|
2014-11-04 11:06:03 -05:00
|
|
|
self.length = length
|
2014-11-04 05:40:43 -05:00
|
|
|
|
|
|
|
def gen_simulation(self, selfp):
|
|
|
|
# init CRC
|
|
|
|
selfp.scrambler.ce = 1
|
|
|
|
selfp.scrambler.reset = 1
|
|
|
|
yield
|
|
|
|
selfp.scrambler.reset = 0
|
|
|
|
|
|
|
|
# get C code results
|
2014-11-04 11:06:03 -05:00
|
|
|
p = subprocess.Popen(["./scrambler"], stdout=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
ref = [int(e, 16) for e in out.decode("utf-8").split("\n")[:-1]]
|
2014-11-04 05:40:43 -05:00
|
|
|
|
|
|
|
# log results
|
|
|
|
yield
|
|
|
|
res = []
|
2014-11-04 11:06:03 -05:00
|
|
|
for i in range(self.length):
|
2014-11-04 05:40:43 -05:00
|
|
|
res.append(selfp.scrambler.value)
|
|
|
|
yield
|
|
|
|
|
|
|
|
# check results
|
|
|
|
s, l, e = check(ref, res)
|
|
|
|
print("shift "+ str(s) + " / length " + str(l) + " / errors " + str(e))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
from migen.sim.generic import run_simulation
|
2014-11-04 11:06:03 -05:00
|
|
|
length = 8192
|
|
|
|
run_simulation(TB(length), ncycles=length+100, vcd_name="my.vcd", keep_files=True)
|