-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'kondys_feat_cocotb_mvb_transactions' into 'devel'
Cocotb - MVB: implementation of MVB transactions and their usage in drivers and monitors + a new rate limiter (for items) See merge request ndk/ndk-fpga!77
- Loading branch information
Showing
11 changed files
with
445 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# cocotb_test.py: | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Ondřej Schwarz <[email protected]> | ||
# Daniel Kondys <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
|
@@ -11,18 +12,20 @@ | |
from cocotb.triggers import RisingEdge, ClockCycles | ||
from cocotbext.ofm.mvb.drivers import MVBDriver | ||
from cocotbext.ofm.mvb.monitors import MVBMonitor | ||
from cocotbext.ofm.ver.generators import random_packets | ||
from cocotbext.ofm.ver.generators import random_integers | ||
from cocotb_bus.drivers import BitDriver | ||
from cocotb_bus.scoreboard import Scoreboard | ||
from cocotbext.ofm.utils.throughput_probe import ThroughputProbe, ThroughputProbeMvbInterface | ||
from cocotbext.ofm.base.generators import ItemRateLimiter | ||
from cocotbext.ofm.mvb.transaction import MvbTrClassic | ||
|
||
|
||
class testbench(): | ||
def __init__(self, dut, debug=False): | ||
self.dut = dut | ||
self.stream_in = MVBDriver(dut, "RX", dut.CLK) | ||
self.backpressure = BitDriver(dut.TX_DST_RDY, dut.CLK) | ||
self.stream_out = MVBMonitor(dut, "TX", dut.CLK) | ||
self.stream_out = MVBMonitor(dut, "TX", dut.CLK, tr_type=MvbTrClassic) | ||
|
||
self.throughput_probe = ThroughputProbe(ThroughputProbeMvbInterface(self.stream_out), throughput_units="items") | ||
self.throughput_probe.set_log_period(10) | ||
|
@@ -51,17 +54,25 @@ async def reset(self): | |
|
||
|
||
@cocotb.test() | ||
async def run_test(dut, pkt_count=10000, item_width=1): | ||
async def run_test(dut, pkt_count=10000): | ||
# Start clock generator | ||
cocotb.start_soon(Clock(dut.CLK, 5, units="ns").start()) | ||
tb = testbench(dut, debug=False) | ||
# Change MVB drivers IdleGenerator to ItemRateLimiter | ||
# Note: the RateLimiter's rate is affected by backpressure (DST_RDY). | ||
# Eventhough it takes into account cycles with DST_RDY=0, the desired rate might not be achievable. | ||
idle_gen_conf = dict(random_idles=True, max_idles=5, zero_idles_chance=50) | ||
tb.stream_in.set_idle_generator(ItemRateLimiter(rate_percentage=30, **idle_gen_conf)) | ||
await tb.reset() | ||
tb.backpressure.start((1, i % 5) for i in itertools.count()) | ||
|
||
for transaction in random_packets(item_width, item_width, pkt_count): | ||
tb.model(transaction) | ||
cocotb.log.debug(f"generated transaction: {transaction.hex()}") | ||
tb.stream_in.append(transaction) | ||
data_width = tb.stream_in.item_widths["data"] | ||
for transaction in random_integers(0, 2**data_width-1, pkt_count): | ||
cocotb.log.debug(f"generated transaction: {hex(transaction)}") | ||
mvb_tr = MvbTrClassic | ||
mvb_tr.data = transaction | ||
tb.model(mvb_tr) | ||
tb.stream_in.append(mvb_tr) | ||
|
||
last_num = 0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
ROOT_PATH=../../../../.. | ||
|
||
PKG_COCOTBEXT_OFM=$ROOT_PATH/python/cocotbext/ | ||
|
||
# Python virtual environment | ||
python -m venv venv-fifox | ||
source venv-fifox/bin/activate | ||
|
||
python -m pip install setuptools | ||
python -m pip install $PKG_COCOTBEXT_OFM | ||
|
||
echo "" | ||
echo "Now activate environment with:" | ||
echo "source venv-fifox/bin/activate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.