2017-01-17 06:53:29 -05:00
|
|
|
import unittest
|
|
|
|
|
2018-02-23 07:39:23 -05:00
|
|
|
from migen import *
|
2017-01-17 06:53:29 -05:00
|
|
|
|
|
|
|
from litex.soc.interconnect.stream import *
|
|
|
|
|
2018-10-01 05:18:54 -04:00
|
|
|
from litedram.common import LiteDRAMNativeWritePort, LiteDRAMNativeReadPort
|
2018-08-21 07:21:04 -04:00
|
|
|
from litedram.frontend.adaptation import LiteDRAMNativePortConverter
|
2017-01-17 06:53:29 -05:00
|
|
|
|
|
|
|
from test.common import *
|
|
|
|
|
2018-08-09 04:54:42 -04:00
|
|
|
from litex.gen.sim import *
|
|
|
|
|
2017-01-17 06:53:29 -05:00
|
|
|
|
|
|
|
class DUT(Module):
|
|
|
|
def __init__(self):
|
|
|
|
# write port and converter
|
2018-10-01 05:18:54 -04:00
|
|
|
self.write_user_port = LiteDRAMNativeWritePort(address_width=32, data_width=32)
|
|
|
|
self.write_crossbar_port = LiteDRAMNativeWritePort(address_width=32, data_width=128)
|
|
|
|
write_converter = LiteDRAMNativePortConverter(
|
|
|
|
self.write_user_port, self.write_crossbar_port)
|
2017-01-17 06:53:29 -05:00
|
|
|
self.submodules += write_converter
|
|
|
|
|
|
|
|
# read port and converter
|
2018-10-01 05:18:54 -04:00
|
|
|
self.read_user_port = LiteDRAMNativeReadPort(address_width=32, data_width=32)
|
|
|
|
self.read_crossbar_port = LiteDRAMNativeReadPort(address_width=32, data_width=128)
|
|
|
|
read_converter = LiteDRAMNativePortConverter(
|
|
|
|
self.read_user_port, self.read_crossbar_port)
|
2017-01-17 06:53:29 -05:00
|
|
|
self.submodules += read_converter
|
|
|
|
|
|
|
|
# memory
|
|
|
|
self.memory = DRAMMemory(128, 128)
|
|
|
|
|
|
|
|
|
|
|
|
write_data = [seed_to_data(i, nbits=32) for i in range(16)]
|
|
|
|
read_data = []
|
|
|
|
|
|
|
|
|
|
|
|
@passive
|
2018-08-28 07:40:50 -04:00
|
|
|
def read_handler(read_port):
|
2017-01-17 06:53:29 -05:00
|
|
|
yield read_port.rdata.ready.eq(1)
|
|
|
|
while True:
|
|
|
|
if (yield read_port.rdata.valid):
|
|
|
|
read_data.append((yield read_port.rdata.data))
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
def main_generator(write_port, read_port):
|
|
|
|
# write
|
|
|
|
for i in range(16):
|
|
|
|
yield write_port.cmd.valid.eq(1)
|
|
|
|
yield write_port.cmd.we.eq(1)
|
2018-10-01 05:18:54 -04:00
|
|
|
yield write_port.cmd.addr.eq(i)
|
2017-01-17 06:53:29 -05:00
|
|
|
yield
|
|
|
|
while (yield write_port.cmd.ready) == 0:
|
|
|
|
yield
|
|
|
|
yield write_port.cmd.valid.eq(0)
|
|
|
|
yield
|
|
|
|
yield write_port.wdata.valid.eq(1)
|
2018-02-23 07:39:23 -05:00
|
|
|
yield write_port.wdata.data.eq(write_data[i])
|
2017-01-17 06:53:29 -05:00
|
|
|
yield
|
|
|
|
while (yield write_port.wdata.ready) == 0:
|
|
|
|
yield
|
|
|
|
yield write_port.wdata.valid.eq(0)
|
|
|
|
yield
|
|
|
|
|
|
|
|
# read
|
|
|
|
for i in range(16):
|
|
|
|
yield read_port.cmd.valid.eq(1)
|
|
|
|
yield read_port.cmd.we.eq(0)
|
2018-10-01 05:18:54 -04:00
|
|
|
yield read_port.cmd.addr.eq(i)
|
2017-01-17 06:53:29 -05:00
|
|
|
yield
|
|
|
|
while (yield read_port.cmd.ready) == 0:
|
|
|
|
yield
|
|
|
|
yield read_port.cmd.valid.eq(0)
|
|
|
|
yield
|
|
|
|
|
|
|
|
# delay
|
|
|
|
for i in range(32):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
class TestUpConverter(unittest.TestCase):
|
|
|
|
def test(self):
|
|
|
|
dut = DUT()
|
2019-06-13 03:15:09 -04:00
|
|
|
generators = [
|
|
|
|
main_generator(dut.write_user_port, dut.read_user_port),
|
|
|
|
read_handler(dut.read_user_port),
|
|
|
|
dut.memory.write_handler(dut.write_crossbar_port),
|
|
|
|
dut.memory.read_handler(dut.read_crossbar_port)
|
|
|
|
]
|
|
|
|
run_simulation(dut, generators)
|
2017-01-17 06:53:29 -05:00
|
|
|
self.assertEqual(write_data, read_data)
|