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-12-05 11:48:01 -05:00
|
|
|
|
|
|
|
from lib.sata.test.common import *
|
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
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
def get_c_values(self, length):
|
|
|
|
stdin = "0x%08x" %length
|
|
|
|
with subprocess.Popen("./scrambler", stdin=subprocess.PIPE, stdout=subprocess.PIPE) as process:
|
2014-12-02 13:53:13 -05:00
|
|
|
process.stdin.write(stdin.encode("ASCII"))
|
2014-12-02 13:24:46 -05:00
|
|
|
out, err = process.communicate()
|
2014-12-02 13:53:13 -05:00
|
|
|
return [int(e, 16) for e in out.decode("ASCII").split("\n")[:-1]]
|
2014-12-02 13:24:46 -05:00
|
|
|
|
2014-11-04 05:40:43 -05:00
|
|
|
def gen_simulation(self, selfp):
|
2014-12-02 13:24:46 -05:00
|
|
|
# init CRC
|
2014-11-04 05:40:43 -05:00
|
|
|
selfp.scrambler.ce = 1
|
|
|
|
selfp.scrambler.reset = 1
|
|
|
|
yield
|
|
|
|
selfp.scrambler.reset = 0
|
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
# log results
|
2014-11-04 05:40:43 -05:00
|
|
|
yield
|
2014-12-02 13:24:46 -05:00
|
|
|
sim_values = []
|
2014-11-04 11:06:03 -05:00
|
|
|
for i in range(self.length):
|
2014-12-02 13:24:46 -05:00
|
|
|
sim_values.append(selfp.scrambler.value)
|
2014-11-04 05:40:43 -05:00
|
|
|
yield
|
|
|
|
|
2014-12-02 13:24:46 -05:00
|
|
|
# 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
|
2014-11-04 11:06:03 -05:00
|
|
|
length = 8192
|
2014-12-02 13:24:46 -05:00
|
|
|
run_simulation(TB(length), ncycles=length+100, vcd_name="my.vcd")
|