VHDL-verification
Package to ease directed testing of HDL entities
throughputchecker.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @author Hipolito Guzman-Miranda
4 --! @brief Checks that a specific valid signal is active with expected data rate
5 -------------------------------------------------------------------------------
6 
7 --! Use IEEE standard definitions library;
8 LIBRARY ieee;
9 --! Use std_logic* signal types
10 USE ieee.std_logic_1164.ALL;
11 --! Allows use of arithmetical operations between integers and vectors
12 use ieee.numeric_std.all;
13 --! Allows writing strings to lines and lines to files
14 use STD.textio.all;
15 --! Allows writing std_logic_vector(s) to line(s) in BIN, HEX, OCT and reading BIN, HEX, OCT vector(s) from line(s)
16 use ieee.std_logic_textio.all;
17 --! For print() function
18 use work.txt_util.all;
19 
20 --! @brief Checks that data is valid with a specific data rate
21 --!
22 --! @detailed Checks that \c valid is active once each \c THROUGHPUT cycles.
23 --! Assumes \c valid is active high. Also reports the total number of
24 --! valid data seen when \c endsim is asserted. Note that this entity does not
25 --! need to know the actual value of the
26 --! data, only the value of the accompanying \c valid signal
28  generic(
29  SIMULATION_LABEL : string := "throughputchecker"; --! To separate messages from different instances in simulation
30  DEBUG : boolean := false; --! Print debug info (developers)
31  THROUGHPUT : integer := 0 --! Wait cycles between valid data
32  );
33  port(
34  clk : in std_logic; --! Input data is aligned to this clock
35  valid : in std_logic; --! Active high, indicates data is valid
36  endsim : in std_logic --! Active high, tells the process that last data from datagen was sent
37  );
38 end throughputchecker;
39 
40 --! @brief Architecture compares input data rate with expected data rate
41 --!
42 --! @detailed After first valid data is seen, internally counts from 0 to
43 --! THROUGHPUT - 1 and checks if \c valid is \c '1' when expected
44 architecture compare_with_expected of throughputchecker is
45 
46  signal cycle_count : integer := THROUGHPUT - 1 ; --! Cycles until next expected data
47  signal valid_count : integer := 0; --! Valid data seen
48  signal expected_valid : std_logic := '1'; --! Expected value for 'valid'
49 
50 begin
51 
52  assert THROUGHPUT > 0
53  report "throughputchecker(" & SIMULATION_LABEL & "): THROUGHPUT must be a positive non-zero integer"
54  severity failure;
55 
56  --! @brief Computes expected value for valid and reports an error if actual value is different
57  --!
58  --! @detailed Manages this by waiting for first valid and keeping an internal
59  --! count. When endsim is asserted, reports total valid data seen
60  expecting_valid : process
61 
62  begin
63 
64  -- wait until the first valid to start counting down
65  while (valid /= '1') loop
66  wait until rising_edge(clk);
67  end loop;
68 
69  while (endsim /= '1') loop
70 
71  assert (valid = '0' OR valid = '1')
72  report "throughputchecker(" & SIMULATION_LABEL & "): invalid value for valid, should only have '0' or '1'! (got '" & std_logic'image(valid) & "')"
73  severity failure;
74 
75  if (valid /= expected_valid) then
76  if (valid = '1' and expected_valid = '0') then
77  report "throughputchecker(" & SIMULATION_LABEL & "): ERROR: data valid " & integer'image(cycle_count + 1) & " cycles before expected" severity error;
78  end if;
79  end if;
80 
81  if (valid = '1') then
82  valid_count <= valid_count + 1;
83  print (DEBUG, "seen valid, valid_count: " & integer'image(valid_count + 1));
84  end if;
85 
86  if (cycle_count = 0) then
87  cycle_count <= THROUGHPUT - 1;
88  expected_valid <= '1';
89  else
90  cycle_count <= cycle_count - 1;
91  expected_valid <= '0';
92  end if;
93 
94  -- Wait for next rising edge of clk
95  -- if endsim is asserted, do not wait for the clk edge, because it will never come
96  wait until rising_edge(clk) or (endsim = '1');
97 
98  end loop;
99 
100  report "throughputchecker(" & SIMULATION_LABEL & "): test end. valid_count: " & integer'image(valid_count) severity note;
101 
102  wait;
103 
104  end process;
105 
106 end compare_with_expected;
107 
in clkstd_logic
Input data is aligned to this clock.
SIMULATION_LABELstring := "throughputchecker"
To separate messages from different instances in simulation.
_library_ ieeeieee
Use IEEE standard definitions library.
Definition: led_emu.vhd:8
in endsimstd_logic
Active high, tells the process that last data from datagen was sent.
integer := 0 valid_count
Valid data seen.
DEBUGboolean := false
Print debug info (developers)
Checks that data is valid with a specific data rate.
std_logic := '1' expected_valid
Expected value for &#39;valid&#39;.
THROUGHPUTinteger := 0
Wait cycles between valid data.
in validstd_logic
Active high, indicates data is valid.
integer := THROUGHPUT- 1 cycle_count
Cycles until next expected data.
Allows for text output in simulation.
Definition: txt_util.vhd:12