forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
74158-tb.v
231 lines (220 loc) · 5.01 KB
/
74158-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
// Test: Quad 2-input multiplexer (inverted outputs)
module test;
`TBASSERT_METHOD(tbassert)
localparam BLOCKS = 3;
localparam WIDTH_IN = 2;
localparam WIDTH_SELECT = $clog2(WIDTH_IN); // do not pass this to the module because
// it is dependent value
// DUT inputs
reg Enable_bar;
reg [WIDTH_SELECT-1:0] Select; // Select is one bit
reg [BLOCKS*WIDTH_IN-1:0] A;
// DUT outputs
wire [BLOCKS-1:0] Y_bar;
// DUT
ttl_74158 #(.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)
);
localparam SELECT_A = 1'b0;
localparam SELECT_B = 1'b1;
initial
begin
reg [BLOCKS-1:0] AInputs;
reg [BLOCKS-1:0] BInputs;
$dumpfile("74158-tb.vcd");
$dumpvars;
// select A: enabled
Enable_bar = 1'b0;
Select = SELECT_A;
AInputs = 3'b011;
BInputs = 3'b111;
A = {BInputs, AInputs};
#6
tbassert(Y_bar == 3'b100, "Test 1");
#0
// select A: disabled -> output 1s
Enable_bar = 1'b1;
#6
tbassert(Y_bar == 3'b111, "Test 2");
#0
// select B: disabled
Select = SELECT_B;
#10
tbassert(Y_bar == 3'b111, "Test 3");
#0
// select B: enabled
Enable_bar = 1'b0;
#10
tbassert(Y_bar == 3'b000, "Test 4");
#0
// while enabled: change to select A from select B
Select = SELECT_A;
#10
tbassert(Y_bar == 3'b100, "Test 5");
#0
// while select A enabled: change to different inputs
AInputs = 3'b111;
BInputs = 3'b001;
A = {BInputs, AInputs};
#10
tbassert(Y_bar == 3'b000, "Test 6");
#0
// while enabled: change to select B from select A
Select = SELECT_B;
#10
tbassert(Y_bar == 3'b110, "Test 7");
#0
// select B: disabled
Enable_bar = 1'b1;
#6
tbassert(Y_bar == 3'b111, "Test 8");
#0
// select A: disabled
Select = SELECT_A;
#10
tbassert(Y_bar == 3'b111, "Test 9");
#0
// select A: enabled and change to different inputs with null effect on output 1s
Enable_bar = 1'b0;
AInputs = 3'b000;
A = {BInputs, AInputs};
#10
tbassert(Y_bar == 3'b111, "Test 10");
#0
// select B: enabled with null change to output 1s
Select = SELECT_B;
AInputs = 3'b010;
BInputs = 3'b000;
A = {BInputs, AInputs};
#10
tbassert(Y_bar == 3'b111, "Test 11");
#0
// select B: all output bits transition from previous, direct from inputs
BInputs = 3'b111;
A = {BInputs, AInputs};
#6
tbassert(Y_bar == 3'b000, "Test 12");
#0
// all output bits transition from previous, direct from select A
AInputs = 3'b011;
BInputs = 3'b110;
A = {BInputs, AInputs};
#6
tbassert(Y_bar == 3'b001, "Test 13");
#0
Select = SELECT_A;
#6
tbassert(Y_bar == 3'b100, "Test 13");
#0
// select A: all output bits transition from previous, on disable
AInputs = 3'b111;
A = {BInputs, AInputs};
#6
tbassert(Y_bar == 3'b000, "Test 14");
#0
Enable_bar = 1'b1;
#10
tbassert(Y_bar == 3'b111, "Test 14");
#0
// while enabled: change to select B from select A and change to different inputs
// with null effect on output 0s
Enable_bar = 1'b0;
#6
tbassert(Y_bar == 3'b000, "Test 15");
#10
Select = SELECT_B;
AInputs = {BLOCKS{1'b0}};
BInputs = {BLOCKS{1'b1}};
A = {BInputs, AInputs};
#10
tbassert(Y_bar == 3'b000, "Test 15");
#0
// timing: while enabled, clear/set inputs, then must wait for outputs to transition
Enable_bar = 1'b0;
Select = 1'bx;
AInputs = {BLOCKS{1'bx}};
BInputs = {BLOCKS{1'bx}};
A = {BInputs, AInputs};
#10
Select = SELECT_A;
AInputs = 3'b011;
BInputs = 3'b101;
A = {BInputs, AInputs};
#2
tbassert(Y_bar === 3'bxxx, "Test 16");
#3
tbassert(Y_bar == 3'b100, "Test 16");
#0
// timing: while enabled, clear/set inputs, then must wait for outputs to transition,
// off the select input only
Enable_bar = 1'b0;
Select = 1'bx;
AInputs = {BLOCKS{1'bx}};
BInputs = {BLOCKS{1'bx}};
A = {BInputs, AInputs};
#10
AInputs = 3'b011;
BInputs = 3'b101;
A = {BInputs, AInputs};
#6
Select = SELECT_A;
#2
tbassert(Y_bar === 3'bxxx, "Test 17");
#3
tbassert(Y_bar == 3'b100, "Test 17");
#0
// timing: same, other select
Enable_bar = 1'b0;
Select = 1'bx;
AInputs = {BLOCKS{1'bx}};
BInputs = {BLOCKS{1'bx}};
A = {BInputs, AInputs};
#10
AInputs = 3'b110;
BInputs = 3'b111;
A = {BInputs, AInputs};
#6
Select = SELECT_B;
#2
tbassert(Y_bar === 3'bxxx, "Test 18");
#3
tbassert(Y_bar == 3'b000, "Test 18");
#0
// timing: while enabled, clear/set inputs, then must wait for outputs to transition,
// off the data inputs only
Select = 1'bx;
AInputs = {BLOCKS{1'bx}};
BInputs = {BLOCKS{1'bx}};
A = {BInputs, AInputs};
#10
Select = SELECT_B;
#6
AInputs = 3'b011;
BInputs = 3'b101;
A = {BInputs, AInputs};
#2
tbassert(Y_bar === 3'bxxx, "Test 19");
#3
tbassert(Y_bar == 3'b010, "Test 19");
#0
// timing: same, other select (with only the selected data input being set)
Select = 1'bx;
AInputs = {BLOCKS{1'bx}};
BInputs = {BLOCKS{1'bx}};
A = {BInputs, AInputs};
#10
Select = SELECT_A;
#6
AInputs = 3'b011;
A = {BInputs, AInputs};
#2
tbassert(Y_bar === 3'bxxx, "Test 20");
#3
tbassert(Y_bar == 3'b100, "Test 20");
#10
$finish;
end
endmodule