Skip to content

Commit 934daab

Browse files
author
1138-4EB
committed
use integer_array_t instead of array_t
1 parent 2cd6b4e commit 934daab

4 files changed

Lines changed: 110 additions & 91 deletions

File tree

examples/vhdl/array/run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
Array
99
-----
1010
11-
Demonstrates the ``array_t`` data type of ``array_pkg.vhd`` which
12-
can be used to handle dynamically sized 1D, 2D and 3D data as well
13-
as storing and loading it from csv and raw files.
11+
Demonstrates the ``integer_array_t`` data type, which can be used to
12+
handle dynamically sized 1D, 2D and 3D data as well as storing and
13+
loading it from csv and raw files.
1414
"""
1515

1616
from os.path import join, dirname
@@ -20,12 +20,14 @@
2020

2121
vu = VUnit.from_argv()
2222
vu.add_osvvm()
23-
vu.add_array_util()
2423

2524
src_path = join(dirname(__file__), "src")
2625

2726
vu.add_library("lib").add_source_files(
2827
[join(src_path, "*.vhd"), join(src_path, "test", "*.vhd")]
2928
)
3029

30+
vu.set_compile_option("ghdl.flags", ["-frelaxed"])
31+
vu.set_sim_option("ghdl.elab_flags", ["-frelaxed"])
32+
3133
vu.main()

examples/vhdl/array/src/test/tb_sobel_x.vhd

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,76 @@ use ieee.numeric_std.all;
1010

1111
library vunit_lib;
1212
context vunit_lib.vunit_context;
13-
use vunit_lib.array_pkg.all;
14-
1513

1614
library osvvm;
17-
use osvvm.RandomPkg.all;
15+
use osvvm.RandomPkg.RandomPType;
1816

1917
entity tb_sobel_x is
2018
generic (
2119
runner_cfg : string;
22-
tb_path : string);
20+
tb_path : string
21+
);
2322
end entity;
2423

2524
architecture tb of tb_sobel_x is
26-
signal clk : std_logic := '0';
27-
signal input_tvalid : std_logic := '0';
28-
signal input_tlast : std_logic := '0';
29-
signal input_tdata : unsigned(14-1 downto 0) := (others => '0');
25+
26+
signal clk : std_logic := '0';
27+
signal input_tvalid : std_logic := '0';
28+
signal input_tlast : std_logic := '0';
29+
signal input_tdata : unsigned(13 downto 0) := (others => '0');
3030
signal output_tvalid : std_logic;
31-
signal output_tlast : std_logic;
32-
signal output_tdata : signed(input_tdata'length downto 0);
31+
signal output_tlast : std_logic;
32+
signal output_tdata : signed(input_tdata'length downto 0);
3333

34-
shared variable image : array_t;
35-
shared variable reference_image : array_t;
34+
shared variable image, ref_image : integer_array_t;
3635
signal start, data_check_done, stimuli_done : boolean := false;
36+
3737
begin
3838

3939
main : process
40-
procedure sobel_x(variable image : inout array_t;
41-
variable result : inout array_t) is
40+
impure function sobel_x (
41+
constant image : integer_array_t
42+
) return integer_array_t is
43+
variable result: integer_array_t := new_2d(
44+
width => width(image),
45+
height => height(image),
46+
bit_width => bit_width(image)+1,
47+
is_signed => true
48+
);
4249
begin
43-
result.init_2d(width => image.width,
44-
height => image.height,
45-
bit_width => image.bit_width+1,
46-
is_signed => true);
47-
48-
for y in 0 to image.height-1 loop
49-
for x in 0 to image.width-1 loop
50-
result.set(x => x, y => y,
51-
value => (image.get(minimum(x+1, image.width-1),y) -
52-
image.get(maximum(x-1, 0), y)));
50+
for y in 0 to height(image)-1 loop
51+
for x in 0 to width(image)-1 loop
52+
set(
53+
result,
54+
x => x,
55+
y => y,
56+
value => (
57+
get(image, minimum(x+1, width(image)-1),y)
58+
- get(image, maximum(x-1, 0), y)
59+
)
60+
);
5361
end loop;
5462
end loop;
55-
56-
end procedure;
63+
return result;
64+
end;
5765

5866
variable rnd : RandomPType;
5967

60-
procedure randomize(variable arr : inout array_t) is
68+
impure function randomize (
69+
constant width, height, bit_width: natural
70+
) return integer_array_t is
71+
variable image: integer_array_t := new_2d(
72+
width => width,
73+
height => height,
74+
bit_width => bit_width,
75+
is_signed => false
76+
);
6177
begin
62-
for idx in 0 to arr.length-1 loop
63-
arr.set(idx, value => rnd.RandInt(arr.lower_limit, arr.upper_limit));
78+
for idx in 0 to length(image)-1 loop
79+
set(image, idx, value => rnd.RandInt(lower_limit(image), upper_limit(image)));
6480
end loop;
65-
end procedure;
81+
return image;
82+
end;
6683

6784
procedure run_test is
6885
begin
@@ -71,18 +88,17 @@ begin
7188
wait until rising_edge(clk);
7289
start <= false;
7390

74-
wait until (stimuli_done and
75-
data_check_done and
76-
rising_edge(clk));
91+
wait until (
92+
stimuli_done and
93+
data_check_done and
94+
rising_edge(clk)
95+
);
7796
end procedure;
7897

7998
procedure test_random_image(width, height : natural) is
8099
begin
81-
image.init_2d(width => width, height => height,
82-
bit_width => input_tdata'length,
83-
is_signed => false);
84-
randomize(image);
85-
sobel_x(image, result => reference_image);
100+
image := randomize(width, height, input_tdata'length);
101+
ref_image := sobel_x(image);
86102
run_test;
87103
end procedure;
88104

@@ -96,8 +112,8 @@ begin
96112
test_random_image(16, 1);
97113
test_random_image(1, 1);
98114
elsif run("test_input_file_against_output_file") then
99-
image.load_csv(tb_path & "input.csv");
100-
reference_image.load_csv(tb_path & "output.csv");
115+
image := load_csv(tb_path & "input.csv");
116+
ref_image := load_csv(tb_path & "output.csv");
101117
run_test;
102118
end if;
103119
end loop;
@@ -110,20 +126,22 @@ begin
110126
wait until start and rising_edge(clk);
111127
stimuli_done <= false;
112128

113-
report ("Sending image of size " &
114-
to_string(image.width) & "x" &
115-
to_string(image.height));
129+
report (
130+
"Sending image of size " &
131+
to_string(width(image)) & "x" &
132+
to_string(height(image))
133+
);
116134

117-
for y in 0 to image.height-1 loop
118-
for x in 0 to image.width-1 loop
135+
for y in 0 to height(image)-1 loop
136+
for x in 0 to width(image)-1 loop
119137
wait until rising_edge(clk);
120138
input_tvalid <= '1';
121-
if x = image.width-1 then
139+
if x = width(image)-1 then
122140
input_tlast <= '1';
123141
else
124142
input_tlast <= '0';
125143
end if;
126-
input_tdata <= to_unsigned(image.get(x,y), input_tdata'length);
144+
input_tdata <= to_unsigned(get(image, x, y), input_tdata'length);
127145
end loop;
128146
end loop;
129147

@@ -137,32 +155,36 @@ begin
137155
begin
138156
wait until start and rising_edge(clk);
139157
data_check_done <= false;
140-
for y in 0 to reference_image.height-1 loop
141-
for x in 0 to reference_image.width-1 loop
158+
for y in 0 to height(ref_image)-1 loop
159+
for x in 0 to width(ref_image)-1 loop
142160
wait until output_tvalid = '1' and rising_edge(clk);
143-
check_equal(output_tlast, x = reference_image.width-1);
144-
check_equal(output_tdata, reference_image.get(x, y),
161+
check_equal(output_tlast, x = width(ref_image)-1);
162+
check_equal(output_tdata, get(ref_image, x, y),
145163
"x=" & to_string(x) & " y=" & to_string(y));
146164
end loop;
147165
end loop;
148-
report ("Done checking image of size " &
149-
to_string(reference_image.width) & "x" &
150-
to_string(reference_image.height));
166+
report (
167+
"Done checking image of size " &
168+
to_string(width(ref_image)) & "x" &
169+
to_string(height(ref_image))
170+
);
151171
data_check_done <= true;
152172
end process;
153173

154174
clk <= not clk after 1 ns;
155175

156176
dut : entity work.sobel_x
157177
generic map (
158-
data_width => input_tdata'length)
178+
data_width => input_tdata'length
179+
)
159180
port map (
160181
clk => clk,
161182
input_tvalid => input_tvalid,
162183
input_tlast => input_tlast,
163184
input_tdata => input_tdata,
164185
output_tvalid => output_tvalid,
165186
output_tlast => output_tlast,
166-
output_tdata => output_tdata);
187+
output_tdata => output_tdata
188+
);
167189

168190
end architecture;

examples/vhdl/array_axis_vcs/run.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
Array and AXI4 Stream Verification Components
99
---------------------------------------------
1010
11-
Demonstrates ``array_t``, ``axi_stream_master_t`` and ``axi_stream_slave_t``
12-
data types of ``array_pkg.vhd``, ``stream_master_pkg`` and ``stream_slave_pkg``,
13-
respectively. Also, ``push_axi_stream`` of ``axi_stream_pkg`` is used. A CSV file
14-
is read, the content is sent in a row-major order to an AXI Stream buffer (FIFO)
15-
and it is received back to be saved in a different file. Further information can
11+
Shows how to use ``integer_array_t``, ``axi_stream_master_t`` and ``axi_stream_slave_t``.
12+
A CSV file is read, the content is sent in a row-major order to an AXI Stream buffer
13+
(FIFO) and it is received back to be saved in a different file. Further information can
1614
be found in the :ref:`verification component library user guide <vc_library>`,
1715
in subsection :ref:`Stream <stream_vci>` and in
1816
:vunit_file:`vhdl/verification_components/test/tb_axi_stream.vhd <vunit/vhdl/verification_components/test/tb_axi_stream.vhd>`.
@@ -22,9 +20,6 @@
2220
from vunit import VUnit
2321

2422
vu = VUnit.from_argv()
25-
26-
vu.add_osvvm()
27-
vu.add_array_util()
2823
vu.add_verification_components()
2924

3025
src_path = join(dirname(__file__), "src")

examples/vhdl/array_axis_vcs/src/test/tb_axis_loop.vhd

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ context ieee.ieee_std_context;
1717
library vunit_lib;
1818
context vunit_lib.vunit_context;
1919
context vunit_lib.vc_context;
20-
use vunit_lib.array_pkg.all;
2120

2221
entity tb_axis_loop is
2322
generic (
@@ -32,13 +31,13 @@ architecture tb of tb_axis_loop is
3231

3332
-- Simulation constants
3433

35-
constant clk_period : time := 20 ns;
34+
constant clk_period : time := 20 ns;
3635
constant data_width : natural := 32;
3736

3837
-- AXI4Stream Verification Components
3938

4039
constant master_axi_stream : axi_stream_master_t := new_axi_stream_master(data_length => data_width);
41-
constant slave_axi_stream : axi_stream_slave_t := new_axi_stream_slave(data_length => data_width);
40+
constant slave_axi_stream : axi_stream_slave_t := new_axi_stream_slave(data_length => data_width);
4241

4342
-- Signals to/from the UUT from/to the verification components
4443

@@ -48,7 +47,8 @@ architecture tb of tb_axis_loop is
4847
-- tb signals and variables
4948

5049
signal clk, rst, rstn : std_logic := '0';
51-
shared variable m_I, m_O : array_t;
50+
constant m_I : integer_array_t := load_csv(tb_path & csv_i);
51+
constant m_O : integer_array_t := new_2d(width(m_I), height(m_I), data_width, true);
5252
signal start, done, saved : boolean := false;
5353

5454
begin
@@ -85,15 +85,13 @@ begin
8585
done <= false;
8686
wait until rising_edge(clk);
8787

88-
m_I.load_csv(tb_path & csv_i);
88+
info("Sending m_I of size " & to_string(height(m_I)) & "x" & to_string(width(m_I)) & " to UUT...");
8989

90-
info("Sending m_I of size " & to_string(m_I.height) & "x" & to_string(m_I.width) & " to UUT...");
91-
92-
for y in 0 to m_I.height-1 loop
93-
for x in 0 to m_I.width-1 loop
90+
for y in 0 to height(m_I)-1 loop
91+
for x in 0 to width(m_I)-1 loop
9492
wait until rising_edge(clk);
95-
if x = m_I.width-1 then last := '1'; else last := '0'; end if;
96-
push_axi_stream(net, master_axi_stream, std_logic_vector(to_signed(m_I.get(x,y), data_width)) , tlast => last);
93+
if x = width(m_I)-1 then last := '1'; else last := '0'; end if;
94+
push_axi_stream(net, master_axi_stream, std_logic_vector(to_signed(get(m_I, x, y), data_width)) , tlast => last);
9795
end loop;
9896
end loop;
9997

@@ -111,24 +109,22 @@ begin
111109
saved <= false;
112110
wait for 50*clk_period;
113111

114-
m_O.init_2d(m_I.width, m_I.height, o'length, true);
115-
116-
info("Receiving m_O of size " & to_string(m_O.height) & "x" & to_string(m_O.width) & " from UUT...");
112+
info("Receiving m_O of size " & to_string(height(m_O)) & "x" & to_string(width(m_O)) & " from UUT...");
117113

118-
for y in 0 to m_O.height-1 loop
119-
for x in 0 to m_O.width-1 loop
114+
for y in 0 to height(m_O)-1 loop
115+
for x in 0 to width(m_O)-1 loop
120116
pop_axi_stream(net, slave_axi_stream, tdata => o, tlast => last);
121-
if (x = m_O.width-1) and (last='0') then
117+
if (x = width(m_O)-1) and (last='0') then
122118
error("Something went wrong. Last misaligned!");
123119
end if;
124-
m_O.set(x,y,to_integer(signed(o)));
120+
set(m_O, x, y, to_integer(signed(o)));
125121
end loop;
126122
end loop;
127123

128124
info("m_O read!");
129125

130126
wait until rising_edge(clk);
131-
m_O.save_csv(tb_path & csv_o);
127+
save_csv(m_O, tb_path & csv_o);
132128

133129
info("m_O saved!");
134130

@@ -140,23 +136,27 @@ begin
140136

141137
vunit_axism: entity vunit_lib.axi_stream_master
142138
generic map (
143-
master => master_axi_stream)
139+
master => master_axi_stream
140+
)
144141
port map (
145142
aclk => clk,
146143
tvalid => m_valid,
147144
tready => m_ready,
148145
tdata => m_data,
149-
tlast => m_last);
146+
tlast => m_last
147+
);
150148

151149
vunit_axiss: entity vunit_lib.axi_stream_slave
152150
generic map (
153-
slave => slave_axi_stream)
151+
slave => slave_axi_stream
152+
)
154153
port map (
155154
aclk => clk,
156155
tvalid => s_valid,
157156
tready => s_ready,
158157
tdata => s_data,
159-
tlast => s_last);
158+
tlast => s_last
159+
);
160160

161161
--
162162

0 commit comments

Comments
 (0)