Skip to content

Commit 2f11dc9

Browse files
util_axis_fifo: Initial testbench commit
Signed-off-by: Istvan-Zsolt Szekely <istvan.szekely@analog.com>
1 parent 98691b5 commit 2f11dc9

File tree

9 files changed

+607
-0
lines changed

9 files changed

+607
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
####################################################################################
2+
####################################################################################
3+
## Copyright 2022(c) Analog Devices, Inc.
4+
####################################################################################
5+
####################################################################################
6+
7+
# Makeincludes
8+
include ../../../scripts/make_tb_path.mk
9+
include $(TB_LIBRARY_PATH)/includes/Makeinclude_common.mk
10+
include $(TB_LIBRARY_PATH)/includes/Makeinclude_axis.mk
11+
include $(TB_LIBRARY_PATH)/includes/Makeinclude_scoreboard.mk
12+
13+
# Remaining test-bench dependencies except test programs
14+
SV_DEPS += environment.sv
15+
16+
LIB_DEPS := util_cdc
17+
LIB_DEPS += util_axis_fifo
18+
19+
# default test program
20+
TP := test_program
21+
22+
# config files should have the following format
23+
# cfg_<param1>_<param2>.tcl
24+
CFG_FILES := $(notdir $(wildcard cfgs/cfg*.tcl))
25+
#$(warning $(CFG_FILES))
26+
27+
# List of tests and configuration combinations that has to be run
28+
# Format is: <configuration>:<test name>
29+
TESTS := $(foreach cfg, $(basename $(CFG_FILES)), $(cfg):$(TP))
30+
31+
include ../../../scripts/project-sim.mk
32+
33+
# usage :
34+
#
35+
# run specific test on a specific configuration in gui mode
36+
# make CFG=cfg2_fsync TST=test_frame_delay MODE=gui
37+
#
38+
# run all test from a configuration
39+
# make cfg1_mm2mm_default
40+
41+
####################################################################################
42+
####################################################################################
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Usage :
2+
3+
Run all tests in batch mode:
4+
5+
make
6+
7+
8+
Run all tests in GUI mode:
9+
10+
make MODE=gui
11+
12+
13+
Run specific test on a specific configuration in gui mode:
14+
15+
make CFG=<name of cfg> TST=<name of test> MODE=gui
16+
17+
18+
Run all test from a configuration:
19+
20+
make <name of cfg>
21+
22+
23+
Where:
24+
25+
* <name of cfg> is a file from the cfgs directory without the tcl extension of format cfg\*
26+
* <name of test> is a file from the tests directory without the tcl extension
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
global ad_project_params
2+
3+
set async_clk [expr int(rand()*2)]
4+
set ad_project_params(ASYNC_CLK) $async_clk
5+
6+
set tkeep_en [expr int(rand()*2)]
7+
set ad_project_params(TKEEP_EN) $tkeep_en
8+
9+
set tlast_en [expr int(rand()*2)]
10+
set ad_project_params(TLAST_EN) $tlast_en
11+
12+
set random_width [expr int(8*pow(2, int(7.0*rand()+1)))]
13+
set DATA_WIDTH $random_width
14+
set ad_project_params(DATA_WIDTH) $DATA_WIDTH
15+
16+
set random_width [expr int(5.0*rand())]
17+
set ad_project_params(ADDRESS_WIDTH) $random_width
18+
19+
set input_clk [expr int(rand()*9)+1]
20+
set ad_project_params(INPUT_CLK) $input_clk
21+
22+
if {$async_clk} {
23+
set output_clk [expr int(rand()*9)+1]
24+
set ad_project_params(OUTPUT_CLK) $output_clk
25+
} else {
26+
set ad_project_params(OUTPUT_CLK) $input_clk
27+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
`include "utils.svh"
2+
`include "axis_definitions.svh"
3+
4+
package environment_pkg;
5+
6+
import logger_pkg::*;
7+
import adi_common_pkg::*;
8+
import axi4stream_vip_pkg::*;
9+
import m_axis_sequencer_pkg::*;
10+
import s_axis_sequencer_pkg::*;
11+
import adi_axis_agent_pkg::*;
12+
import scoreboard_pkg::*;
13+
14+
class util_axis_fifo_environment #(`AXIS_VIP_PARAM_DECL(input_axis), `AXIS_VIP_PARAM_DECL(output_axis), int INPUT_CLK, int OUTPUT_CLK) extends adi_environment;
15+
16+
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(INPUT_CLK)) input_clk_vip_if;
17+
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(OUTPUT_CLK)) output_clk_vip_if;
18+
19+
adi_axis_master_agent #(`AXIS_VIP_PARAM_ORDER(input_axis)) input_axis_agent;
20+
adi_axis_slave_agent #(`AXIS_VIP_PARAM_ORDER(output_axis)) output_axis_agent;
21+
22+
scoreboard #(logic [7:0]) scoreboard_inst;
23+
24+
//============================================================================
25+
// Constructor
26+
//============================================================================
27+
function new (
28+
input string name,
29+
30+
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(INPUT_CLK)) input_clk_vip_if,
31+
virtual interface clk_vip_if #(.C_CLK_CLOCK_PERIOD(OUTPUT_CLK)) output_clk_vip_if,
32+
33+
virtual interface axi4stream_vip_if #(`AXIS_VIP_IF_PARAMS(input_axis)) input_axis_vip_if,
34+
virtual interface axi4stream_vip_if #(`AXIS_VIP_IF_PARAMS(output_axis)) output_axis_vip_if);
35+
36+
// creating the agents
37+
super.new(name);
38+
39+
this.input_clk_vip_if = input_clk_vip_if;
40+
this.output_clk_vip_if = output_clk_vip_if;
41+
42+
this.input_axis_agent = new("Input AXI Stream Agent", input_axis_vip_if, this);
43+
this.output_axis_agent = new("Output AXI Stream Agent", output_axis_vip_if, this);
44+
45+
this.scoreboard_inst = new("Util AXIS FIFO Scoreboard", this);
46+
endfunction
47+
48+
//============================================================================
49+
// Configure environment
50+
//============================================================================
51+
task configure();
52+
// configuration for input
53+
this.input_axis_agent.sequencer.set_stop_policy(STOP_POLICY_PACKET);
54+
this.input_axis_agent.sequencer.set_data_gen_mode(DATA_GEN_MODE_AUTO_INCR);
55+
this.input_axis_agent.sequencer.set_descriptor_gen_mode(1);
56+
this.input_axis_agent.sequencer.set_data_beat_delay(0);
57+
this.input_axis_agent.sequencer.set_descriptor_delay(0);
58+
this.input_axis_agent.sequencer.set_inactive_drive_output_0();
59+
60+
// configuration for output
61+
this.output_axis_agent.sequencer.set_mode(XIL_AXI4STREAM_READY_GEN_NO_BACKPRESSURE);
62+
63+
// this.output_axis_agent.sequencer.set_use_variable_ranges();
64+
// this.output_axis_agent.sequencer.set_high_time_range(1,1);
65+
// this.output_axis_agent.sequencer.set_low_time_range(0,0);
66+
67+
// this.output_axis_agent.sequencer.clr_use_variable_ranges();
68+
// this.output_axis_agent.sequencer.set_high_time(1);
69+
// this.output_axis_agent.sequencer.set_low_time(1);
70+
endtask
71+
72+
//============================================================================
73+
// Start environment
74+
// - Connect all the agents to the scoreboard
75+
// - Start the agents
76+
//============================================================================
77+
task start();
78+
this.input_clk_vip_if.start_clock();
79+
this.output_clk_vip_if.start_clock();
80+
81+
this.input_axis_agent.start();
82+
this.output_axis_agent.start();
83+
84+
this.input_axis_agent.monitor.publisher.subscribe(this.scoreboard_inst.subscriber_source);
85+
this.output_axis_agent.monitor.publisher.subscribe(this.scoreboard_inst.subscriber_sink);
86+
endtask
87+
88+
//============================================================================
89+
// Run subroutine
90+
//============================================================================
91+
task run();
92+
fork
93+
this.input_axis_agent.run();
94+
this.output_axis_agent.run();
95+
96+
this.scoreboard_inst.run();
97+
join_none
98+
endtask
99+
100+
//============================================================================
101+
// Stop subroutine
102+
//============================================================================
103+
task stop();
104+
this.input_axis_agent.stop();
105+
this.output_axis_agent.stop();
106+
endtask
107+
108+
endclass
109+
110+
endpackage
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# ***************************************************************************
2+
# ***************************************************************************
3+
# Copyright 2022 (c) Analog Devices, Inc. All rights reserved.
4+
#
5+
# In this HDL repository, there are many different and unique modules, consisting
6+
# of various HDL (Verilog or VHDL) components. The individual modules are
7+
# developed independently, and may be accompanied by separate and unique license
8+
# terms.
9+
#
10+
# The user should read each of these license terms, and understand the
11+
# freedoms and responsibilities that he or she has by using this source/core.
12+
#
13+
# This core is distributed in the hope that it will be useful, but WITHOUT ANY
14+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15+
# A PARTICULAR PURPOSE.
16+
#
17+
# Redistribution and use of source or resulting binaries, with or without modification
18+
# of this file, are permitted under one of the following two license terms:
19+
#
20+
# 1. The GNU General Public License version 2 as published by the
21+
# Free Software Foundation, which can be found in the top level directory
22+
# of this repository (LICENSE_GPL2), and also online at:
23+
# <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
24+
#
25+
# OR
26+
#
27+
# 2. An ADI specific BSD license, which can be found in the top level directory
28+
# of this repository (LICENSE_ADIBSD), and also on-line at:
29+
# https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
30+
# This will allow to generate bit files and not release the source code,
31+
# as long as it attaches to an ADI device.
32+
#
33+
# ***************************************************************************
34+
# ***************************************************************************
35+
36+
global ad_project_params
37+
38+
set ASYNC_CLK $ad_project_params(ASYNC_CLK)
39+
set TKEEP_EN $ad_project_params(TKEEP_EN)
40+
set TLAST_EN $ad_project_params(TLAST_EN)
41+
set DATA_WIDTH $ad_project_params(DATA_WIDTH)
42+
set ADDRESS_WIDTH $ad_project_params(ADDRESS_WIDTH)
43+
set INPUT_CLK $ad_project_params(INPUT_CLK)
44+
set OUTPUT_CLK $ad_project_params(OUTPUT_CLK)
45+
46+
# Input clock
47+
ad_ip_instance clk_vip input_clk_vip [ list \
48+
INTERFACE_MODE {MASTER} \
49+
FREQ_HZ [expr pow(10, 9)/$INPUT_CLK] \
50+
]
51+
adi_sim_add_define "INPUT_CLK_VIP=input_clk_vip"
52+
53+
ad_ip_instance clk_vip output_clk_vip [ list \
54+
INTERFACE_MODE {MASTER} \
55+
FREQ_HZ [expr pow(10, 9)/$OUTPUT_CLK] \
56+
]
57+
adi_sim_add_define "OUTPUT_CLK_VIP=output_clk_vip"
58+
59+
ad_connect input_clk input_clk_vip/clk_out
60+
ad_connect output_clk output_clk_vip/clk_out
61+
62+
ad_ip_instance proc_sys_reset input_rstgen
63+
ad_ip_parameter input_rstgen CONFIG.C_EXT_RST_WIDTH 1
64+
65+
ad_ip_instance proc_sys_reset output_rstgen
66+
ad_ip_parameter output_rstgen CONFIG.C_EXT_RST_WIDTH 1
67+
68+
ad_connect sys_rst_vip/rst_out input_rstgen/ext_reset_in
69+
ad_connect sys_rst_vip/rst_out output_rstgen/ext_reset_in
70+
71+
ad_connect input_clk input_rstgen/slowest_sync_clk
72+
ad_connect output_clk output_rstgen/slowest_sync_clk
73+
74+
ad_connect input_resetn input_rstgen/peripheral_aresetn
75+
ad_connect output_resetn output_rstgen/peripheral_aresetn
76+
77+
ad_ip_instance util_axis_fifo util_axis_fifo_DUT [list \
78+
ASYNC_CLK $ASYNC_CLK \
79+
DATA_WIDTH $DATA_WIDTH \
80+
ADDRESS_WIDTH $ADDRESS_WIDTH \
81+
M_AXIS_REGISTERED 1 \
82+
ALMOST_EMPTY_THRESHOLD 0 \
83+
ALMOST_FULL_THRESHOLD 0 \
84+
TLAST_EN $TLAST_EN \
85+
TKEEP_EN $TKEEP_EN \
86+
REMOVE_NULL_BEAT_EN 0 \
87+
]
88+
89+
ad_connect input_clk util_axis_fifo_DUT/s_axis_aclk
90+
ad_connect input_resetn util_axis_fifo_DUT/s_axis_aresetn
91+
92+
ad_connect output_clk util_axis_fifo_DUT/m_axis_aclk
93+
ad_connect output_resetn util_axis_fifo_DUT/m_axis_aresetn
94+
95+
ad_ip_instance axi4stream_vip input_axis [list \
96+
INTERFACE_MODE {MASTER} \
97+
HAS_TREADY {1} \
98+
TDEST_WIDTH {0} \
99+
TID_WIDTH {0} \
100+
HAS_TLAST $TLAST_EN \
101+
HAS_TKEEP $TKEEP_EN \
102+
TDATA_NUM_BYTES [expr {$DATA_WIDTH/8}] \
103+
]
104+
adi_sim_add_define "INPUT_AXIS=input_axis"
105+
106+
ad_connect input_clk input_axis/aclk
107+
ad_connect input_resetn input_axis/aresetn
108+
109+
ad_connect util_axis_fifo_DUT/s_axis input_axis/m_axis
110+
111+
ad_ip_instance axi4stream_vip output_axis [list \
112+
INTERFACE_MODE {SLAVE} \
113+
HAS_TLAST $TLAST_EN \
114+
HAS_TKEEP $TKEEP_EN \
115+
TDATA_NUM_BYTES [expr {$DATA_WIDTH/8}] \
116+
]
117+
adi_sim_add_define "OUTPUT_AXIS=output_axis"
118+
119+
ad_connect output_clk output_axis/aclk
120+
ad_connect output_resetn output_axis/aresetn
121+
122+
ad_connect util_axis_fifo_DUT/m_axis output_axis/s_axis
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
source ../../../scripts/adi_sim.tcl
2+
3+
if {$argc < 1} {
4+
puts "Expecting at least one argument that specifies the test configuration"
5+
exit 1
6+
} else {
7+
set cfg_file [lindex $argv 0]
8+
}
9+
10+
# Read config file
11+
source "cfgs/${cfg_file}"
12+
13+
# Set the project name
14+
set project_name [file rootname $cfg_file]
15+
16+
# Create the project
17+
adi_sim_project_xilinx $project_name "xcvu9p-flga2104-2L-e"
18+
19+
source $ad_tb_dir/library/includes/sp_include_axis.tcl
20+
source $ad_tb_dir/library/includes/sp_include_scoreboard.tcl
21+
22+
# Add test files to the project
23+
adi_sim_project_files [list \
24+
"environment.sv" \
25+
"tests/test_program.sv" \
26+
]
27+
28+
#set a default test program
29+
adi_sim_add_define "TEST_PROGRAM=test_program"
30+
31+
adi_sim_generate $project_name

0 commit comments

Comments
 (0)