2019-07-23 06:39:43 -04:00
|
|
|
# This file is Copyright (c) 2019 Florent Kermarrec <florent@enjoy-digital.fr>
|
|
|
|
# License: BSD
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import random
|
|
|
|
|
|
|
|
from migen import *
|
|
|
|
|
2019-07-23 09:58:26 -04:00
|
|
|
from litedram.common import tXXDController, tFAWController
|
2019-07-23 06:39:43 -04:00
|
|
|
|
2019-07-23 09:48:32 -04:00
|
|
|
|
|
|
|
def c2bool(c):
|
|
|
|
return {"-": 1, "_": 0}[c]
|
|
|
|
|
|
|
|
|
2019-07-23 10:05:31 -04:00
|
|
|
class TestTiming(unittest.TestCase):
|
2019-07-23 09:48:32 -04:00
|
|
|
def txxd_controller_test(self, txxd, valids, readys):
|
|
|
|
def generator(dut):
|
|
|
|
dut.errors = 0
|
|
|
|
for valid, ready in zip(valids, readys):
|
|
|
|
yield dut.valid.eq(c2bool(valid))
|
|
|
|
yield
|
|
|
|
if (yield dut.ready) != c2bool(ready):
|
|
|
|
dut.errors += 1
|
|
|
|
|
|
|
|
dut = tXXDController(txxd)
|
|
|
|
run_simulation(dut, [generator(dut)])
|
|
|
|
self.assertEqual(dut.errors, 0)
|
|
|
|
|
|
|
|
def test_txxd_controller(self):
|
|
|
|
txxd = 1
|
2020-05-20 17:40:01 -04:00
|
|
|
valids = "__-______"
|
|
|
|
readys = "_--------"
|
2019-07-23 09:48:32 -04:00
|
|
|
self.txxd_controller_test(txxd, valids, readys)
|
|
|
|
|
|
|
|
txxd = 2
|
2020-05-20 17:40:01 -04:00
|
|
|
valids = "__-______"
|
|
|
|
readys = "_--_-----"
|
2019-07-23 09:48:32 -04:00
|
|
|
self.txxd_controller_test(txxd, valids, readys)
|
|
|
|
|
|
|
|
txxd = 3
|
2020-05-20 17:40:01 -04:00
|
|
|
valids = "____-______"
|
|
|
|
readys = "___--__----"
|
2019-07-23 09:48:32 -04:00
|
|
|
self.txxd_controller_test(txxd, valids, readys)
|
|
|
|
|
|
|
|
txxd = 4
|
2020-05-20 17:40:01 -04:00
|
|
|
valids = "____-______"
|
|
|
|
readys = "___--___---"
|
2019-07-23 09:48:32 -04:00
|
|
|
self.txxd_controller_test(txxd, valids, readys)
|
|
|
|
|
|
|
|
def txxd_controller_random_test(self, txxd, loops):
|
2019-07-23 06:39:43 -04:00
|
|
|
def generator(dut, valid_rand):
|
|
|
|
prng = random.Random(42)
|
|
|
|
for l in range(loops):
|
|
|
|
while prng.randrange(100) < valid_rand:
|
|
|
|
yield
|
|
|
|
yield dut.valid.eq(1)
|
|
|
|
yield
|
|
|
|
yield dut.valid.eq(0)
|
|
|
|
|
|
|
|
@passive
|
|
|
|
def checker(dut):
|
|
|
|
dut.ready_gaps = []
|
|
|
|
while True:
|
|
|
|
while (yield dut.ready) != 0:
|
|
|
|
yield
|
|
|
|
ready_gap = 1
|
|
|
|
while (yield dut.ready) != 1:
|
|
|
|
ready_gap += 1
|
|
|
|
yield
|
|
|
|
dut.ready_gaps.append(ready_gap)
|
|
|
|
|
|
|
|
dut = tXXDController(txxd)
|
|
|
|
run_simulation(dut, [generator(dut, valid_rand=90), checker(dut)])
|
|
|
|
self.assertEqual(min(dut.ready_gaps), txxd)
|
|
|
|
|
2019-07-23 09:48:32 -04:00
|
|
|
def test_txxd_controller_random(self):
|
2020-03-25 07:32:36 -04:00
|
|
|
for txxd in range(2, 32):
|
|
|
|
with self.subTest(txxd=txxd):
|
|
|
|
self.txxd_controller_random_test(txxd, 512)
|
2019-07-23 09:58:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
def tfaw_controller_test(self, txxd, valids, readys):
|
|
|
|
def generator(dut):
|
|
|
|
dut.errors = 0
|
|
|
|
for valid, ready in zip(valids, readys):
|
|
|
|
yield dut.valid.eq(c2bool(valid))
|
|
|
|
yield
|
|
|
|
if (yield dut.ready) != c2bool(ready):
|
|
|
|
dut.errors += 1
|
|
|
|
|
|
|
|
dut = tFAWController(txxd)
|
|
|
|
run_simulation(dut, [generator(dut)])
|
|
|
|
self.assertEqual(dut.errors, 0)
|
|
|
|
|
|
|
|
def test_tfaw_controller(self):
|
|
|
|
tfaw = 8
|
|
|
|
valids = "_----___________"
|
|
|
|
readys = "-----______-----"
|
2020-03-25 07:32:36 -04:00
|
|
|
with self.subTest(tfaw=tfaw, valids=valids, readys=readys):
|
|
|
|
self.tfaw_controller_test(tfaw, valids, readys)
|
2019-07-23 09:58:26 -04:00
|
|
|
|
|
|
|
tfaw = 8
|
|
|
|
valids = "_-_-_-_-________"
|
|
|
|
readys = "--------___-----"
|
2020-03-25 07:32:36 -04:00
|
|
|
with self.subTest(tfaw=tfaw, valids=valids, readys=readys):
|
|
|
|
self.tfaw_controller_test(tfaw, valids, readys)
|
2019-07-23 09:58:26 -04:00
|
|
|
|
|
|
|
tfaw = 8
|
|
|
|
valids = "_-_-___-_-______"
|
|
|
|
readys = "----------_-----"
|
2020-03-25 07:32:36 -04:00
|
|
|
with self.subTest(tfaw=tfaw, valids=valids, readys=readys):
|
|
|
|
self.tfaw_controller_test(tfaw, valids, readys)
|
2019-07-23 09:58:26 -04:00
|
|
|
|
|
|
|
tfaw = 8
|
|
|
|
valids = "_-_-____-_-______"
|
|
|
|
readys = "-----------------"
|
2020-03-25 07:32:36 -04:00
|
|
|
with self.subTest(tfaw=tfaw, valids=valids, readys=readys):
|
|
|
|
self.tfaw_controller_test(tfaw, valids, readys)
|