Skip to content

Commit eabe333

Browse files
committed
Refactoring
1 parent bb6d253 commit eabe333

7 files changed

Lines changed: 97 additions & 130 deletions

File tree

vunit/vhdl/verification_components/src/axi_stream_master.vhd

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,51 @@ begin
9494
variable reply_msg : msg_t;
9595
variable msg_type : msg_type_t;
9696
variable rnd : RandomPType;
97-
variable inactive_axi_stream_policy : inactive_axi_stream_policy_t := get_inactive_axi_stream_policy(master);
9897
variable inactive_bus_policy : inactive_bus_policy_t;
9998
variable axi_stream_signal : axi_stream_signal_t;
10099
variable stall_config : integer_vector_ptr_t;
101100

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
101+
impure function get_inactive_axi_stream_policy(master : axi_stream_master_t) return inactive_axi_stream_policy_t is
102+
impure function to_inactive_axi_stream_policy(vec : integer_vector_ptr_t) return inactive_axi_stream_policy_t is
103+
variable inactive_policy : inactive_axi_stream_policy_t;
104+
begin
105+
for sig in inactive_policy'range loop
106+
inactive_policy(sig) := inactive_bus_policy_t'val(get(vec, axi_stream_signal_t'pos(sig)));
107+
end loop;
108+
109+
return inactive_policy;
110+
end;
106111
begin
107-
probability_stall_axi_stream(aclk, get_stall_config(axi_stream), rnd);
108-
end procedure;
112+
return to_inactive_axi_stream_policy(to_integer_vector_ptr(get(master.p_config, p_inactive_policy_idx)));
113+
end;
114+
115+
variable inactive_axi_stream_policy : inactive_axi_stream_policy_t := get_inactive_axi_stream_policy(master);
116+
117+
procedure set_inactive_axi_stream_policy(
118+
master : axi_stream_master_t;
119+
inactive_policy : inactive_bus_policy_t;
120+
axi_stream_signal : axi_stream_signal_t
121+
) is
122+
variable start, stop : axi_stream_signal_t := axi_stream_signal;
123+
begin
124+
if axi_stream_signal = all_signals then
125+
start := work.axi_stream_pkg.tdata;
126+
stop := work.axi_stream_pkg.tuser;
127+
end if;
128+
129+
for sig in start to stop loop
130+
set(
131+
to_integer_vector_ptr(get(master.p_config, p_inactive_policy_idx)),
132+
axi_stream_signal_t'pos(sig),
133+
inactive_bus_policy_t'pos(inactive_policy)
134+
);
135+
end loop;
136+
end;
137+
138+
impure function get_stall_config(master : axi_stream_master_t) return stall_config_t is
139+
begin
140+
return p_to_stall_config(to_integer_vector_ptr(get(master.p_config, p_stall_config_idx)));
141+
end;
109142

