pmd: Export check_bits from testbench

I forgot to export this function when reusing it.

Fixes: 2eac757 ("Add DP83223-based PMD")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
This commit is contained in:
Sean Anderson 2023-01-09 20:38:52 -05:00
parent 5b3c350581
commit 3902e8f77a
1 changed files with 32 additions and 29 deletions

View File

@ -26,6 +26,36 @@ def mindelays(count):
def maxdelays(count): def maxdelays(count):
return (8100,) * count return (8100,) * count
async def check_bits(pmd, ins):
# Wait for things to stabilize
await RisingEdge(pmd.signal_status)
outs = []
while pmd.signal_status.value:
await RisingEdge(pmd.clk_125)
valid = pmd.rx_data_valid.value
if valid == 0:
pass
elif valid == 1:
outs.append(pmd.rx_data[1].value)
else:
outs.append(pmd.rx_data[1].value)
outs.append(pmd.rx_data[0].value)
best_corr = -1
best_off = None
for off in range(16):
corr = sum(i == o for i, o in zip(ins[off:], outs))
if corr > best_corr:
best_corr = corr
best_off = off
print(f"best offset is {best_off} correlation {best_corr/(len(ins) - best_off)}")
compare_lists(ins[best_off:], outs)
# There will be a few bits at the end not recorded because signal_detect
# isn't delayed like the data signals
print(best_corr, len(ins), best_off)
assert best_corr > len(ins) - best_off - 10
@timeout(100, 'us') @timeout(100, 'us')
async def test_rx(pmd, delays): async def test_rx(pmd, delays):
pmd.signal_detect.value = 0 pmd.signal_detect.value = 0
@ -63,36 +93,9 @@ async def test_rx(pmd, delays):
pass pass
await Timer(delay, units='ps') await Timer(delay, units='ps')
pmd.signal_detect.value = 0 pmd.signal_detect.value = 0
await cocotb.start(generate_bits()) await cocotb.start(generate_bits())
await check_bits(pmd, ins)
# Wait for things to stabilize
await RisingEdge(pmd.signal_status)
outs = []
while pmd.signal_status.value:
await RisingEdge(pmd.clk_125)
valid = pmd.rx_data_valid.value
if valid == 0:
pass
elif valid == 1:
outs.append(pmd.rx_data[1].value)
else:
outs.append(pmd.rx_data[1].value)
outs.append(pmd.rx_data[0].value)
best_corr = -1
best_off = None
for off in range(16):
corr = sum(i == o for i, o in zip(ins[off:], outs))
if corr > best_corr:
best_corr = corr
best_off = off
print(f"best offset is {best_off} correlation {best_corr/(len(ins) - best_off)}")
compare_lists(ins[best_off:], outs)
# There will be a few bits at the end not recorded because signal_detect
# isn't delayed like the data signals
print(best_corr, len(ins), best_off)
assert best_corr > len(ins) - best_off - 10
rx_tests = TestFactory(test_rx) rx_tests = TestFactory(test_rx)
rx_tests.add_option('delays', (random_delays, mindelays, maxdelays)) rx_tests.add_option('delays', (random_delays, mindelays, maxdelays))