VHDL-verification
Package to ease directed testing of HDL entities
vhdl_verification.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 --! @file
3 --! @author Hipolito Guzman-Miranda
4 --! @brief Common datatypes and component declarations
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 
12 --! @brief Common datatypes and component declarations
13 --!
14 --!
16 
17  --! @brief Output of datagen when \c valid='0'
18  --!
19  --! @detailed This data type has the same possible values that a \c std_logic
20  --! can take, but adding the value
21  --! \c keep, which means "maintain last valid value"
23  keep, -- Keep previous valid value
24  uninitialized, -- 'U'
25  unknown, -- 'X'
26  zero, -- '0'
27  one, -- '1'
28  high_impedance, -- 'Z'
29  weak_unknown, -- 'W'
30  weak_zero, -- 'L'
31  weak_one, -- 'H'
32  dont_care); -- '-'
33 
34  COMPONENT clkmanager
35  generic (
36  CLK_PERIOD : time := 10 ns;
37  RST_ACTIVE_VALUE : std_logic := '0';
38  RST_CYCLES : integer := 10
39  );
40  port (
41  endsim : in std_logic;
42  clk : out std_logic;
43  rst : out std_logic
44  );
45  END COMPONENT;
46 
47  COMPONENT datawrite
48  generic (
49  SIMULATION_LABEL : string := "datawrite";
50  VERBOSE : boolean := false;
51  DEBUG : boolean := false;
52  OUTPUT_FILE : string := "./out/datawrite_test.txt";
53  OUTPUT_NIBBLES : integer := 2;
54  DATA_WIDTH : integer := 8
55  );
56  port (
57  clk : in std_logic;
58  data : in std_logic_vector (DATA_WIDTH-1 downto 0);
59  valid : in std_logic;
60  endsim : in std_logic
61  );
62  END COMPONENT;
63 
64  COMPONENT datacompare
65  generic (
66  SIMULATION_LABEL : string := "datacompare";
67  VERBOSE : boolean := false;
68  DEBUG : boolean := false;
69  GOLD_OUTPUT_FILE : string := "../test/datagen_test.txt";
70  GOLD_OUTPUT_NIBBLES : integer := 2;
71  DATA_WIDTH : integer := 8;
72  ERROR_MARGIN : integer := 0
73  );
74  port (
75  clk : in std_logic;
76  data : in std_logic_vector (DATA_WIDTH-1 downto 0);
77  valid : in std_logic;
78  endsim : in std_logic
79  );
80  END COMPONENT;
81 
82  COMPONENT datagen
83  generic (
84  VERBOSE : boolean := false;
85  DEBUG : boolean := false;
86  STIMULI_FILE : string := "../test/datagen_test.txt";
87  STIMULI_NIBBLES : integer := 2;
88  DATA_WIDTH : integer := 8;
89  THROUGHPUT : integer := 0;
91  CYCLES_AFTER_LAST_VECTOR : integer := 10
92  );
93  port (
94  clk : in std_logic;
95  can_write : in std_logic;
96  data : out std_logic_vector (DATA_WIDTH-1 downto 0);
97  valid : out std_logic;
98  endsim : out std_logic
99  );
100  END COMPONENT;
101 
102  COMPONENT throughputchecker
103  generic (
104  SIMULATION_LABEL : string := "throughputchecker";
105  DEBUG : boolean := false;
106  THROUGHPUT : integer := 0
107  );
108  PORT (
109  clk : IN std_logic;
110  valid : IN std_logic;
111  endsim : IN std_logic
112  );
113  END COMPONENT;
114 
115  component led_emu is
116  generic (
117  ACTIVE_VALUE : std_logic := '0'; --! Led polarity
118  NUM_LEDS : integer := 4 --! How many leds are we emulating
119  );
120  port (
121  led_input : in std_logic_vector(NUM_LEDS-1 downto 0) --! Connect here the signal that drives the leds
122  );
123  end component;
124 
125  component uart_emu is
126  generic (
127  OUTPUT_FILE : string := "uart.log"; --! File where received chars will be written
128  VERBOSE : boolean := false; --! Log beginning and end of transactions, as well as individual bit values
129  DATA_BITS : integer := 8; --! Number of data bits in the UART word
130  PARITY : string := "none"; --! Can be either "even", "odd", or "none"
131  BIT_DURATION : time := 104 us; --! Duration of each bit, depends on baudrate (it is actually 1 second / baudrate)
132  STOP_BITS : integer := 1 --! Can be either 1 or 2
133  );
134  port (
135  uart_input : in std_logic --! Connect here the TX signal from your design
136  );
137  end component;
138 
139  component keypad_emu is
140  generic (
141  VERBOSE : boolean := false
142  );
143  port (
144  keypad_rows : out std_logic_vector(3 downto 0); --! This is the signal that must be read from the keypad
145  keypad_columns : in std_logic_vector(3 downto 0); --! Connect here the signal that drives the keypad
146  pressed_keys : in std_logic_vector(15 downto 0) --! One bit for each key. Set to '1' to emulate key press, set to '0' to emulate key release
147  );
148  end component;
149 
150 function slv2hexstring (data: std_logic_vector) return string;
151  function slv2string (a : std_logic_vector) return string;
152  function padstring (a: string) return string;
153  function xor_reduce (a: std_logic_vector) return std_logic;
154  function xnor_reduce (a: std_logic_vector) return std_logic;
155 
156 end vhdl_verification;
157 
158 package body vhdl_verification is
159 
160  -- Convert std_logic_vector (slv) to hexadecimal string
161  function slv2hexstring(data : std_logic_vector) return string is
162  variable binstr : string (1 to ((data'length+3)/4)*4);
163  variable hexstr : string (1 to (data'length+3)/4);
164  begin
165  binstr := padstring(slv2string(data));
166  for i in 1 to hexstr'length loop
167  case binstr(((i-1)*4)+1 to ((i-1)*4)+4) is
168  when "0000" => hexstr(i) := '0';
169  when "0001" => hexstr(i) := '1';
170  when "0010" => hexstr(i) := '2';
171  when "0011" => hexstr(i) := '3';
172  when "0100" => hexstr(i) := '4';
173  when "0101" => hexstr(i) := '5';
174  when "0110" => hexstr(i) := '6';
175  when "0111" => hexstr(i) := '7';
176  when "1000" => hexstr(i) := '8';
177  when "1001" => hexstr(i) := '9';
178  when "1010" => hexstr(i) := 'A';
179  when "1011" => hexstr(i) := 'B';
180  when "1100" => hexstr(i) := 'C';
181  when "1101" => hexstr(i) := 'D';
182  when "1110" => hexstr(i) := 'E';
183  when "1111" => hexstr(i) := 'F';
184  when others => hexstr(i) := 'X';
185  end case;
186  end loop;
187  return hexstr;
188  end slv2hexstring;
189 
190  -- Convert std_logic_vector to string
191  function slv2string ( a: std_logic_vector) return string is
192  variable b : string (1 to a'length) := (others => NUL);
193  variable stri : integer := 1;
194  begin
195  for i in a'range loop
196  b(stri) := std_logic'image(a((i)))(2);
197  stri := stri + 1;
198  end loop;
199  return b;
200  end function;
201 
202  -- Pad string to nearest multiple of 4
203  function padstring (a: string) return string is
204  variable b : string (1 to ((a'length+3)/4)*4);
205  variable padlen : integer := b'length - a'length;
206  begin
207  for i in 1 to padlen loop
208  b(i) := '0';
209  end loop;
210  for i in padlen+1 to b'length loop
211  b(i+padlen) := a(i);
212  end loop;
213  return b;
214  end function;
215 
216  -- Perform an xor reduction
217  function xor_reduce (a: std_logic_vector) return std_logic is
218  variable ret: std_logic;
219  begin
220  ret := '0';
221  for i in a'range loop
222  ret := ret xor a(i);
223  end loop;
224  return ret;
225  end function;
226 
227  -- Perform an xnor reduction
228  function xnor_reduce (a: std_logic_vector) return std_logic is
229  begin
230  return not xor_reduce(a);
231  end function;
232 
233 end vhdl_verification;
234 
GOLD_OUTPUT_FILEstring := "../test/datacompare_test.txt"
File where data is stored.
Definition: datacompare.vhd:36
SIMULATION_LABELstring := "datacompare"
Allow to separate messages from different instances in SIMULATION.
Definition: datacompare.vhd:33
in uart_inputstd_logic
Connect here the TX signal from your design.
Definition: uart_emu.vhd:42
Emulates PMOD keypad.
Definition: keypad_emu.vhd:20
Reads stimuli from file and outputs it with specified format.
Definition: datagen.vhd:31
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to write to file.
Definition: datawrite.vhd:40
GOLD_OUTPUT_NIBBLESinteger := 2
Maximum hex chars for each output data.
Definition: datacompare.vhd:37
out validstd_logic
Active high, indicates data is valid.
Definition: datagen.vhd:46
DATA_WIDTHinteger := 8
Width of input data.
Definition: datawrite.vhd:37
VERBOSEboolean := false
Report correct data and not only erroneous data.
Definition: datacompare.vhd:34
SIMULATION_LABELstring := "datawrite"
Allow to separate messages from different instances in SIMULATION.
Definition: datawrite.vhd:31
RST_ACTIVE_VALUEstd_logic := '0'
Reset polarity.
Definition: clkmanager.vhd:20
VERBOSEboolean := false
If true, log changes in the pressed_keys vector, apart from the changes in the individual keys...
Definition: keypad_emu.vhd:23
in led_inputstd_logic_vector( NUM_LEDS- 1 downto 0)
Connect here the signal that drives the leds.
Definition: led_emu.vhd:27
OUTPUT_FILEstring := "./output/datawrite_test.txt"
File where data will be stored.
Definition: datawrite.vhd:34
DEBUGboolean := false
Print debug info (developers only)
Definition: datagen.vhd:34
in clkstd_logic
Input data is aligned to this clock.
Writes circuit output data to file.
Definition: datawrite.vhd:29
Compares input data with values in file and reports errors.
Definition: datacompare.vhd:31
out rststd_logic
Generated reset.
Definition: clkmanager.vhd:27
out clkstd_logic
Generated clock.
Definition: clkmanager.vhd:25
Common datatypes and component declarations.
PARITYstring := "none"
Can be either "even", "odd", or "none".
Definition: uart_emu.vhd:36
CYCLES_AFTER_LAST_VECTORinteger := 10
Number of cycles between last data and assertion of endsim.
Definition: datagen.vhd:41
Emulates on-board leds.
Definition: led_emu.vhd:20
SIMULATION_LABELstring := "throughputchecker"
To separate messages from different instances in simulation.
in keypad_columnsstd_logic_vector( 3 downto 0)
Connect here the signal that drives the keypad.
Definition: keypad_emu.vhd:26
STOP_BITSinteger := 1
Can be either 1 or 2.
Definition: uart_emu.vhd:39
ACTIVE_VALUEstd_logic := '0'
Led polarity.
Definition: led_emu.vhd:22
Generates a clock and reset for simulation purposes.
Definition: clkmanager.vhd:17
in endsimstd_logic
clk stops changing when endsim='1', which effectively stops the simulation
Definition: clkmanager.vhd:24
in endsimstd_logic
Active high, tells the process that last data from datagen was sent.
in validstd_logic
Active high, indicates data is valid.
Definition: datawrite.vhd:41
OUTPUT_FILEstring := "uart.log"
File where received chars will be written.
Definition: uart_emu.vhd:33
DATA_BITSinteger := 8
Number of data bits in the UART word.
Definition: uart_emu.vhd:35
DEBUGboolean := false
Print debug info (developers)
DEBUGboolean := false
Print debug info (developers only)
Definition: datacompare.vhd:35
INVALID_DATAdatagen_invalid_data := unknown
Output value when data is not valid.
Definition: datagen.vhd:39
Checks that data is valid with a specific data rate.
STIMULI_NIBBLESinteger := 2
Maximum hex chars for each input data.
Definition: datagen.vhd:36
VERBOSEboolean := false
Log beginning and end of transactions, as well as individual bit values.
Definition: uart_emu.vhd:34
BIT_DURATIONtime := 104 us
Duration of each bit, depends on baudrate (it is actually 1 second / baudrate)
Definition: uart_emu.vhd:37
THROUGHPUTinteger := 0
Output 1 valid data each THROUGHPUT cycles.
Definition: datagen.vhd:38
RST_CYCLESinteger := 10
Number of cycles that reset will be asserted at the beginning of the simulation.
Definition: clkmanager.vhd:22
CLK_PERIODtime := 10 ns
Period of generated clock.
Definition: clkmanager.vhd:19
(keep,uninitialized,unknown,zero,one,high_impedance,weak_unknown,weak_zero,weak_one,dont_care) datagen_invalid_data
Output of datagen when valid='0'.
out datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Generated data.
Definition: datagen.vhd:45
ERROR_MARGINinteger := 0
Comparison is ok if data differs by this value or less.
Definition: datacompare.vhd:40
VERBOSEboolean := false
Print more internal details.
Definition: datawrite.vhd:32
THROUGHPUTinteger := 0
Wait cycles between valid data.
in pressed_keysstd_logic_vector( 15 downto 0)
One bit for each key. Set to '1' to emulate key press, set to '0' to emulate key release.
Definition: keypad_emu.vhd:28
in endsimstd_logic
Active high, tells the process to close its open files.
Definition: datawrite.vhd:43
VERBOSEboolean := false
Print more internal details.
Definition: datagen.vhd:33
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to compare with data in file.
Definition: datacompare.vhd:43
in validstd_logic
Active high, indicates data is valid.
in can_writestd_logic
Active high, tells datagen it can assert valid. Use for control-flow.
Definition: datagen.vhd:44
out keypad_rowsstd_logic_vector( 3 downto 0)
This is the signal that must be read from the keypad.
Definition: keypad_emu.vhd:25
in clkstd_logic
Align generated data to this clock.
Definition: datagen.vhd:43
STIMULI_FILEstring := "../test/datagen_test.txt"
File where data is stored.
Definition: datagen.vhd:35
OUTPUT_NIBBLESinteger := 2
Hex chars on each output line.
Definition: datawrite.vhd:35
Emulates an UART receiver. Writes receiver characters to a file.
Definition: uart_emu.vhd:31
in clkstd_logic
Will sample input on rising_edge of this clock.
Definition: datawrite.vhd:39
NUM_LEDSinteger := 4
How many leds are we emulating.
Definition: led_emu.vhd:24
string slv2hexstringdata,
One bit for each key. Set to '1' to emulate key press, set to '0' to emulate key release.
DATA_WIDTHinteger := 8
Width of inout data.
Definition: datacompare.vhd:38
in clkstd_logic
Expects input data aligned to this clock.
Definition: datacompare.vhd:42
DATA_WIDTHinteger := 8
Width of generated data.
Definition: datagen.vhd:37
out endsimstd_logic
Active high, tells the other simulation processes to close their open files.
Definition: datagen.vhd:48
in endsimstd_logic
Active high, tells the process to close its open files.
Definition: datacompare.vhd:46
_library_ IEEEIEEE
Use IEEE standard definitions library.
in validstd_logic
Active high, indicates data is valid.
Definition: datacompare.vhd:44
DEBUGboolean := false
Print debug info (developers only)
Definition: datawrite.vhd:33