-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlloreSequenze_TB.vhd
187 lines (160 loc) · 5.64 KB
/
ControlloreSequenze_TB.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 13:38:32 01/09/2020
-- Design Name:
-- Module Name: /home/valeriotor/Scrivania/Valerio/Uni/XilinxWEBPACK/14.7/ISE_DS/Safe/ControlloreSequenze_TB.vhd
-- Project Name: Safe
-- Target Device:
-- Tool versions:
-- Description:
--
-- VHDL Test Bench Created by ISE for module: ControlloreSequenze
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes:
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test. Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation
-- simulation model.
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
USE ieee.numeric_std.ALL;
ENTITY ControlloreSequenze_TB IS
END ControlloreSequenze_TB;
ARCHITECTURE behavior OF ControlloreSequenze_TB IS
-- Utilizzato per facilitare il loop test
signal LoopVector : std_logic_vector(3 downto 0) := "0000";
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT ControlloreSequenze
PORT(
Clock : IN std_logic;
Reset : IN std_logic;
BitKey : IN std_logic;
Code : IN std_logic_vector(3 downto 0);
EnableKey : IN std_logic;
EnterCode : IN std_logic;
Success : OUT std_logic
);
END COMPONENT;
--Inputs
signal Clock : std_logic := '0';
signal Reset : std_logic := '0';
signal BitKey : std_logic := '0';
signal Code : std_logic_vector(3 downto 0) := (others => '0');
signal EnableKey : std_logic := '0';
signal EnterCode : std_logic := '0';
--Outputs
signal Success : std_logic;
-- Clock period definitions
constant Clock_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: ControlloreSequenze PORT MAP (
Clock => Clock,
Reset => Reset,
BitKey => BitKey,
Code => Code,
EnableKey => EnableKey,
EnterCode => EnterCode,
Success => Success
);
-- Clock process definitions
Clock_process :process
begin
Clock <= '0';
wait for Clock_period/2;
Clock <= '1';
wait for Clock_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
Reset <= '1';
wait for 60 ns;
Reset <= '0';
wait for Clock_period*4;
Code <= "1011";
EnableKey <= '1';
wait for Clock_period;
BitKey <= '1';
wait for Clock_period;
BitKey <= '1';
wait for Clock_period;
BitKey <= '0';
wait for Clock_period;
BitKey <= '1';
wait for Clock_period;
EnterCode <= '1';
wait for Clock_period*3; -- Nota: in behavioral basterebbe Clock_period*2, ma aumento il ritardo per la simulazione post-route
assert (Success = '1') report "Incorrect output #1: expected 1, received " & std_logic'image(Success) severity error;
Code <= "0001";
wait for Clock_period*2;
assert (Success = '1') report "Incorrect output #2: expected 1, received " & std_logic'image(Success) severity error;
wait for Clock_period * 10;
EnableKey <= '0';
wait for Clock_period*2;
assert (Success = '0') report "Incorrect output #3: expected 0, received " & std_logic'image(Success) severity error;
-- ^^ Semplice controllo iniziale per verificare che il componente funzioni a dovere. #1 verifica che l'output si alzi,
-- #2 verifica che l'output non si abbassi al cambiare del codice, #3 verifica che l'output si abbassi all'abbassarsi di
-- EnableKey (che nel componente principale coinciderà con il sensore della chiave).
EnterCode <= '0';
EnableKey <= '1';
wait for Clock_period;
BitKey <= '0';
wait for Clock_period;
BitKey <= '0';
wait for Clock_period;
BitKey <= '0';
wait for Clock_period;
BitKey <= '0';
wait for Clock_period;
EnterCode <= '1';
wait for Clock_period*3;
assert (Success = '0') report "Incorrect output #4: expected 0, received " & std_logic'image(Success) severity error;
-- ^^ Verifico che un codice sbagliato non alzi l'uscita.
EnableKey <= '0';
wait for Clock_period;
-- Decommentare la seguente riga di codice per aggiungere uno sfasamento
--wait for 4.55 ns;
for i in 0 to 15 loop
Code <= std_logic_vector(to_unsigned(i, Code'length));
for j in 0 to 15 loop
LoopVector <= std_logic_vector(to_unsigned(j, LoopVector'length));
EnableKey <= '1';
EnterCode <= '0';
wait for Clock_Period;
BitKey <= LoopVector(0);
wait for Clock_Period;
BitKey <= LoopVector(1);
wait for Clock_Period;
BitKey <= LoopVector(2);
wait for Clock_Period;
BitKey <= LoopVector(3);
wait for Clock_Period;
EnterCode <= '1';
wait for Clock_Period*3;
if(Code = LoopVector) then
assert (Success = '1') report "Incorrect output #5: expected 1, received " & std_logic'image(Success) & " for i/j = " & integer'image(i) & "/" & integer'image(j) severity error;
else
assert (Success = '0') report "Incorrect output #5: expected 0, received " & std_logic'image(Success) & " for i/j = " & integer'image(i) & "/" & integer'image(j) severity error;
end if;
wait for Clock_Period;
EnableKey <= '0';
wait for Clock_Period;
end loop;
end loop;
-- ^^ Verifico tutte le 256 combinazioni tra chiave e codice (4 bit ciascuno => 16x16 comb.).
wait;
end process;
END;