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-12-02 13:24:46 -05:00
|
|
|
from lib.sata.link.test.common import *
|
2014-11-03 12:54:41 -05:00
|
|
|
|
|
|
|
class TB(Module):
|
2014-12-02 13:24:46 -05:00
|
|
|
def __init__(self, length, random):
|
2014-11-03 12:54:41 -05:00
|
|
|
self.submodules.crc = SATACRC()
|
2014-11-04 11:06:03 -05:00
|
|
|
self.length = length
|
2014-12-02 13:24:46 -05:00
|
|
|
self.random = random
|
|
|
|
|
|
|
|
def get_c_crc(self, datas):
|
|
|
|
stdin = ""
|
|
|
|
for data in datas:
|
|
|
|
stdin += "0x%08x " %data
|
|
|
|
stdin += "exit"
|
|
|
|
with subprocess.Popen("./crc", stdin=subprocess.PIPE, stdout=subprocess.PIPE) as process:
|
|
|
|
process.stdin.write(stdin.encode("UTF-8"))
|
|
|
|
out, err = process.communicate()
|
|
|
|
return int(out.decode("UTF-8"), 16)
|
2014-11-03 12:54:41 -05:00
|
|
|
|
|
|
|
def gen_simulation(self, selfp):
|
2014-12-02 13:24:46 -05:00
|
|
|
# init CRC
|
|
|
|
selfp.crc.d = 0
|
2014-11-03 12:54:41 -05:00
|
|
|
selfp.crc.ce = 1
|
|
|
|
selfp.crc.reset = 1
|
|
|
|
yield
|
|
|
|
selfp.crc.reset = 0
|
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
# feed CRC with datas
|
|
|
|
datas = []
|
|
|
|
for i in range(self.length):
|
|
|
|
data = seed_to_data(i, self.random)
|
|
|
|
datas.append(data)
|
|
|
|
selfp.crc.d = data
|
|
|
|
yield
|
2014-11-04 11:06:03 -05:00
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
# log results
|
|
|
|
yield
|
|
|
|
sim_crc = selfp.crc.value
|
2014-11-03 12:54:41 -05:00
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
# stop
|
|
|
|
selfp.crc.ce = 0
|
|
|
|
for i in range(32):
|
2014-11-03 12:54:41 -05:00
|
|
|
yield
|
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
# get C core reference
|
|
|
|
c_crc = self.get_c_crc(datas)
|
|
|
|
|
|
|
|
# check results
|
|
|
|
s, l, e = check(c_crc, sim_crc)
|
2014-11-03 12:54:41 -05:00
|
|
|
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
|
2014-12-02 13:24:46 -05:00
|
|
|
run_simulation(TB(length, True), ncycles=length+100, vcd_name="my.vcd")
|