forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path74352-tb.v
195 lines (185 loc) · 4.49 KB
/
74352-tb.v
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
188
189
190
191
192
193
194
195
// Test: Dual 4-input multiplexer (inverted outputs)
module test;
`TBASSERT_METHOD(tbassert)
localparam BLOCKS = 3;
localparam WIDTH_IN = 4;
localparam WIDTH_SELECT = $clog2(WIDTH_IN); // do not pass this to the module because
// it is dependent value
// DUT inputs
reg [BLOCKS-1:0] Enable_bar;
reg [WIDTH_SELECT-1:0] Select; // Select is two bits, full range 2'b00 to 2'b11
reg [WIDTH_IN*BLOCKS-1:0] A;
// DUT outputs
wire [BLOCKS-1:0] Y_bar;
// DUT
ttl_74352 #(.BLOCKS(BLOCKS), .WIDTH_IN(WIDTH_IN), .DELAY_RISE(5), .DELAY_FALL(3)) dut(
.Enable_bar(Enable_bar),
.Select(Select),
.A_2D(A),
.Y_bar(Y_bar)
);
initial
begin
reg [WIDTH_IN-1:0] Block1;
reg [WIDTH_IN-1:0] Block2;
reg [WIDTH_IN-1:0] Block3;
$dumpfile("74352-tb.vcd");
$dumpvars;
// select A: enabled
Enable_bar = {BLOCKS{1'b0}};
Select = 2'b00;
Block1 = 4'b0111;
Block2 = 4'b0011;
Block3 = 4'b1110;
A = {Block3, Block2, Block1};
#6
tbassert(Y_bar == 3'b100, "Test 1");
#0
// select A: disabled in first BLOCK -> output is 1s where disabled
Enable_bar[0] = 1'b1;
#6
tbassert(Y_bar == 3'b101, "Test 2");
#0
// select A: disabled in second BLOCK, enabled in first BLOCK
Enable_bar[0] = 1'b0;
Enable_bar[1] = 1'b1;
#6
tbassert(Y_bar == 3'b110, "Test 3");
#0
// select B: disabled
Enable_bar = {BLOCKS{1'b1}};
Select = 2'b01;
#10
tbassert(Y_bar == 3'b111, "Test 4");
#0
// select B: enabled in second and third BLOCKs
Enable_bar[1] = 1'b0;
Enable_bar[2] = 1'b0;
#10
tbassert(Y_bar == 3'b001, "Test 5");
#0
// select A: enabled in second and third BLOCKs
Select = 2'b00;
#10
tbassert(Y_bar == 3'b101, "Test 6");
#0
// select D: enabled in second and third BLOCKs
Select = 2'b11;
#10
tbassert(Y_bar == 3'b011, "Test 7");
#0
// select D: enabled
Enable_bar[0] = 1'b0;
#10
tbassert(Y_bar == 3'b011, "Test 8");
#0
// while select D enabled: change to different inputs
Block1 = 4'b1111;
Block2 = 4'b0111;
Block3 = 4'b0111;
A = {Block3, Block2, Block1};
#10
tbassert(Y_bar == 3'b110, "Test 9");
#0
// while enabled: change to select C from select D
Select = 2'b10;
#10
tbassert(Y_bar == 3'b000, "Test 10");
#0
// select C: disabled in first BLOCK
Enable_bar[0] = 1'b1;
#6
tbassert(Y_bar == 3'b001, "Test 11");
#0
// select A: disabled in first and third BLOCKs
Enable_bar[2] = 1'b1;
Select = 2'b00;
#10
tbassert(Y_bar == 3'b101, "Test 12");
#0
// select A: enabled and change to different inputs with null effect on output 1s
Enable_bar = {BLOCKS{1'b0}};
Block1 = 4'b1110;
Block2 = 4'b0110;
Block3 = 4'b0110;
A = {Block3, Block2, Block1};
#10
tbassert(Y_bar == 3'b111, "Test 13");
#0
// select B: enabled with null change to output 1s
Select = 2'b01;
Block1 = 4'b1100;
Block2 = 4'b0101;
Block3 = 4'b0100;
A = {Block3, Block2, Block1};
#10
tbassert(Y_bar == 3'b111, "Test 14");
#0
// select B: all output bits transition from previous, direct from inputs
Block1 = 4'b1110;
Block2 = 4'b0111;
Block3 = 4'b0110;
A = {Block3, Block2, Block1};
#6
tbassert(Y_bar == 3'b000, "Test 15");
#0
// all output bits transition from previous, direct from select D
Block1 = 4'b1100;
Block2 = 4'b0111;
Block3 = 4'b0110;
A = {Block3, Block2, Block1};
#6
tbassert(Y_bar == 3'b001, "Test 16");
#0
Select = 2'b11;
#6
tbassert(Y_bar == 3'b110, "Test 16");
#0
// select D: all output bits transition from previous, on disable
Block1 = 4'b1100;
Block2 = 4'b1111;
Block3 = 4'b1110;
A = {Block3, Block2, Block1};
#6
tbassert(Y_bar == 3'b000, "Test 17");
#0
Enable_bar = {BLOCKS{1'b1}};
#10
tbassert(Y_bar == 3'b111, "Test 17");
#0
// while enabled: change to select B from select D and change to different inputs
// with null effect on output 0s
Enable_bar = {BLOCKS{1'b0}};
#6
tbassert(Y_bar == 3'b000, "Test 18");
#10
Select = 2'b01;
Block1 = 4'b0010;
Block2 = 4'b0011;
Block3 = 4'b0010;
A = {Block3, Block2, Block1};
#10
tbassert(Y_bar == 3'b000, "Test 18");
#0
// while enabled in second and third BLOCKs: change to select A from select B and
// change to different inputs with null effect on output 0s
Enable_bar = 3'b001;
#6
tbassert(Y_bar == 3'b001, "Test 19");
#10
Select = 2'b00;
Block1 = 4'b0011;
Block2 = 4'b0001;
Block3 = 4'b0001;
A = {Block3, Block2, Block1};
#10
tbassert(Y_bar == 3'b001, "Test 19");
#0
// while enabled in second and third BLOCKs: change back to select B from select A
Select = 2'b01;
#10
tbassert(Y_bar == 3'b111, "Test 20");
#10
$finish;
end
endmodule