Skip to content

Commit 3bbae69

Browse files
committed
Refactoring
1 parent bb6d253 commit 3bbae69

6 files changed

Lines changed: 38 additions & 50 deletions

File tree

vunit/vhdl/verification_components/src/axi_stream_master.vhd

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ begin
9999
variable axi_stream_signal : axi_stream_signal_t;
100100
variable stall_config : integer_vector_ptr_t;
101101

102-
procedure probability_stall_axi_stream(
103-
signal aclk : in std_logic;
104-
axi_stream : in axi_stream_master_t;
105-
rnd : inout RandomPType) is
106-
begin
107-
probability_stall_axi_stream(aclk, get_stall_config(axi_stream), rnd);
108-
end procedure;
109-
110102
procedure drive_inactive(
111103
signal l_tdata : out std_logic_vector(data_length(master)-1 downto 0);
112104
signal l_tlast : out std_logic;
@@ -159,7 +151,7 @@ begin
159151
rnd.InitSeed(rnd'instance_name);
160152
loop
161153
drive_inactive(tdata, tlast, tkeep, tstrb, tid, tdest, tuser);
162-
if (areset_n = '0') then
154+
if areset_n = '0' then
163155
tvalid <= '0';
164156
wait until areset_n = '1' and rising_edge(aclk);
165157
else
@@ -182,7 +174,7 @@ begin
182174

183175
elsif msg_type = stream_push_msg or msg_type = push_axi_stream_msg then
184176
-- stall according to probability configuration
185-
probability_stall_axi_stream(aclk, master, rnd);
177+
probability_stall_axi_stream(aclk, get_stall_config(master), rnd);
186178

187179
tvalid <= '1';
188180
tdata <= pop_std_ulogic_vector(msg);
@@ -194,11 +186,7 @@ begin
194186
tdest <= pop_std_ulogic_vector(msg);
195187
tuser <= pop_std_ulogic_vector(msg);
196188
else
197-
if pop_boolean(msg) then
198-
tlast <= '1';
199-
else
200-
tlast <= '0';
201-
end if;
189+
tlast <= '1' when pop_boolean(msg) else '0';
202190
tkeep <= (others => '1');
203191
tstrb <= (others => '1');
204192
tid <= (others => '0');

vunit/vhdl/verification_components/src/axi_stream_monitor.vhd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ library ieee;
88
use ieee.std_logic_1164.all;
99

1010
use work.axi_stream_pkg.all;
11+
use work.axi_stream_private_pkg.all;
1112
use work.com_pkg.net;
1213
use work.com_pkg.publish;
1314
use work.com_types_pkg.msg_t;
@@ -55,7 +56,7 @@ begin
5556
);
5657
end if;
5758

58-
tstrb_resolved := tkeep when is_u(tstrb) else tstrb;
59+
tstrb_resolved := resolve_tstrb(tkeep, tstrb);
5960
axi_stream_transaction := (
6061
tdata => tdata,
6162
tlast => tlast = '1',

vunit/vhdl/verification_components/src/axi_stream_pkg.vhd

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,16 @@ package axi_stream_pkg is
397397
max_stall_cycles : natural
398398
) return stall_config_t;
399399

400-
function is_u(value : std_ulogic_vector) return boolean;
401-
402400
-- Private
403401
constant p_stall_config_idx : natural := 0;
404-
constant p_interactive_policy_idx : natural := 1;
402+
constant p_inactive_policy_idx : natural := 1;
405403
impure function p_to_stall_config(vec : integer_vector_ptr_t) return stall_config_t;
406404

407405
end package;
408406

409407
package body axi_stream_pkg is
408+
constant single_precision_mantissa_length : natural := 23;
409+
410410
impure function get_valid_monitor(
411411
data_length : natural;
412412
id_length : natural := 0;
@@ -472,19 +472,19 @@ package body axi_stream_pkg is
472472
axi_stream_checker,
473473
protocol_checker.p_id_length,
474474
id_length,
475-
"ID length of monitor doesn't match that of the " & parent_component
475+
"ID length of protocol checker doesn't match that of the " & parent_component
476476
);
477477
check_equal(
478478
axi_stream_checker,
479479
protocol_checker.p_dest_length,
480480
dest_length,
481-
"Dest length of monitor doesn't match that of the " & parent_component
481+
"Dest length of protocol checker doesn't match that of the " & parent_component
482482
);
483483
check_equal(
484484
axi_stream_checker,
485485
protocol_checker.p_user_length,
486486
user_length,
487-
"User length of monitor doesn't match that of the " & parent_component
487+
"User length of protocol checker doesn't match that of the " & parent_component
488488
);
489489
return protocol_checker;
490490
end if;
@@ -495,7 +495,7 @@ package body axi_stream_pkg is
495495
begin
496496
-- Since values are in the 0 - 1 range, we can have the full resolution of the mantissa fit within
497497
-- an integer if reals are implemented as single-precision floats.
498-
set(result, 0, integer(stall_config.stall_probability * (2.0 ** 23)));
498+
set(result, 0, integer(stall_config.stall_probability * (2.0 ** single_precision_mantissa_length)));
499499
set(result, 1, stall_config.min_stall_cycles);
500500
set(result, 2, stall_config.max_stall_cycles);
501501

@@ -522,7 +522,7 @@ package body axi_stream_pkg is
522522
inactive_policy : inactive_axi_stream_policy_t
523523
) is
524524
begin
525-
set(master.p_config, p_interactive_policy_idx, to_integer(to_integer_vector_ptr(inactive_policy)));
525+
set(master.p_config, p_inactive_policy_idx, to_integer(to_integer_vector_ptr(inactive_policy)));
526526
end;
527527

