2014-11-04 11:06:03 -05:00
|
|
|
import subprocess
|
2014-11-03 12:54:41 -05:00
|
|
|
|
|
|
|
from migen.fhdl.std import *
|
|
|
|
|
|
|
|
from lib.sata.std import *
|
|
|
|
from lib.sata.link.crc import *
|
2014-11-04 11:06:03 -05:00
|
|
|
from lib.sata.link.test.common import check
|
2014-11-03 12:54:41 -05:00
|
|
|
|
|
|
|
class TB(Module):
|
2014-11-04 11:06:03 -05:00
|
|
|
def __init__(self, length):
|
2014-11-03 12:54:41 -05:00
|
|
|
self.submodules.crc = SATACRC()
|
2014-11-04 11:06:03 -05:00
|
|
|
self.length = length
|
2014-11-03 12:54:41 -05:00
|
|
|
|
|
|
|
def gen_simulation(self, selfp):
|
|
|
|
# init CRC
|
|
|
|
selfp.crc.d = 0x12345678
|
|
|
|
selfp.crc.ce = 1
|
|
|
|
selfp.crc.reset = 1
|
|
|
|
yield
|
|
|
|
selfp.crc.reset = 0
|
|
|
|
|
|
|
|
# get C code results
|
2014-11-04 11:06:03 -05:00
|
|
|
p = subprocess.Popen(["./crc"], stdout=subprocess.PIPE)
|
|
|
|
out, err = p.communicate()
|
|
|
|
ref = [int(e, 16) for e in out.decode("utf-8").split("\n")[:-1]]
|
|
|
|
|
2014-11-03 12:54:41 -05:00
|
|
|
|
|
|
|
# log results
|
|
|
|
res = []
|
2014-11-04 11:06:03 -05:00
|
|
|
for i in range(self.length):
|
2014-11-03 12:54:41 -05:00
|
|
|
res.append(selfp.crc.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)
|