forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path74155-tb.v
300 lines (278 loc) · 6.98 KB
/
74155-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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Test: Dual 2-line to 4-line decoder/demultiplexer (inverted outputs)
module test;
`TBASSERT_METHOD(tbassert)
`TBASSERT_2_METHOD(tbassert2)
localparam BLOCKS_DIFFERENT = 2;
localparam WIDTH_OUT = 8;
localparam WIDTH_IN = $clog2(WIDTH_OUT); // do not pass this to the module because
// it is dependent value
// DUT inputs
reg Enable1C;
reg Enable1G_bar;
reg Enable2C_bar;
reg Enable2G_bar;
reg [WIDTH_IN-1:0] A;
// DUT outputs
wire [WIDTH_OUT*BLOCKS_DIFFERENT-1:0] Y;
// DUT
ttl_74155 #(.BLOCKS_DIFFERENT(BLOCKS_DIFFERENT), .WIDTH_OUT(WIDTH_OUT),
.DELAY_RISE(5), .DELAY_FALL(3)) dut(
.Enable1C(Enable1C),
.Enable1G_bar(Enable1G_bar),
.Enable2C_bar(Enable2C_bar),
.Enable2G_bar(Enable2G_bar),
.A(A),
.Y_2D(Y)
);
initial
begin
reg [WIDTH_OUT-1:0] Block1;
reg [WIDTH_OUT-1:0] Block2;
reg [WIDTH_OUT-1:0] Y_expected;
integer i;
$dumpfile("74155-tb.vcd");
$dumpvars;
// select Addr 0: enabled -> first output is 0
Enable1C = 1'b1;
Enable1G_bar = 1'b0;
Enable2C_bar = 1'b0;
Enable2G_bar = 1'b0;
A = 3'b000;
#6
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111110, "Test 1");
tbassert(Block2 == 8'b11111110, "Test 1");
#0
// select Addr 0: disabled in first BLOCK -> output is 1s where disabled
Enable1C = 1'b0;
#6
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 2");
tbassert(Block2 == 8'b11111110, "Test 2");
#0
// select Addr 0: disabled in second BLOCK, enabled in first BLOCK
Enable1C = 1'b1;
Enable2C_bar = 1'b1;
#6
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111110, "Test 3");
tbassert(Block2 == 8'b11111111, "Test 3");
#0
// select Addr 0: disabled by the other enable input in second BLOCK, enabled in first BLOCK
Enable2C_bar = 1'b0;
Enable2G_bar = 1'b1;
#6
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111110, "Test 4");
tbassert(Block2 == 8'b11111111, "Test 4");
#0
// select Addr 1: disabled
Enable1C = 1'b0;
Enable1G_bar = 1'b1;
Enable2C_bar = 1'b1;
Enable2G_bar = 1'b1;
A = 3'b001;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 5");
tbassert(Block2 == 8'b11111111, "Test 5");
#0
// select Addr 1: enabled in second BLOCK -> second output is 0 where enabled
Enable2C_bar = 1'b0;
Enable2G_bar = 1'b0;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 6");
tbassert(Block2 == 8'b11111101, "Test 6");
#0
// select Addr 1: enabled in second BLOCK, disabled by only one enable input in first BLOCK
Enable1G_bar = 1'b0;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 7");
tbassert(Block2 == 8'b11111101, "Test 7");
#0
// select Addr 1: enabled in second BLOCK, disabled by the other enable input in first BLOCK
Enable1C = 1'b1;
Enable1G_bar = 1'b1;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 8");
tbassert(Block2 == 8'b11111101, "Test 8");
#0
// select Addr 1: from enabled to disabled in both BLOCKs -> output 1s
Enable1G_bar = 1'b0;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111101, "Test 9");
tbassert(Block2 == 8'b11111101, "Test 9");
#0
Enable1C = 1'b0;
Enable2G_bar = 1'b1;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 9");
tbassert(Block2 == 8'b11111111, "Test 9");
#0
// while disabled in both BLOCKs: all enable inputs transition from previous with null change to
// output 1s
Enable1C = 1'b1;
Enable1G_bar = 1'b1;
Enable2C_bar = 1'b0;
Enable2G_bar = 1'b1;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 10");
tbassert(Block2 == 8'b11111111, "Test 10");
#0
Enable1C = 1'b0;
Enable1G_bar = 1'b0;
Enable2C_bar = 1'b1;
Enable2G_bar = 1'b0;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 10");
tbassert(Block2 == 8'b11111111, "Test 10");
#0
// select Addr 1: from disabled to enabled in both BLOCKs -> second output is 0
Enable1C = 1'b1;
Enable2C_bar = 1'b0;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111101, "Test 11");
tbassert(Block2 == 8'b11111101, "Test 11");
#0
// while enabled: change to select Addr 7 from select Addr 1 -> highest output is 0
A = 3'b111;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b01111111, "Test 12");
tbassert(Block2 == 8'b01111111, "Test 12");
#0
// repeat tests: while enabled: change to select Addr n-1 from select Addr n
for (i = 6; i >= 0; i--)
begin
A = i;
case (i)
6:
begin
Y_expected = 8'b10111111;
end
5:
begin
Y_expected = 8'b11011111;
end
4:
begin
Y_expected = 8'b11101111;
end
3:
begin
Y_expected = 8'b11110111;
end
2:
begin
Y_expected = 8'b11111011;
end
1:
begin
Y_expected = 8'b11111101;
end
0:
begin
Y_expected = 8'b11111110;
end
endcase
#10
{Block2, Block1} = Y;
tbassert2(Block1 == Y_expected, "Test", (7 - i), "13");
tbassert2(Block2 == Y_expected, "Test", (7 - i), "13");
end
// end repeat tests
#0
// repeat tests: while enabled only in second BLOCK: change to select Addr n-1 from select Addr n
Enable1C = 1'b0;
for (i = 6; i >= 0; i--)
begin
A = i;
case (i)
6:
begin
Y_expected = 8'b10111111;
end
5:
begin
Y_expected = 8'b11011111;
end
4:
begin
Y_expected = 8'b11101111;
end
3:
begin
Y_expected = 8'b11110111;
end
2:
begin
Y_expected = 8'b11111011;
end
1:
begin
Y_expected = 8'b11111101;
end
0:
begin
Y_expected = 8'b11111110;
end
endcase
#10
{Block2, Block1} = Y;
tbassert2(Block1 == 8'b11111111, "Test", (7 - i), "14");
tbassert2(Block2 == Y_expected, "Test", (7 - i), "14");
end
// end repeat tests
#0
// while disabled: change to select Addr 5 from select Addr 0 with null change to output 1s
Enable1C = 1'b0;
Enable1G_bar = 1'b1;
Enable2C_bar = 1'b1;
Enable2G_bar = 1'b1;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 15");
tbassert(Block2 == 8'b11111111, "Test 15");
#0
A = 3'b101;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 15");
tbassert(Block2 == 8'b11111111, "Test 15");
#0
// all input select bits transition from previous with null change to output 1s
A = 3'b010;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111111, "Test 16");
tbassert(Block2 == 8'b11111111, "Test 16");
#0
// all input select bits and all enable bits transition from previous -> sixth output is 0
Enable1C = 1'b1;
Enable1G_bar = 1'b0;
Enable2C_bar = 1'b0;
Enable2G_bar = 1'b0;
A = 3'b101;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11011111, "Test 17");
tbassert(Block2 == 8'b11011111, "Test 17");
#0
// all input select bits transition from previous -> third output is 0
A = 3'b010;
#10
{Block2, Block1} = Y;
tbassert(Block1 == 8'b11111011, "Test 18");
tbassert(Block2 == 8'b11111011, "Test 18");
#10
$finish;
end
endmodule