-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_logicGates_tb.vhd
126 lines (98 loc) · 2.65 KB
/
03_logicGates_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
--------------------------------------------------------------------
-- Test Bench des portes logiques de base : NAND, NOT, AND, OR, XOR.
--------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity LOGIC_GATES_TB is
end LOGIC_GATES_TB;
architecture arch of LOGIC_GATES_TB is
component NAND_GATE
port( A: in std_logic;
B: in std_logic;
Q: out std_logic
);
end component;
component NOT_GATE
port( A: in std_logic;
Q: out std_logic
);
end component;
component AND_GATE
port( A: in std_logic;
B: in std_logic;
Q: out std_logic
);
end component;
component OR_GATE
port( A: in std_logic;
B: in std_logic;
Q: out std_logic
);
end component;
component XOR_GATE
port( A: in std_logic;
B: in std_logic;
Q: out std_logic
);
end component;
signal A, B, Q_NAND, Q_NOT_A, Q_AND, Q_OR, Q_XOR: std_logic;
function isValid (A, B, Q_NAND, Q_NOT_A, Q_AND, Q_OR, Q_XOR : std_logic) return std_logic is
variable result : std_logic;
begin
result := '1';
if (Q_NAND/=not(A and B)) then result := '0'; end if;
if (Q_NOT_A/=not(A)) then result := '0'; end if;
if (Q_AND/=(A and B)) then result := '0'; end if;
if (Q_OR/=(A or B)) then result := '0'; end if;
if (Q_XOR/=(A xor B)) then result := '0'; end if;
return result;
end;
begin
Nand1: NAND_GATE port map (A, B, Q_NAND);
Not1: NOT_GATE port map (A, Q_NOT_A);
And1: AND_GATE port map (A, B, Q_AND);
Or1: OR_GATE port map (A, B, Q_OR);
Xor1: XOR_GATE port map (A, B, Q_XOR);
process
variable tb_failed: integer := 0;
begin
A <= '0';
B <= '0';
wait for 10 ns;
if (isValid(A, B, Q_NAND, Q_NOT_A, Q_AND, Q_OR, Q_XOR)/='1') then
report "Regtest a échoué - test 1" severity error;
tb_failed := 1;
end if;
A <= '1';
B <= '0';
wait for 10 ns;
if (isValid(A, B, Q_NAND, Q_NOT_A, Q_AND, Q_OR, Q_XOR)/='1') then
report "Regtest a échoué - test 1" severity error;
tb_failed := 1;
end if;
A <= '1';
B <= '1';
wait for 10 ns;
if (isValid(A, B, Q_NAND, Q_NOT_A, Q_AND, Q_OR, Q_XOR)/='1') then
report "Regtest a échoué - test 1" severity error;
tb_failed := 1;
end if;
A <= '0';
B <= '1';
wait for 10 ns;
if (isValid(A, B, Q_NAND, Q_NOT_A, Q_AND, Q_OR, Q_XOR)/='1') then
report "Regtest a échoué - test 1" severity error;
tb_failed := 1;
end if;
if (tb_failed=0) then
assert false report "Testbench OK"
severity note;
else
assert true
report "Testbench a échoué"
severity error;
end if;
wait;
end process;
end arch;