Debian Codegraph @

examples/gw5a/lut8.v

raw
1 /********************************************
2 Two PMODs will be required - seven-segment indicators and pushbuttons with switches.
3 Connect them as shown in the photo: apuicula/doc/fig/tangprimer25-lut-test.jpeg
4 ********************************************/
5 `default_nettype none
6
7 (* top *)
8 module top(input wire resetn, input wire key_i, input wire [7:0]pmod_keys, output wire [7:0]led);
9 wire key = key_i ^ `INV_BTN;
10
11 wire [7:0]w;
12 assign led = {~w[5], ~w[6], ~w[4:3], ~w[1:0], ~w[2], w[7]};
13
14 llut8 l8(
15 .cnst0(resetn),
16 .cnst1(key),
17 .inp(pmod_keys),
18 .out(w)
19 );
20
21 endmodule
22
23 module llut8(input wire cnst0, input wire cnst1, input wire [7:0]inp, output wire [7:0]out);
24 wire [15:0]w;
25
26 llut7a l7a(
27 .cnst0(cnst0),
28 .cnst1(cnst1),
29 .inp(inp),
30 .out(w[7:0])
31 );
32
33 llut7a l7b(
34 .cnst0(cnst0),
35 .cnst1(cnst1),
36 .inp({inp[7:4], inp[2:0], inp[3]}),
37 .out(w[15:8])
38 );
39
40 MUX2_LUT8 m2l7A(
41 .I0(w[0]),
42 .I1(w[8]),
43 .S0(~inp[7]),
44 .O(out[0])
45 );
46
47 MUX2_LUT8 m2l6B(
48 .I0(w[1]),
49 .I1(w[9]),
50 .S0(~inp[7]),
51 .O(out[1])
52 );
53
54 MUX2_LUT8 m2l6C(
55 .I0(w[2]),
56 .I1(w[10]),
57 .S0(~inp[7]),
58 .O(out[2])
59 );
60
61 MUX2_LUT8 m2l6D(
62 .I0(w[3]),
63 .I1(w[11]),
64 .S0(~inp[7]),
65 .O(out[3])
66 );
67
68 MUX2_LUT8 m2l6E(
69 .I0(w[4]),
70 .I1(w[12]),
71 .S0(~inp[7]),
72 .O(out[4])
73 );
74
75 MUX2_LUT8 m2l6F(
76 .I0(w[5]),
77 .I1(w[13]),
78 .S0(~inp[7]),
79 .O(out[5])
80 );
81
82 MUX2_LUT8 m2l6G(
83 .I0(w[6]),
84 .I1(w[14]),
85 .S0(~inp[7]),
86 .O(out[6])
87 );
88
89 MUX2_LUT8 m2l6SEL(
90 .I0(w[7]),
91 .I1(w[15]),
92 .S0(~inp[7]),
93 .O(out[7])
94 );
95 endmodule
96
97 module llut7a(input wire cnst0, input wire cnst1, input wire [7:0]inp, output wire [7:0]out);
98 wire [15:0]w;
99
100 llut6a l6a(
101 .cnst0(cnst0),
102 .cnst1(cnst1),
103 .inp(inp),
104 .out(w[7:0])
105 );
106
107 llut6a l6b(
108 .cnst0(cnst0),
109 .cnst1(cnst1),
110 .inp(~inp),
111 .out(w[15:8])
112 );
113
114 MUX2_LUT7 m2l7A(
115 .I0(w[0]),
116 .I1(w[8]),
117 .S0(~inp[6]),
118 .O(out[0])
119 );
120
121 MUX2_LUT7 m2l7B(
122 .I0(w[1]),
123 .I1(w[9]),
124 .S0(~inp[6]),
125 .O(out[1])
126 );
127
128 MUX2_LUT7 m2l7C(
129 .I0(w[2]),
130 .I1(w[10]),
131 .S0(~inp[6]),
132 .O(out[2])
133 );
134
135 MUX2_LUT7 m2l7D(
136 .I0(w[3]),
137 .I1(w[11]),
138 .S0(~inp[6]),
139 .O(out[3])
140 );
141
142 MUX2_LUT7 m2l7E(
143 .I0(w[4]),
144 .I1(w[12]),
145 .S0(~inp[6]),
146 .O(out[4])
147 );
148
149 MUX2_LUT7 m2l7F(
150 .I0(w[5]),
151 .I1(w[13]),
152 .S0(~inp[6]),
153 .O(out[5])
154 );
155
156 MUX2_LUT7 m2l7G(
157 .I0(w[6]),
158 .I1(w[14]),
159 .S0(~inp[6]),
160 .O(out[6])
161 );
162
163 MUX2_LUT7 m2l7SEL(
164 .I0(w[7]),
165 .I1(w[15]),
166 .S0(~inp[6]),
167 .O(out[7])
168 );
169 endmodule
170
171 module llut6a(input wire cnst0, input wire cnst1, input wire [7:0]inp, output wire [7:0]out);
172 wire [17:0]w;
173
174 llut5a l5a(
175 .cnst0(cnst0),
176 .cnst1(cnst1),
177 .inp(inp),
178 .out(w[7:0])
179 );
180
181 llut5m l5b(
182 .cnst0(cnst0),
183 .cnst1(cnst1),
184 .inp(inp),
185 .out(w[15:8])
186 );
187
188 // straight <-> mirror
189 MUX2_LUT6 m2l6A(
190 .I0(w[0]),
191 .I1(w[8]),
192 .S0(~inp[5]),
193 .O(out[0])
194 );
195
196 MUX2_LUT6 m2l6B(
197 .I0(w[1]),
198 .I1(w[9]),
199 .S0(~inp[5]),
200 .O(out[1])
201 );
202
203 MUX2_LUT6 m2l6C(
204 .I0(w[2]),
205 .I1(w[10]),
206 .S0(~inp[5]),
207 .O(out[2])
208 );
209
210 MUX2_LUT6 m2l6D(
211 .I0(w[3]),
212 .I1(w[11]),
213 .S0(~inp[5]),
214 .O(out[3])
215 );
216
217 MUX2_LUT6 m2l6E(
218 .I0(w[4]),
219 .I1(w[12]),
220 .S0(~inp[5]),
221 .O(out[4])
222 );
223
224 MUX2_LUT6 m2l6F(
225 .I0(w[5]),
226 .I1(w[13]),
227 .S0(~inp[5]),
228 .O(out[5])
229 );
230
231 MUX2_LUT6 m2l6G(
232 .I0(w[6]),
233 .I1(w[14]),
234 .S0(~inp[5]),
235 .O(out[6])
236 );
237
238 MUX2_LUT6 m2l6SEL(
239 .I0(w[7]),
240 .I1(w[15]),
241 .S0(~inp[5]),
242 .O(out[7])
243 );
244 endmodule
245
246 module llut5a(input wire cnst0, input wire cnst1, input wire [7:0]inp, output wire [7:0]out);
247 wire [17:0]w;
248
249 llut4a l4a0(
250 .inp(inp),
251 .out(w[7:0]),
252 );
253 llut4a l4a1(
254 .inp(inp),
255 .out(w[15:8]),
256 );
257
258 MUX2_LUT5 m2l5A(
259 .I0(w[0]),
260 .I1(w[8]),
261 .S0(~inp[4]),
262 .O(out[0])
263 );
264 MUX2_LUT5 m2l5B(
265 .I0(w[1]),
266 .I1(w[9]),
267 .S0(~inp[4]),
268 .O(out[1])
269 );
270 MUX2_LUT5 m2l5C(
271 .I0(w[2]),
272 .I1(w[10]),
273 .S0(~inp[4]),
274 .O(out[2])
275 );
276 MUX2_LUT5 m2l5D(
277 .I0(w[3]),
278 .I1(w[11]),
279 .S0(~inp[4]),
280 .O(out[3])
281 );
282 MUX2_LUT5 m2l5E(
283 .I0(w[4]),
284 .I1(w[12]),
285 .S0(~inp[4]),
286 .O(out[4])
287 );
288 MUX2_LUT5 m2l5F(
289 .I0(w[5]),
290 .I1(w[13]),
291 .S0(~inp[4]),
292 .O(out[5])
293 );
294 MUX2_LUT5 m2l5G(
295 .I0(w[6]),
296 .I1(w[14]),
297 .S0(~inp[4]),
298 .O(out[6])
299 );
300 MUX2_LUT5 m2l5S0EL(
301 .I0(w[16]),
302 .I1(w[17]),
303 .S0(~inp[4]),
304 .O(out[7])
305 );
306
307 LUT1 vcc_lut(
308 .I0(cnst1),
309 .F(w[16])
310 );
311 defparam vcc_lut.INIT=2'b01;
312
313 LUT1 vss_lut(
314 .I0(cnst0),
315 .F(w[17])
316 );
317 defparam vss_lut.INIT=2'b10;
318 endmodule
319
320 module llut5m(input wire cnst0, input wire cnst1, input wire [7:0]inp, output wire [7:0]out);
321 wire [17:0]w;
322
323 llut4m l4a0(
324 .inp(inp),
325 .out(w[7:0]),
326 );
327 llut4m l4a1(
328 .inp(inp),
329 .out(w[15:8]),
330 );
331
332 MUX2_LUT5 m2l5A(
333 .I0(w[0]),
334 .I1(w[8]),
335 .S0(~inp[4]),
336 .O(out[0])
337 );
338 MUX2_LUT5 m2l5B(
339 .I0(w[1]),
340 .I1(w[9]),
341 .S0(~inp[4]),
342 .O(out[1])
343 );
344 MUX2_LUT5 m2l5C(
345 .I0(w[2]),
346 .I1(w[10]),
347 .S0(~inp[4]),
348 .O(out[2])
349 );
350 MUX2_LUT5 m2l5D(
351 .I0(w[3]),
352 .I1(w[11]),
353 .S0(~inp[4]),
354 .O(out[3])
355 );
356 MUX2_LUT5 m2l5E(
357 .I0(w[4]),
358 .I1(w[12]),
359 .S0(~inp[4]),
360 .O(out[4])
361 );
362 MUX2_LUT5 m2l5F(
363 .I0(w[5]),
364 .I1(w[13]),
365 .S0(~inp[4]),
366 .O(out[5])
367 );
368 MUX2_LUT5 m2l5G(
369 .I0(w[6]),
370 .I1(w[14]),
371 .S0(~inp[4]),
372 .O(out[6])
373 );
374 MUX2_LUT5 m2l5S0EL(
375 .I0(w[16]),
376 .I1(w[17]),
377 .S0(~inp[4]),
378 .O(out[7])
379 );
380
381 LUT1 vcc_lut(
382 .I0(cnst1),
383 .F(w[16])
384 );
385 defparam vcc_lut.INIT=2'b01;
386
387 LUT1 vss_lut(
388 .I0(cnst0),
389 .F(w[17])
390 );
391 defparam vss_lut.INIT=2'b10;
392 endmodule
393
394 module llut4a(input wire [7:0]inp, output wire [7:0]out);
395 // *********************
396 // normal 0
397 LUT4 l4A(
398 .I0(!inp[0]),
399 .I1(!inp[1]),
400 .I2(!inp[2]),
401 .I3(!inp[3]),
402 .F(out[0])
403 );
404 defparam l4A.INIT=16'b1101_0111_1110_1101;
405
406 LUT4 l4B(
407 .I0(!inp[0]),
408 .I1(!inp[1]),
409 .I2(!inp[2]),
410 .I3(!inp[3]),
411 .F(out[1])
412 );
413 defparam l4B.INIT=16'b0010_0111_1001_1111;
414
415 LUT4 l4C(
416 .I0(!inp[0]),
417 .I1(!inp[1]),
418 .I2(!inp[2]),
419 .I3(!inp[3]),
420 .F(out[2])
421 );
422 defparam l4C.INIT=16'b0010_1111_1111_1011;
423
424 LUT4 l4D(
425 .I0(!inp[0]),
426 .I1(!inp[1]),
427 .I2(!inp[2]),
428 .I3(!inp[3]),
429 .F(out[3])
430 );
431 defparam l4D.INIT=16'b0111_1001_0110_1101;
432
433 LUT4 l4E(
434 .I0(!inp[0]),
435 .I1(!inp[1]),
436 .I2(!inp[2]),
437 .I3(!inp[3]),
438 .F(out[4])
439 );
440 defparam l4E.INIT=16'b1111_1101_0100_0101;
441
442 LUT4 l4F(
443 .I0(!inp[0]),
444 .I1(!inp[1]),
445 .I2(!inp[2]),
446 .I3(!inp[3]),
447 .F(out[5])
448 );
449 defparam l4F.INIT=16'b1101_1111_0111_0001;
450
451 LUT4 l4G(
452 .I0(!inp[0]),
453 .I1(!inp[1]),
454 .I2(!inp[2]),
455 .I3(!inp[3]),
456 .F(out[6])
457 );
458 defparam l4G.INIT=16'b1110_1111_0111_1100;
459 endmodule
460
461 module llut4m(input wire [7:0]inp, output wire [7:0]out);
462 // *********************************
463 // upside down 0
464 LUT4 l4AU(
465 .I0(!inp[0]),
466 .I1(!inp[1]),
467 .I2(!inp[2]),
468 .I3(!inp[3]),
469 .F(out[0])
470 );
471 defparam l4AU.INIT=16'b0111_1001_0110_1101;
472
473 LUT4 l4BU(
474 .I0(!inp[0]),
475 .I1(!inp[1]),
476 .I2(!inp[2]),
477 .I3(!inp[3]),
478 .F(out[1])
479 );
480 defparam l4BU.INIT=16'b1111_1101_0100_0101;
481
482 LUT4 l4CU(
483 .I0(!inp[0]),
484 .I1(!inp[1]),
485 .I2(!inp[2]),
486 .I3(!inp[3]),
487 .F(out[2])
488 );
489 defparam l4CU.INIT=16'b1101_1111_0111_0001;
490
491 LUT4 l4DU(
492 .I0(!inp[0]),
493 .I1(!inp[1]),
494 .I2(!inp[2]),
495 .I3(!inp[3]),
496 .F(out[3])
497 );
498 defparam l4DU.INIT=16'b1101_0111_1110_1101;
499
500 LUT4 l4EU(
501 .I0(!inp[0]),
502 .I1(!inp[1]),
503 .I2(!inp[2]),
504 .I3(!inp[3]),
505 .F(out[4])
506 );
507 defparam l4EU.INIT=16'b0010_0111_1001_1111;
508
509 LUT4 l4FU(
510 .I0(!inp[0]),
511 .I1(!inp[1]),
512 .I2(!inp[2]),
513 .I3(!inp[3]),
514 .F(out[5])
515 );
516 defparam l4FU.INIT=16'b0010_1111_1111_1011;
517
518 LUT4 l4GU(
519 .I0(!inp[0]),
520 .I1(!inp[1]),
521 .I2(!inp[2]),
522 .I3(!inp[3]),
523 .F(out[6])
524 );
525 defparam l4GU.INIT=16'b1110_1111_0111_1100;
526 endmodule
527