110143
procedure drive_inactive(
111144
signal l_tdata : out std_logic_vector(data_length(master)-1 downto 0);
@@ -159,7 +192,7 @@ begin
159192
rnd.InitSeed(rnd'instance_name);
160193
loop
161194
drive_inactive(tdata, tlast, tkeep, tstrb, tid, tdest, tuser);
162-
if (areset_n = '0') then
195+
if areset_n = '0' then
163196
tvalid <= '0';
164197
wait until areset_n = '1' and rising_edge(aclk);
165198
else
@@ -182,7 +215,7 @@ begin
182215

183216
elsif msg_type = stream_push_msg or msg_type = push_axi_stream_msg then
184217
-- stall according to probability configuration
185-
probability_stall_axi_stream(aclk, master, rnd);
218+
probability_stall_axi_stream(aclk, get_stall_config(master), rnd);
186219

187220
tvalid <= '1';
188221
tdata <= pop_std_ulogic_vector(msg);
@@ -194,11 +227,7 @@ begin
194227
tdest <= pop_std_ulogic_vector(msg);
195228
tuser <= pop_std_ulogic_vector(msg);
196229
else
197-
if pop_boolean(msg) then
198-
tlast <= '1';
199-
else
200-
tlast <= '0';
201-
end if;
230+
tlast <= '1' when pop_boolean(msg) else '0';
202231
tkeep <= (others => '1');
203232
tstrb <= (others => '1');
204233
tid <= (others => '0');
@@ -207,7 +236,6 @@ begin
207236
end if;
208237
wait until ((tvalid and tready) = '1' or areset_n = '0') and rising_edge(aclk);
209238
tvalid <= '0';
210-
drive_inactive(tdata, tlast, tkeep, tstrb, tid, tdest, tuser);
211239

212240
elsif msg_type = set_inactive_axi_stream_policy_msg then
213241
inactive_bus_policy := inactive_bus_policy_t'val(pop_integer(msg));
@@ -283,12 +311,17 @@ begin
283311
end generate axi_stream_protocol_checker_generate;
284312

285313
deprecation_message : process is
314+
impure function default_generics return boolean is
315+
begin
316+
return drive_invalid and (drive_invalid_val = 'X') and (drive_invalid_val_user = '0');
317+
end;
286318
begin
287-
warning_if(
319+
error_if(
288320
master.p_logger,
289-
drive_invalid,
290-
"The drive_invalid generics have been deprecated. Bus inactivity is now controlled " &
291-
"by the inactive_bus_policy parameter to the new_axi_stream_master function."
321+
not default_generics,
322+
"The drive_invalid generics have been deprecated. Bus inactivity is now controlled " & LF &
323+
"by the inactive_bus_policy parameter to the new_axi_stream_master function. Remove generics " & LF &
324+
"assignments and use the inactive_bus_policy parameter to avoid this error."
292325
);
293326

294327
wait;

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: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,19 @@ 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+
constant stall_probability_idx : natural := 0;
410+
constant min_stall_idx : natural := 1;
411+
constant max_stall_idx : natural := 2;
412+
410413
impure function get_valid_monitor(
411414
data_length : natural;
412415
id_length : natural := 0;
@@ -472,19 +475,19 @@ package body axi_stream_pkg is
472475
axi_stream_checker,
473476
protocol_checker.p_id_length,
474477
id_length,
475-
"ID length of monitor doesn't match that of the " & parent_component
478+
"ID length of protocol checker doesn't match that of the " & parent_component
476479
);
477480
check_equal(
478481
axi_stream_checker,
479482
protocol_checker.p_dest_length,
480483
dest_length,
481-
"Dest length of monitor doesn't match that of the " & parent_component
484+
"Dest length of protocol checker doesn't match that of the " & parent_component
482485
);
483486
check_equal(
484487
axi_stream_checker,
485488
protocol_checker.p_user_length,
486489
user_length,
487-
"User length of monitor doesn't match that of the " & parent_component
490+
"User length of protocol checker doesn't match that of the " & parent_component
488491
);
489492
return protocol_checker;
490493
end if;
@@ -495,18 +498,17 @@ package body axi_stream_pkg is
495498
begin
496499
-- Since values are in the 0 - 1 range, we can have the full resolution of the mantissa fit within
497500
-- an integer if reals are implemented as single-precision floats.
498-
set(result, 0, integer(stall_config.stall_probability * (2.0 ** 23)));
499-
set(result, 1, stall_config.min_stall_cycles);
500-
set(result, 2, stall_config.max_stall_cycles);
501+
set(
502+
result,
503+
stall_probability_idx,
504+
integer(stall_config.stall_probability * (2.0 ** single_precision_mantissa_length))
505+
);
506+
set(result, min_stall_idx, stall_config.min_stall_cycles);
507+
set(result, max_stall_idx, stall_config.max_stall_cycles);
501508

502509
return result;
503510
end;
504511

505-
procedure set_stall_config(master : axi_stream_master_t; stall_config : stall_config_t) is
506-
begin
507-
set(master.p_config, p_stall_config_idx, to_integer(to_integer_vector_ptr(stall_config)));
508-
end;
509-
510512
impure function to_integer_vector_ptr(inactive_policy : inactive_axi_stream_policy_t) return integer_vector_ptr_t is
511513
variable result : integer_vector_ptr_t := new_integer_vector_ptr(inactive_policy'length);
512514
begin
@@ -517,14 +519,6 @@ package body axi_stream_pkg is
517519
return result;
518520
end;
519521

520-
procedure set_inactive_axi_stream_policy(
521-
master : axi_stream_master_t;
522-
inactive_policy : inactive_axi_stream_policy_t
523-
) is
524-
begin
525-
set(master.p_config, p_interactive_policy_idx, to_integer(to_integer_vector_ptr(inactive_policy)));
526-
end;
527-
528522
impure function new_axi_stream_master(
529523
data_length : natural;
530524
id_length : natural := 0;
@@ -558,20 +552,15 @@ package body axi_stream_pkg is
558552
p_logger => logger,
559553
p_monitor => p_monitor,
560554
p_protocol_checker => p_protocol_checker,
561-
p_config => new_integer_vector_ptr(p_interactive_policy_idx + 1)
555+
p_config => new_integer_vector_ptr(p_inactive_policy_idx + 1)
562556
);
563557

564-
set_stall_config(handle, stall_config);
565-
set_inactive_axi_stream_policy(handle, inactive_policy);
558+
set(handle.p_config, p_stall_config_idx, to_integer(to_integer_vector_ptr(stall_config)));
559+
set(handle.p_config, p_inactive_policy_idx, to_integer(to_integer_vector_ptr(inactive_policy)));
566560

567561
return handle;
568562
end;
569563

570-
procedure set_stall_config(slave : axi_stream_slave_t; stall_config : stall_config_t) is
571-
begin
572-
set(slave.p_config, p_stall_config_idx, to_integer(to_integer_vector_ptr(stall_config)));
573-
end;
574-
575564
impure function new_axi_stream_slave(
576565
data_length : natural;
577566
id_length : natural := 0;
@@ -606,7 +595,7 @@ package body axi_stream_pkg is
606595
p_protocol_checker => p_protocol_checker,
607596
p_config => new_integer_vector_ptr(p_stall_config_idx + 1));
608597

609-
set_stall_config(handle, stall_config);
598+
set(handle.p_config, p_stall_config_idx, to_integer(to_integer_vector_ptr(stall_config)));
610599

611600
return handle;
612601
end;
@@ -998,9 +987,9 @@ package body axi_stream_pkg is
998987
impure function p_to_stall_config(vec : integer_vector_ptr_t) return stall_config_t is
999988
variable stall_config : stall_config_t;
1000989
begin
1001-
stall_config.stall_probability := real(get(vec, 0)) * (2.0 ** (-23));
1002-
stall_config.min_stall_cycles := get(vec, 1);
1003-
stall_config.max_stall_cycles := get(vec, 2);
990+
stall_config.stall_probability := real(get(vec, stall_probability_idx)) * (2.0 ** (-single_precision_mantissa_length));
991+
stall_config.min_stall_cycles := get(vec, min_stall_idx);
992+
stall_config.max_stall_cycles := get(vec, max_stall_idx);
1004993

1005994
return stall_config;
1006995
end;
@@ -1102,15 +1091,4 @@ package body axi_stream_pkg is
11021091
return stall_config;
11031092
end;
11041093

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-
11161094
end package body;

vunit/vhdl/verification_components/src/axi_stream_private_pkg.vhd

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,10 @@ package axi_stream_private_pkg is
2121
rnd : inout RandomPType
2222
);
2323

24-
procedure set_inactive_axi_stream_policy(
25-
master : axi_stream_master_t;
26-
inactive_policy : inactive_bus_policy_t;
27-
axi_stream_signal : axi_stream_signal_t
28-
);
29-
30-
impure function get_inactive_axi_stream_policy(master : axi_stream_master_t) return inactive_axi_stream_policy_t;
31-
32-
impure function get_stall_config(master : axi_stream_master_t) return stall_config_t;
33-
impure function get_stall_config(slave : axi_stream_slave_t) return stall_config_t;
24+
function resolve_tstrb(
25+
tkeep : std_logic_vector;
26+
tstrb : std_logic_vector
27+
) return std_logic_vector;
3428
end package;
3529

3630
package body axi_stream_private_pkg is
@@ -48,49 +42,15 @@ package body axi_stream_private_pkg is
4842
end loop;
4943
end procedure;
5044

51-
procedure set_inactive_axi_stream_policy(
52-
master : axi_stream_master_t;
53-
inactive_policy : inactive_bus_policy_t;
54-
axi_stream_signal : axi_stream_signal_t
55-
) is
56-
variable start, stop : axi_stream_signal_t := axi_stream_signal;
45+
function resolve_tstrb(
46+
tkeep : std_logic_vector;
47+
tstrb : std_logic_vector
48+
) return std_logic_vector is
5749
begin
58-
if axi_stream_signal = all_signals then
59-
start := tdata;
60-
stop := tuser;
50+
if tstrb = (tstrb'range => 'U') then
51+
return tkeep;
52+
else
53+
return tstrb;
6154
end if;
62-
63-
for sig in start to stop loop
64-
set(
65-
to_integer_vector_ptr(get(master.p_config, p_interactive_policy_idx)),
66-
axi_stream_signal_t'pos(sig),
67-
inactive_bus_policy_t'pos(inactive_policy)
68-
);
69-
end loop;
70-
end;
71-
72-
impure function to_inactive_axi_stream_policy(vec : integer_vector_ptr_t) return inactive_axi_stream_policy_t is
73-
variable inactive_policy : inactive_axi_stream_policy_t;
74-
begin
75-
for sig in inactive_policy'range loop
76-
inactive_policy(sig) := inactive_bus_policy_t'val(get(vec, axi_stream_signal_t'pos(sig)));
77-
end loop;
78-
79-
return inactive_policy;
80-
end;
81-
82-
impure function get_inactive_axi_stream_policy(master : axi_stream_master_t) return inactive_axi_stream_policy_t is
83-
begin
84-
return to_inactive_axi_stream_policy(to_integer_vector_ptr(get(master.p_config, p_interactive_policy_idx)));
85-
end;
86-
87-
impure function get_stall_config(master : axi_stream_master_t) return stall_config_t is
88-
begin
89-
return p_to_stall_config(to_integer_vector_ptr(get(master.p_config, p_stall_config_idx)));
90-
end;
91-
92-
impure function get_stall_config(slave : axi_stream_slave_t) return stall_config_t is
93-
begin
94-
return p_to_stall_config(to_integer_vector_ptr(get(slave.p_config, p_stall_config_idx)));
9555
end;
9656
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,

0 commit comments

Comments
 (0)