2016-05-26 05:10:03 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-05-24 15:14:49 -04:00
|
|
|
from litex.gen import *
|
|
|
|
|
|
|
|
from litex.soc.interconnect.stream import *
|
2016-06-08 11:33:21 -04:00
|
|
|
from litex.soc.interconnect.stream_sim import check
|
2016-05-24 15:14:49 -04:00
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
from litedram.common import LiteDRAMWritePort, LiteDRAMReadPort
|
2016-05-26 05:03:55 -04:00
|
|
|
from litedram.frontend.adaptation import LiteDRAMPortConverter
|
2016-05-24 15:14:49 -04:00
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
from test.common import *
|
2016-05-24 15:14:49 -04:00
|
|
|
|
|
|
|
class TB(Module):
|
|
|
|
def __init__(self):
|
2016-06-15 11:51:46 -04:00
|
|
|
self.write_user_port = LiteDRAMWritePort(aw=32, dw=32)
|
|
|
|
self.write_crossbar_port = LiteDRAMWritePort(aw=32, dw=64)
|
|
|
|
self.submodules.write_converter = LiteDRAMPortConverter(self.write_user_port,
|
|
|
|
self.write_crossbar_port)
|
|
|
|
|
|
|
|
self.read_user_port = LiteDRAMReadPort(aw=32, dw=32)
|
|
|
|
self.read_crossbar_port = LiteDRAMReadPort(aw=32, dw=64)
|
|
|
|
self.submodules.read_converter = LiteDRAMPortConverter(self.read_user_port,
|
|
|
|
self.read_crossbar_port)
|
|
|
|
|
2016-05-24 15:14:49 -04:00
|
|
|
self.memory = DRAMMemory(64, 128)
|
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
write_data = [seed_to_data(i, nbits=32) for i in range(8)]
|
|
|
|
read_data = []
|
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
@passive
|
|
|
|
def read_generator(dut):
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.read_user_port.rdata.ready.eq(1)
|
2016-06-08 11:33:21 -04:00
|
|
|
while True:
|
2016-06-15 11:51:46 -04:00
|
|
|
if (yield dut.read_user_port.rdata.valid):
|
|
|
|
read_data.append((yield dut.read_user_port.rdata.data))
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-08 11:33:21 -04:00
|
|
|
|
2016-06-15 11:51:46 -04:00
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
def main_generator(dut):
|
2016-05-24 15:14:49 -04:00
|
|
|
# write
|
|
|
|
for i in range(8):
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.write_user_port.cmd.valid.eq(1)
|
|
|
|
yield dut.write_user_port.cmd.we.eq(1)
|
|
|
|
yield dut.write_user_port.cmd.adr.eq(i)
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
while (yield dut.write_user_port.cmd.ready) == 0:
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.write_user_port.cmd.valid.eq(0)
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.write_user_port.wdata.valid.eq(1)
|
|
|
|
yield dut.write_user_port.wdata.data.eq(write_data[i])
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
while (yield dut.write_user_port.wdata.ready) == 0:
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.write_user_port.wdata.valid.eq(0)
|
2016-05-24 15:14:49 -04:00
|
|
|
yield
|
2016-06-08 11:33:21 -04:00
|
|
|
|
2016-05-24 15:40:46 -04:00
|
|
|
# read
|
|
|
|
for i in range(8):
|
|
|
|
for j in range(2):
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.read_user_port.cmd.valid.eq(1)
|
|
|
|
yield dut.read_user_port.cmd.we.eq(0)
|
|
|
|
yield dut.read_user_port.cmd.adr.eq(i)
|
2016-05-24 15:40:46 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
while (yield dut.read_user_port.cmd.ready) == 0:
|
2016-05-24 15:40:46 -04:00
|
|
|
yield
|
2016-06-15 11:51:46 -04:00
|
|
|
yield dut.read_user_port.cmd.valid.eq(0)
|
2016-05-24 15:40:46 -04:00
|
|
|
yield
|
2016-05-24 15:14:49 -04:00
|
|
|
|
2016-06-08 11:33:21 -04:00
|
|
|
# delay
|
|
|
|
for i in range(32):
|
|
|
|
yield
|
|
|
|
|
|
|
|
# check
|
|
|
|
s, l, e = check(write_data, read_data)
|
|
|
|
print("shift " + str(s) + " / length " + str(l) + " / errors " + str(e))
|
|
|
|
|
|
|
|
|
2016-05-24 15:14:49 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
tb = TB()
|
|
|
|
generators = {
|
|
|
|
"sys" : [main_generator(tb),
|
2016-06-08 11:33:21 -04:00
|
|
|
read_generator(tb),
|
2016-06-15 11:51:46 -04:00
|
|
|
tb.memory.write_generator(tb.write_crossbar_port),
|
|
|
|
tb.memory.read_generator(tb.read_crossbar_port)]
|
2016-05-24 15:14:49 -04:00
|
|
|
}
|
|
|
|
clocks = {"sys": 10}
|
|
|
|
run_simulation(tb, generators, clocks, vcd_name="sim.vcd")
|