-
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_mfb_mvb_appeder' into 'devel'
MFB MVB Appender component See merge request ndk/ndk-fpga!101
- Loading branch information
Showing
9 changed files
with
819 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Modules.tcl: Components include script | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Daniel Kondys <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
# Paths to components | ||
set FIFOXM_BASE "$OFM_PATH/comp/base/fifo/fifox_multi" | ||
set MFB_BASE "$OFM_PATH/comp/mfb_tools" | ||
set LOGIC_BASE "$OFM_PATH/comp/base/logic" | ||
|
||
# Packages | ||
lappend PACKAGES "$OFM_PATH/comp/base/pkg/math_pack.vhd" | ||
lappend PACKAGES "$OFM_PATH/comp/base/pkg/type_pack.vhd" | ||
|
||
# Components | ||
lappend COMPONENTS [ list "FIFOX_MULTI" $FIFOXM_BASE "FULL" ] | ||
lappend COMPONENTS [ list "MFB_FIFOX" "$MFB_BASE/storage/fifox" "FULL" ] | ||
lappend COMPONENTS [ list "MFB_RECONF" "$MFB_BASE/flow/reconfigurator" "FULL" ] | ||
lappend COMPONENTS [ list "OFFSET_REACHED" "$MFB_BASE/logic/offset_reached" "FULL" ] | ||
lappend COMPONENTS [ list "FIRST_ONE" "$LOGIC_BASE/first_one" "FULL" ] | ||
lappend COMPONENTS [ list "ONES_INSERTOR" "$LOGIC_BASE/ones_insertor" "FULL" ] | ||
lappend COMPONENTS [ list "BARREL_SHIFTER" "$LOGIC_BASE/barrel_shifter" "FULL" ] | ||
|
||
# Source files for implemented component | ||
lappend MOD "$ENTITY_BASE/mfb_mvb_appender.vhd" | ||
|
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,13 @@ | ||
# Makefile: Makefile to compile module | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Daniel Kondys <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
TOP_LEVEL_ENT=MFB_MVB_APPENDER | ||
TARGET=cocotb | ||
|
||
.PHONY: all | ||
all: comp | ||
|
||
include ../../../../../build/Makefile |
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,93 @@ | ||
# cocotb_test.py: | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Daniel Kondys <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import itertools | ||
import sys | ||
from random import randint | ||
|
||
import cocotb | ||
from cocotb.clock import Clock | ||
from cocotb.triggers import RisingEdge, ClockCycles | ||
from cocotb_bus.drivers import BitDriver | ||
from cocotb_bus.scoreboard import Scoreboard | ||
|
||
from cocotbext.ofm.mfb.drivers import MFBDriver | ||
from cocotbext.ofm.mfb.monitors import MFBMonitor | ||
from cocotbext.ofm.mvb.drivers import MVBDriver, MvbTrClassic | ||
from cocotbext.ofm.base.generators import ItemRateLimiter | ||
from cocotbext.ofm.ver.generators import random_packets | ||
|
||
|
||
class testbench(): | ||
def __init__(self, dut, debug=False): | ||
self.dut = dut | ||
self.mfb_rx_drv = MFBDriver(dut, "RX_MFB", dut.CLK) | ||
self.mfb_tx_drv = BitDriver(dut.TX_MFB_DST_RDY, dut.CLK) | ||
self.mvb_rx_drv = MVBDriver(dut, "RX_MVB", dut.CLK) | ||
self.mfb_tx_mon = MFBMonitor(dut, "TX_MFB", dut.CLK) | ||
|
||
self.pkts_sent = 0 | ||
self.expected_output = [] | ||
self.scoreboard = Scoreboard(dut) | ||
self.scoreboard.add_interface(self.mfb_tx_mon, self.expected_output) | ||
|
||
if debug: | ||
self.mfb_rx_drv.log.setLevel(cocotb.logging.DEBUG) | ||
self.mvb_rx_drv.log.setLevel(cocotb.logging.DEBUG) | ||
self.mfb_tx_mon.log.setLevel(cocotb.logging.DEBUG) | ||
|
||
def model(self, append_tr: bytes, packet_tr: bytes): | ||
"""Model of the DUT""" | ||
appended_tr = packet_tr + append_tr | ||
self.expected_output.append(appended_tr) | ||
self.pkts_sent += 1 | ||
|
||
async def reset(self): | ||
self.dut.RESET.value = 1 | ||
await ClockCycles(self.dut.CLK, 10) | ||
self.dut.RESET.value = 0 | ||
await RisingEdge(self.dut.CLK) | ||
|
||
|
||
@cocotb.test() | ||
async def run_test(dut, pkt_count=10000, frame_size_min=60, frame_size_max=1500): | ||
dut.RESET.value = 1 | ||
cocotb.start_soon(Clock(dut.CLK, 5, units='ns').start()) | ||
|
||
tb = testbench(dut) | ||
# Change MVB driver's IdleGenerator to ItemRateLimiter | ||
idle_gen_conf = dict(random_idles=True, max_idles=5, zero_idles_chance=50) | ||
tb.mvb_rx_drv.set_idle_generator(ItemRateLimiter(rate_percentage=30, **idle_gen_conf)) | ||
await tb.reset() | ||
|
||
cocotb.log.info("\n--- Beginning the test ---\n") | ||
|
||
tb.mfb_tx_drv.start((1, i % 3) for i in itertools.count()) | ||
# Option to change MVB drivers Rate Limiter (0 = random Idles = inconsistent rate) | ||
tb.mvb_rx_drv.set_idle_generator(ItemRateLimiter(rate_percentage=0)) | ||
|
||
await ClockCycles(tb.dut.CLK, 10) | ||
|
||
for mfb_pkt in random_packets(frame_size_min, frame_size_max, pkt_count): | ||
tb.mfb_rx_drv.append(mfb_pkt) | ||
|
||
mvb_tr = MvbTrClassic() | ||
mvb_bus_width = tb.mvb_rx_drv.item_widths['data'] | ||
mvb_append = randint(0, 2**mvb_bus_width-1) | ||
mvb_tr.data = mvb_append | ||
tb.mvb_rx_drv.append(mvb_tr) | ||
|
||
tb.model(append_tr=(mvb_append.to_bytes(mvb_bus_width//8, sys.byteorder)), packet_tr=(mfb_pkt)) | ||
|
||
last_num = 0 | ||
while (tb.mfb_tx_mon.frame_cnt < pkt_count): | ||
if (this_num := tb.mfb_tx_mon.frame_cnt // (pkt_count // 10)) > last_num: | ||
last_num = this_num | ||
cocotb.log.info(f"Number of transactions processed: {tb.mfb_tx_mon.frame_cnt}/{pkt_count}") | ||
await ClockCycles(dut.CLK, 100) | ||
|
||
cocotb.log.info("\n--- Test complete, getting results ---\n") | ||
raise tb.scoreboard.result |
13 changes: 13 additions & 0 deletions
13
comp/mfb_tools/edit/frame_appender/cocotb/cocotb_test_sig.fdo
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,13 @@ | ||
# coctb_test_sig.fdo : Include file with signals | ||
# Copyright (C) 2024 CESNET z. s. p. o. | ||
# Author(s): Daniel Kondys <[email protected]> | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
view wave | ||
delete wave * | ||
|
||
add_wave -group {Appender} -noupdate -hex /mfb_mvb_appender/* | ||
|
||
|
||
config wave -signalnamewidth 1 |
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=$ROOT_PATH/python/cocotbext/ | ||
|
||
# Python virtual environment | ||
python -m venv venv-appender | ||
source venv-appender/bin/activate | ||
|
||
python -m pip install setuptools | ||
python -m pip install $PKG_COCOTBEXT | ||
|
||
echo "" | ||
echo "Now activate environment with:" | ||
echo "source venv-appender/bin/activate" |
Oops, something went wrong.