528528
impure function new_axi_stream_master(
@@ -558,7 +558,7 @@ package body axi_stream_pkg is
558558
p_logger => logger,
559559
p_monitor => p_monitor,
560560
p_protocol_checker => p_protocol_checker,
561-
p_config => new_integer_vector_ptr(p_interactive_policy_idx + 1)
561+
p_config => new_integer_vector_ptr(p_inactive_policy_idx + 1)
562562
);
563563

564564
set_stall_config(handle, stall_config);
@@ -998,7 +998,7 @@ package body axi_stream_pkg is
998998
impure function p_to_stall_config(vec : integer_vector_ptr_t) return stall_config_t is
999999
variable stall_config : stall_config_t;
10001000
begin
1001-
stall_config.stall_probability := real(get(vec, 0)) * (2.0 ** (-23));
1001+
stall_config.stall_probability := real(get(vec, 0)) * (2.0 ** (-single_precision_mantissa_length));
10021002
stall_config.min_stall_cycles := get(vec, 1);
10031003
stall_config.max_stall_cycles := get(vec, 2);
10041004

@@ -1102,15 +1102,4 @@ package body axi_stream_pkg is
11021102
return stall_config;
11031103
end;
11041104

1105-
function is_u(value : std_ulogic_vector) return boolean is
1106-
begin
1107-
for idx in value'range loop
1108-
if value(idx) /= 'U' then
1109-
return false;
1110-
end if;
1111-
end loop;
1112-
1113-
return true;
1114-
end;
1115-
11161105
end package body;

vunit/vhdl/verification_components/src/axi_stream_private_pkg.vhd

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ package axi_stream_private_pkg is
3131

3232
impure function get_stall_config(master : axi_stream_master_t) return stall_config_t;
3333
impure function get_stall_config(slave : axi_stream_slave_t) return stall_config_t;
34+
35+
function resolve_tstrb(
36+
tkeep : std_logic_vector;
37+
tstrb : std_logic_vector
38+
) return std_logic_vector;
3439
end package;
3540

3641
package body axi_stream_private_pkg is
@@ -62,7 +67,7 @@ package body axi_stream_private_pkg is
6267

