1 ------------------------------------------------------------------------------- 3 --! @author Hipolito Guzman-Miranda 4 --! @brief Common datatypes and component declarations 5 ------------------------------------------------------------------------------- 7 --! Use IEEE standard definitions library 9 --! Use std_logic* signal types 10 use IEEE.STD_LOGIC_1164.
all;
12 --! @brief Common datatypes and component declarations 17 --! @brief Output of datagen when \c valid='0' 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 28 high_impedance, -- 'Z' 118 NUM_LEDS : :=
4 --! How many leds are we emulating 121 led_input :
in (
NUM_LEDS-1 downto 0)
--! Connect here the signal that drives the leds 127 OUTPUT_FILE : :=
"uart.log";
--! File where received chars will be written 128 VERBOSE : := false;
--! Log beginning and end of transactions, as well as individual bit values 129 DATA_BITS : :=
8;
--! Number of data bits in the UART word 130 PARITY : :=
"none";
--! Can be either "even", "odd", or "none" 131 BIT_DURATION : :=
104 us;
--! Duration of each bit, depends on baudrate (it is actually 1 second / baudrate) 132 STOP_BITS : :=
1 --! Can be either 1 or 2 135 uart_input :
in --! Connect here the TX signal from your design 144 keypad_rows :
out (
3 downto 0);
--! This is the signal that must be read from the keypad 145 keypad_columns :
in (
3 downto 0);
--! Connect here the signal that drives the keypad 146 pressed_keys :
in (
15 downto 0)
--! One bit for each key. Set to '1' to emulate key press, set to '0' to emulate key release 151 function slv2string (a : )
return ;
152 function padstring (a: )
return ;
153 function xor_reduce (a: )
return ;
154 function xnor_reduce (a: )
return ;
156 end vhdl_verification;
160 -- Convert std_logic_vector (slv) to hexadecimal string 162 variable binstr :
(1 to ((data'
length+
3)/
4)*
4);
163 variable hexstr :
(1 to (data'
length+
3)/
4);
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';
190 -- Convert std_logic_vector to string 191 function slv2string ( a: )
return is 192 variable b :
(1 to a'
length) :=
(others => NUL
);
193 variable stri : :=
1;
195 for i
in a'
range loop 196 b
(stri
) := '
image(a
((i
)))(2);
202 -- Pad string to nearest multiple of 4 203 function padstring (a: )
return is 204 variable b :
(1 to ((a'
length+
3)/
4)*
4);
205 variable padlen : := b'
length - a'
length;
207 for i
in 1 to padlen
loop 210 for i
in padlen+
1 to b'
length loop 216 -- Perform an xor reduction 217 function xor_reduce (a: )
return is 221 for i
in a'
range loop 227 -- Perform an xnor reduction 228 function xnor_reduce (a: )
return is 230 return not xor_reduce
(a
);
233 end vhdl_verification;
GOLD_OUTPUT_FILEstring := "../test/datacompare_test.txt"
File where data is stored.
SIMULATION_LABELstring := "datacompare"
Allow to separate messages from different instances in SIMULATION.
in uart_inputstd_logic
Connect here the TX signal from your design.
Reads stimuli from file and outputs it with specified format.
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to write to file.
GOLD_OUTPUT_NIBBLESinteger := 2
Maximum hex chars for each output data.
out validstd_logic
Active high, indicates data is valid.
DATA_WIDTHinteger := 8
Width of input data.
VERBOSEboolean := false
Report correct data and not only erroneous data.
SIMULATION_LABELstring := "datawrite"
Allow to separate messages from different instances in SIMULATION.
RST_ACTIVE_VALUEstd_logic := '0'
Reset polarity.
VERBOSEboolean := false
If true, log changes in the pressed_keys vector, apart from the changes in the individual keys...
in led_inputstd_logic_vector( NUM_LEDS- 1 downto 0)
Connect here the signal that drives the leds.
OUTPUT_FILEstring := "./output/datawrite_test.txt"
File where data will be stored.
DEBUGboolean := false
Print debug info (developers only)
in clkstd_logic
Input data is aligned to this clock.
Writes circuit output data to file.
Compares input data with values in file and reports errors.
out rststd_logic
Generated reset.
out clkstd_logic
Generated clock.
Common datatypes and component declarations.
PARITYstring := "none"
Can be either "even", "odd", or "none".
CYCLES_AFTER_LAST_VECTORinteger := 10
Number of cycles between last data and assertion of endsim.
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.
STOP_BITSinteger := 1
Can be either 1 or 2.
ACTIVE_VALUEstd_logic := '0'
Led polarity.
Generates a clock and reset for simulation purposes.
in endsimstd_logic
clk stops changing when endsim='1', which effectively stops the simulation
in endsimstd_logic
Active high, tells the process that last data from datagen was sent.
in validstd_logic
Active high, indicates data is valid.
OUTPUT_FILEstring := "uart.log"
File where received chars will be written.
DATA_BITSinteger := 8
Number of data bits in the UART word.
DEBUGboolean := false
Print debug info (developers)
DEBUGboolean := false
Print debug info (developers only)
INVALID_DATAdatagen_invalid_data := unknown
Output value when data is not valid.
Checks that data is valid with a specific data rate.
STIMULI_NIBBLESinteger := 2
Maximum hex chars for each input data.
VERBOSEboolean := false
Log beginning and end of transactions, as well as individual bit values.
BIT_DURATIONtime := 104 us
Duration of each bit, depends on baudrate (it is actually 1 second / baudrate)
THROUGHPUTinteger := 0
Output 1 valid data each THROUGHPUT cycles.
RST_CYCLESinteger := 10
Number of cycles that reset will be asserted at the beginning of the simulation.
CLK_PERIODtime := 10 ns
Period of generated clock.
(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.
ERROR_MARGINinteger := 0
Comparison is ok if data differs by this value or less.
VERBOSEboolean := false
Print more internal details.
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.
in endsimstd_logic
Active high, tells the process to close its open files.
VERBOSEboolean := false
Print more internal details.
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to compare with data in file.
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.
out keypad_rowsstd_logic_vector( 3 downto 0)
This is the signal that must be read from the keypad.
in clkstd_logic
Align generated data to this clock.
STIMULI_FILEstring := "../test/datagen_test.txt"
File where data is stored.
OUTPUT_NIBBLESinteger := 2
Hex chars on each output line.
Emulates an UART receiver. Writes receiver characters to a file.
in clkstd_logic
Will sample input on rising_edge of this clock.
NUM_LEDSinteger := 4
How many leds are we emulating.
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.
in clkstd_logic
Expects input data aligned to this clock.
DATA_WIDTHinteger := 8
Width of generated data.
out endsimstd_logic
Active high, tells the other simulation processes to close their open files.
in endsimstd_logic
Active high, tells the process to close its open files.
_library_ IEEEIEEE
Use IEEE standard definitions library.
in validstd_logic
Active high, indicates data is valid.
DEBUGboolean := false
Print debug info (developers only)