6368
for sig in start to stop loop
6469
set(
65-
to_integer_vector_ptr(get(master.p_config, p_interactive_policy_idx)),
70+
to_integer_vector_ptr(get(master.p_config, p_inactive_policy_idx)),
6671
axi_stream_signal_t'pos(sig),
6772
inactive_bus_policy_t'pos(inactive_policy)
6873
);
@@ -81,7 +86,7 @@ package body axi_stream_private_pkg is
8186

8287
impure function get_inactive_axi_stream_policy(master : axi_stream_master_t) return inactive_axi_stream_policy_t is
8388
begin
84-
return to_inactive_axi_stream_policy(to_integer_vector_ptr(get(master.p_config, p_interactive_policy_idx)));
89+
return to_inactive_axi_stream_policy(to_integer_vector_ptr(get(master.p_config, p_inactive_policy_idx)));
8590
end;
8691

8792
impure function get_stall_config(master : axi_stream_master_t) return stall_config_t is
@@ -93,4 +98,16 @@ package body axi_stream_private_pkg is
9398
begin
9499
return p_to_stall_config(to_integer_vector_ptr(get(slave.p_config, p_stall_config_idx)));
95100
end;
101+
102+
function resolve_tstrb(
103+
tkeep : std_logic_vector;
104+
tstrb : std_logic_vector
105+
) return std_logic_vector is
106+
begin
107+
if tstrb = (tstrb'range => 'U') then
108+
return tkeep;
109+
else
110+
return tstrb;
111+
end if;
112+
end;
96113
end package body;

vunit/vhdl/verification_components/src/axi_stream_protocol_checker.vhd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use ieee.numeric_std_unsigned.all;
1111
use std.textio.all;
1212

1313
use work.axi_stream_pkg.all;
14+
use work.axi_stream_private_pkg.all;
1415
use work.check_pkg.all;
1516
use work.checker_pkg.all;
1617
use work.event_common_pkg.is_active;
@@ -91,7 +92,7 @@ architecture a of axi_stream_protocol_checker is
9192
return ret;
9293
end function;
9394
begin
94-
tstrb_resolved <= tkeep when is_u(tstrb) else tstrb;
95+
tstrb_resolved <= resolve_tstrb(tkeep, tstrb);
9596
handshake_is_not_x <= '1' when not is_x(tvalid) and not is_x(tready) else '0';
9697

9798
-- AXI4STREAM_ERRM_TDATA_STABLE TDATA remains stable when TVALID is asserted,

vunit/vhdl/verification_components/src/axi_stream_slave.vhd

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ begin
8282
end process;
8383

8484
bus_process : process
85-
procedure probability_stall_axi_stream(
86-
signal aclk : in std_logic;
87-
axi_stream : in axi_stream_slave_t;
88-
rnd : inout RandomPType) is
89-
begin
90-
probability_stall_axi_stream(aclk, get_stall_config(axi_stream), rnd);
91-
end procedure;
92-
9385
procedure check_field(got, exp : std_logic_vector; msg : string) is
9486
begin
9587
if got'length /= 0 and exp'length /= 0 then
@@ -135,13 +127,13 @@ begin
135127
elsif msg_type = stream_pop_msg or msg_type = pop_axi_stream_msg or msg_type = check_axi_stream_msg then
136128

137129
-- stall according to probability configuration
138-
probability_stall_axi_stream(aclk, slave, rnd);
130+
probability_stall_axi_stream(aclk, get_stall_config(slave), rnd);
139131

140132
tready <= '1';
141133
wait until (tvalid and tready) = '1' and rising_edge(aclk);
142134
tready <= '0';
143135

144-
tstrb_resolved := tkeep when is_u(tstrb) else tstrb;
136+
tstrb_resolved := resolve_tstrb(tkeep, tstrb);
145137
if msg_type = stream_pop_msg or msg_type = pop_axi_stream_msg then
146138
axi_stream_transaction := (
147139
tdata => tdata,

0 commit comments

Comments
 (0)