-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprim_sim.sv
executable file
·20256 lines (18038 loc) · 691 KB
/
prim_sim.sv
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ===========Oooo==========================================Oooo========
// = Copyright (C) 2014-2024 Gowin Semiconductor Technology Co.,Ltd.
// = All rights reserved.
// =====================================================================
//
// __ __ __
// \ \ / \ / / [File name ] prim_sim.v
// \ \ / /\ \ / / [Description ] GW5AT verilog functional simulation library
// \ \/ / \ \/ / [Timestamp ] Fri November 4 11:00:30 2022
// \ / \ / [version ] 1.9.10
// \/ \/
//
// ===========Oooo==========================================Oooo========
`timescale 1ns / 1ps
// verilator lint_off DECLFILENAME
// verilator lint_off IMPLICIT
// verilator lint_off DEFPARAM
// MUX2
primitive mux2 (O, I0, I1, S);
output O;
input I0, I1, S;
table
// I0 I1 S O
0 ? 0 : 0 ;
1 ? 0 : 1 ;
x ? 0 : x ;
? 0 1 : 0 ;
? 1 1 : 1 ;
? x 1 : x ;
0 0 x : 0 ;
0 1 x : x ;
1 0 x : x ;
1 1 x : 1 ;
? x x : x ;
x ? x : x ;
endtable
endprimitive
// MUXes
module MUX2 (O, I0, I1, S0);
input I0,I1;
input S0;
output O;
mux2 mux2_0 (O, I0, I1, S0);
endmodule //MUX2
module MUX2_LUT5 (O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_lut5 (O, I0, I1, S0);
endmodule //MUX2 LUT_5: use two 4-input LUTs and 1 MUX2_LUT_5 to construct 5-input LUT
module MUX2_LUT6 (O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_lut6 (O, I0, I1, S0);
endmodule //MUX2 LUT_6: use two 5-input LUTs and 1 MUX2_LUT_6 to construct 6-input LUT
module MUX2_LUT7 (O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_lut7 (O, I0, I1, S0);
endmodule //MUX2 LUT_7: use two 6-input LUTs and 1 MUX2_LUT_7 to construct 7-input LUT
module MUX2_LUT8 (O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_lut8 (O, I0, I1, S0);
endmodule //MUX2 LUT_8: use two 7-input LUTs and 1 MUX2_LUT_8 to construct 8-input LUT
module MUX2_MUX8(O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_mux8 (O, I0, I1, S0);
endmodule // MUX2_MUX8:use two 4-input MUXs and 1 MUX2_MUX8's to construct 8-input mux
module MUX2_MUX16(O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_mux16 (O, I0, I1, S0);
endmodule //MUX2_MUX16:use two 8-input MUXs and 1 MUX2_MUX8's to construct 16-input mux
module MUX2_MUX32(O, I0, I1, S0);
input I0,I1;
input S0;
output O;
MUX2 mux2_mux32 (O, I0, I1, S0);
endmodule //MUX2_MUX32:use two 16-input MUXs and 1 MUX2_MUX16's to construct 32-input mux
module MUX4 (O, I0, I1, I2, I3, S0, S1);
input I0, I1, I2, I3;
input S0, S1;
output O;
wire O1,O2;
MUX2 mux2_1(O1, I0, I1, S0);
MUX2 mux2_2(O2, I2, I3, S0);
MUX2 mux2_0(O, O1, O2, S1);
endmodule // MUX4
module MUX8 (O, I0, I1, I2, I3, I4, I5, I6, I7, S0, S1, S2);
input I0, I1, I2, I3, I4, I5, I6, I7;
input S0, S1, S2;
output O;
wire O1, O2;
MUX4 mux4_1(O1, I0, I1, I2, I3, S0, S1);
MUX4 mux4_2(O2, I4, I5, I6, I7, S0, S1);
MUX2 mux2_0(O, O1, O2, S2);
endmodule //MUX8
module MUX16(O, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, S0, S1, S2, S3);
input I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15;
input S0, S1, S2, S3;
output O;
wire O1, O2;
MUX8 mux8_1(O1, I0, I1, I2, I3, I4, I5, I6, I7, S0, S1, S2);
MUX8 mux8_2(O2, I8, I9, I10, I11, I12, I13, I14, I15, S0, S1, S2);
MUX2 mux2_o(O, O1, O2, S3);
endmodule
module MUX32(O, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15,
I16, I17, I18, I19, I20, I21, I22, I23, I24, I25, I26, I27, I28, I29, I30,
I31, S0, S1, S2, S3, S4
);
input I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19, I20, I21, I22, I23, I24, I25, I26, I27, I28, I29, I30, I31;
input S0, S1, S2, S3, S4;
output O;
wire O1, O2;
MUX16 mux16_1(O1, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, S0, S1, S2, S3);
MUX16 mux16_2(O2, I16, I17, I18, I19, I20, I21, I22, I23, I24, I25, I26, I27, I28, I29, I30, I31, S0, S1, S2, S3);
MUX2 mux2_o(O ,O1, O2, S4);
endmodule
//LUTs
module LUT1 (F, I0);
parameter INIT = 2'h0;
input I0;
output F;
MUX2 lut_1 (F, INIT[0], INIT[1], I0);
endmodule //lut1
module LUT2 (F, I0, I1);
parameter INIT = 4'h0;
input I0, I1;
output F;
MUX4 lut_2 (F, INIT[0], INIT[1], INIT[2], INIT[3], I0, I1);
endmodule //lut2
module LUT3 (F, I0, I1, I2);
parameter INIT = 8'h00;
input I0, I1, I2;
output F;
MUX8 lut_3 (F, INIT[0], INIT[1], INIT[2], INIT[3], INIT[4], INIT[5], INIT[6], INIT[7], I0, I1, I2);
endmodule //lut3
module LUT4 (F, I0, I1, I2, I3);
parameter INIT = 16'h0000;
input I0, I1, I2, I3;
output F;
MUX16 lut_4(F, INIT[0], INIT[1], INIT[2], INIT[3], INIT[4], INIT[5], INIT[6], INIT[7], INIT[8], INIT[9], INIT[10], INIT[11], INIT[12], INIT[13], INIT[14], INIT[15], I0, I1, I2, I3);
endmodule //lut4
module LUT5 (F, I0, I1, I2, I3, I4);
parameter INIT = 32'h00000000;
input I0, I1, I2, I3, I4;
output F;
MUX32 lut_5(F, INIT[0], INIT[1], INIT[2], INIT[3], INIT[4], INIT[5], INIT[6], INIT[7], INIT[8], INIT[9], INIT[10], INIT[11], INIT[12], INIT[13], INIT[14], INIT[15], INIT[16], INIT[17], INIT[18], INIT[19], INIT[20], INIT[21], INIT[22], INIT[23], INIT[24], INIT[25], INIT[26], INIT[27], INIT[28], INIT[29], INIT[30], INIT[31], I0, I1, I2, I3, I4);
endmodule//lut5
module LUT6 (F, I0, I1, I2, I3, I4, I5);
parameter INIT = 64'h0000_0000_0000_0000;
input I0, I1, I2, I3, I4, I5;
output F;
wire O1, O2;
defparam lut5_1.INIT = INIT[31:0];
LUT5 lut5_1(O1, I0, I1, I2, I3, I4);
defparam lut5_2.INIT = INIT[63:32];
LUT5 lut5_2(O2, I0, I1, I2, I3, I4);
MUX2 lut_6(F, O1, O2, I5);
endmodule//lut6
module LUT7 (F, I0, I1, I2, I3, I4, I5, I6);
parameter INIT = 128'h0000_0000_0000_0000_0000_0000_0000_0000;
input I0, I1, I2, I3, I4, I5, I6;
output F;
wire O1, O2;
defparam lut6_1.INIT = INIT[63:0];
LUT6 lut6_1(O1, I0, I1, I2, I3, I4, I5);
defparam lut6_2.INIT = INIT[127:64];
LUT6 lut6_2(O2, I0, I1, I2, I3, I4, I5);
MUX2 lut_7(F, O1, O2, I6);
endmodule//lut7
module LUT8 (F, I0, I1, I2, I3, I4, I5, I6, I7);
parameter INIT = 256'h0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000;
input I0, I1, I2, I3, I4, I5, I6, I7;
output F;
wire O1, O2;
defparam lut7_1.INIT = INIT[127:0];
LUT7 lut7_1(O1, I0, I1, I2, I3, I4, I5, I6);
defparam lut7_2.INIT = INIT[255:128];
LUT7 lut7_2(O2, I0, I1, I2, I3, I4, I5, I6);
MUX2 lut_8(F, O1, O2, I7);
endmodule//lut8
// ALU
module ALU (SUM, COUT, I0, I1, I3, CIN);
input I0;
input I1;
input I3;
input CIN;
output SUM;
output COUT;
parameter ADD = 0;
parameter SUB = 1;
parameter ADDSUB = 2;
parameter NE = 3;
parameter GE = 4;
parameter LE = 5;
parameter CUP = 6;
parameter CDN = 7;
parameter CUPCDN = 8;
parameter ALU_MODE = 0;
reg S, C;
assign SUM = S ^ CIN;
assign COUT = S? CIN : C;
always @(I0, I1, I3,CIN) begin
case (ALU_MODE)
ADD: begin // adder; LSB CIN must be 1'b0
S = I0 ^ I1;
C = I0;
end
SUB: begin // subtractor; LSB CIN must be 1'b1
S = I0 ^ ~I1;
C = I0;
end
ADDSUB: begin // adder subtractor;
S = I3? I0 ^ I1 : I0 ^ ~I1;
C = I0;
end
NE: begin // not equal to; LSB CIN must be 1'b0
S = I0 ^ ~I1;
C = 1'b1;
end
GE: begin // greater than or equal to; LSB CIN must be 1'b1
S = I0 ^ ~I1;
C = I0;
end
LE: begin // less than or equal to; LSB CIN must be 1'b1
S = ~I0 ^ I1;
C = I1;
end
CUP: begin // up counter; LSB CIN must be 1'b1
S = I0;
C = 1'b0; // or equivalently, I0
end
CDN: begin // down counter; LSB CIN must be 1'b0
S = ~I0;
C = 1'b1; // or equivalently, I0
end
CUPCDN: begin // up down counter; I3 as select bit - 1'b0: down counter, LSB CIN must be 1'b0; 1'b1: up counter, LSB CIN must be 1'b1
S = I3? I0 : ~I0;
C = I0;
end
default: begin
// $display ("%d: Unsupported ALU mode\n", ALU_PARAM);
// $finish;
end
endcase
end
endmodule // ALU: 2-input arithmetic logic unit
// Flip-Flops
module DFFSE (Q, D, CLK, CE, SET);
input D, CLK, SET, CE;
output Q;
parameter INIT = 1'b1;
reg Q_reg;
wire gsrt = 1'b1; // GSR.GSRO
initial Q_reg = INIT;
always @(gsrt)begin
if(!gsrt)
force Q_reg = INIT;
else
release Q_reg;
end
always @(posedge CLK) begin
if (SET)
Q_reg <= 1'b1;
else if (CE)
Q_reg <= D;
end
assign Q = Q_reg;
endmodule // DFFSE (positive clock edge; synchronous set takes precedence over clock enable)
module DFFRE (Q, D, CLK, CE, RESET);
input D, CLK, RESET, CE;
output Q;
parameter INIT = 1'b0;
reg Q_reg;
wire gsrt = 1'b1; // GSR.GSRO
initial Q_reg = INIT;
always @(gsrt) begin
if(!gsrt)
force Q_reg = INIT;
else
release Q_reg;
end
always @(posedge CLK) begin
if (RESET)
Q_reg <= 1'b0;
else if (CE)
Q_reg <= D;
end
assign Q = Q_reg;
endmodule // DFFRE (positive clock edge; synchronous reset takes precedence over clock enable)
module DFFPE (Q, D, CLK, CE, PRESET);
input D, CLK, PRESET, CE;
output Q;
parameter INIT = 1'b1;
reg Q_reg;
wire gsrt = 1'b1; // GSR.GSRO
initial Q_reg = INIT;
always @(gsrt or PRESET) begin
if(!gsrt)
force Q_reg = INIT;
else if(PRESET)
force Q_reg = 1'b1;
else
release Q_reg;
end
always @(posedge CLK) begin
if (CE)
Q_reg <= D;
end
assign Q = Q_reg;
endmodule // DFFPE (positive clock edge; asynchronous preset; clock enable)
module DFFCE (Q, D, CLK, CE, CLEAR);
input D, CLK, CLEAR, CE;
output Q;
parameter INIT = 1'b0;
reg Q_reg;
wire gsrt = 1'b1; // GSR.GSRO
initial Q_reg = INIT;
always @(gsrt or CLEAR) begin
if(!gsrt)
force Q_reg = INIT;
else if(CLEAR)
force Q_reg = 1'b0;
else
release Q_reg;
end
always @(posedge CLK) begin
if (CE)
Q_reg <= D;
end
assign Q = Q_reg;
endmodule // DFFCE (positive clock edge; asynchronous clear; clock enable)
//Latches
module DLCE (Q, D, G, GE, CLEAR);
input D, G, CLEAR, GE;
output Q;
parameter INIT = 1'b0;
reg Q_reg;
wire gsrt = 1'b1; // GSR.GSRO
initial Q_reg = INIT;
always @(D or G or CLEAR or GE or gsrt) begin
if (!gsrt)
Q_reg <= INIT;
else if (CLEAR)
Q_reg <= 1'b0;
else if (G && GE)
Q_reg <= D;
end
assign Q = Q_reg;
endmodule // DLCE (high active latch; asynchronous clear; latch enable)
module DLPE (Q, D, G, GE, PRESET);
input D, G, PRESET, GE;
output Q;
parameter INIT = 1'b1;
reg Q_reg;
wire gsrt = 1'b1; // GSR.GSRO
initial Q_reg = INIT;
always @(D or G or PRESET or GE or gsrt) begin
if (!gsrt)
Q_reg <= INIT;
else if (PRESET)
Q_reg <= 1'b1;
else if (G && GE)
Q_reg <= D;
end
assign Q = Q_reg;
endmodule // DLPE (high active latch; asynchronous preset; latch enable)
// RAM16S1
module RAM16S1 (DO, DI, AD, WRE, CLK);
input CLK;
input WRE;
input [3:0] AD;
input DI;
output DO;
parameter INIT_0 = 16'h0000;
reg [15:0] mem = INIT_0;
assign DO = mem [AD];
always @(posedge CLK) begin
if (WRE) begin
mem [AD] <= DI;
end
end
endmodule // RAM16S1: signal-port S-SRAM(16X1)
//RAM16S2
module RAM16S2 (DO, DI, AD, WRE, CLK);
input CLK;
input WRE;
input [3:0] AD;
input [1:0] DI;
output [1:0] DO;
parameter INIT_0 = 16'h0000;
parameter INIT_1 = 16'h0000;
reg [15:0] mem0;
reg [15:0] mem1;
initial begin
mem0 = INIT_0;
mem1 = INIT_1;
end
assign DO[0] = mem0[AD];
assign DO[1] = mem1[AD];
always @(posedge CLK) begin
if (WRE) begin
mem0[AD] <= DI[0];
mem1[AD] <= DI[1];
end
end
endmodule // RAM16S2: single-port S-SRAM(16X2)
//RAM16S4
module RAM16S4 (DO, DI, AD, WRE, CLK);
input CLK;
input WRE;
input [3:0] AD;
input [3:0] DI;
output [3:0] DO;
parameter INIT_0 = 16'h0000;
parameter INIT_1 = 16'h0000;
parameter INIT_2 = 16'h0000;
parameter INIT_3 = 16'h0000;
reg [15:0] mem0;
reg [15:0] mem1;
reg [15:0] mem2;
reg [15:0] mem3;
initial begin
mem0 = INIT_0;
mem1 = INIT_1;
mem2 = INIT_2;
mem3 = INIT_3;
end
assign DO[0] = mem0[AD];
assign DO[1] = mem1[AD];
assign DO[2] = mem2[AD];
assign DO[3] = mem3[AD];
always @(posedge CLK) begin
if (WRE) begin
mem0[AD] <= DI[0];
mem1[AD] <= DI[1];
mem2[AD] <= DI[2];
mem3[AD] <= DI[3];
end
end
endmodule // RAM16S4: single-port S-SRAM(16X4)
//RAM16SDP1
module RAM16SDP1 (DO, DI, WAD, RAD, WRE, CLK);
input CLK;
input WRE;
input [3:0] WAD;
input DI;
input [3:0] RAD;
output DO;
parameter INIT_0 = 16'h0000;
reg [15:0] mem;
initial mem = INIT_0;
assign DO = mem[RAD];
always @(posedge CLK) begin
if (WRE)
mem[WAD] <= DI;
end
endmodule // RAM16SDP1: Semi dual-port S-SRAM(16X1)
//RAM16SDP2
module RAM16SDP2 (DO, DI, WAD, RAD, WRE, CLK);
input CLK;
input WRE;
input [3:0] WAD;
input [1:0] DI;
input [3:0] RAD;
output [1:0] DO;
parameter INIT_0 = 16'h0000;
parameter INIT_1 = 16'h0000;
reg [15:0] mem0;
reg [15:0] mem1;
initial begin
mem0 = INIT_0;
mem1 = INIT_1;
end
assign DO[0] = mem0[RAD];
assign DO[1] = mem1[RAD];
always @(posedge CLK) begin
if (WRE) begin
mem0[WAD] <= DI[0];
mem1[WAD] <= DI[1];
end
end
endmodule // RAM16SDP2: Semi dual-port S-SRAM(16X2)
//RAM16SDP4
module RAM16SDP4 (DO, DI, WAD, RAD, WRE, CLK);
input CLK;
input WRE;
input [3:0] WAD;
input [3:0] DI;
input [3:0] RAD;
output [3:0] DO;
parameter INIT_0 = 16'h0000;
parameter INIT_1 = 16'h0000;
parameter INIT_2 = 16'h0000;
parameter INIT_3 = 16'h0000;
reg [15:0] mem0;
reg [15:0] mem1;
reg [15:0] mem2;
reg [15:0] mem3;
initial begin
mem0 = INIT_0;
mem1 = INIT_1;
mem2 = INIT_2;
mem3 = INIT_3;
end
assign DO[0] = mem0[RAD];
assign DO[1] = mem1[RAD];
assign DO[2] = mem2[RAD];
assign DO[3] = mem3[RAD];
always @(posedge CLK) begin
if (WRE) begin
mem0[WAD] <= DI[0];
mem1[WAD] <= DI[1];
mem2[WAD] <= DI[2];
mem3[WAD] <= DI[3];
end
end
endmodule // RAM16SDP4: Semi dual-port S-SRAM(16X4)
//ROM16
module ROM16 (DO, AD);
parameter INIT_0 = 16'h0000;
input [3:0] AD;
output DO;
reg DO;
reg [15:0] mem;
initial mem = INIT_0;
always @(AD) begin
DO <= mem [AD];
end
endmodule // ROM16: signal-port shadow ROM(16 bit)
// Inverter
module INV (O, I);
input I;
output O;
assign O = !I;
endmodule // inv
//Misc
module GND (G);
output G;
wire G;
assign G = 1'b0;
endmodule
module VCC (V);
output V;
wire V;
assign V = 1'b1;
endmodule
module GSR (GSRI);
input GSRI;
wire GSRO;
assign GSRO = GSRI;
endmodule //GSR (global set/reset control)
//IOBs
module IBUF (O, I);
input I;
output O;
buf IB (O, I);
endmodule //IBUF (input buffer)
module OBUF (O, I);
input I;
output O;
buf OB (O, I);
endmodule //OBUF (output buffer)
module TBUF (O, I, OEN);
input I, OEN;
output O;
bufif0 TB (O, I, OEN);
endmodule // TBUF (output buffer with tri-state control)
module IOBUF (O, IO, I, OEN);
input I,OEN;
output O;
inout IO;
buf OB (O, IO);
bufif0 IB (IO,I,OEN);
endmodule //IOBUF (inout buffer)
//TRUE LVDS
module TLVDS_IBUF (O, I, IB);
output O;
input I, IB;
reg O_oreg;
assign O = O_oreg;
always @(I or IB) begin
if (I == 1'b1 && IB == 1'b0)
O_oreg <= I;
else if (I == 1'b0 && IB == 1'b1)
O_oreg <= I;
else if (I == 1'bx || IB == 1'bx)
O_oreg <= 1'bx;
end
endmodule
module TLVDS_OBUF (O, OB, I);
output O, OB;
input I;
supply0 gst;
bufif0 TB (O, I, gst);
notif0 YB (OB, I, gst);
endmodule
module TLVDS_TBUF (O, OB, I, OEN);
output O, OB;
input I, OEN;
bufif0 TB (O, I, OEN);
notif0 YB (OB, I, OEN);
endmodule
module TLVDS_IOBUF (O, IO, IOB, I, OEN);
output O;
inout IO, IOB;
input I, OEN;
reg O;
bufif0 IB (IO, I, OEN);
notif0 YB (IOB, I, OEN);
always @(IO or IOB) begin
if (IO == 1'b1 && IOB == 1'b0)
O <= IO;
else if (IO == 1'b0 && IOB == 1'b1)
O <= IO;
else if (IO == 1'bx || IOB == 1'bx)
O <= 1'bx;
end
endmodule
//emulated LVDS
module ELVDS_OBUF (O, OB, I);
output O, OB;
input I;
supply0 gst;
bufif0 TB (O, I, gst);
notif0 YB (OB, I, gst);
endmodule
module ELVDS_TBUF (O, OB, I, OEN);
output O, OB;
input I, OEN;
bufif0 TB (O, I, OEN);
notif0 YB (OB, I, OEN);
endmodule
module ELVDS_IOBUF (O, IO, IOB, I, OEN);
output O;
inout IO, IOB;
input I, OEN;
reg O;
bufif0 IB (IO, I, OEN);
notif0 YB (IOB, I, OEN);
always @(IO or IOB) begin
if (IO == 1'b1 && IOB == 1'b0)
O <= IO;
else if (IO == 1'b0 && IOB == 1'b1)
O <= IO;
else if (IO == 1'bx || IOB == 1'bx)
O <= 1'bx;
end
endmodule
//MIPI_IBUF
//BUF for mipi input
module MIPI_IBUF (OH, OL, OB, IO, IOB, I, IB, OEN, OENB, HSEN, HSREN);
output OH, OL, OB;
inout IO, IOB;
input I, IB;
input OEN, OENB;
input HSEN, HSREN;
reg OH;
//LP mode
bufif0 IL_INST (IO,I,OEN);
bufif0 IB_INST (IOB,IB,OENB);
assign OL = IO;
assign OB = IOB;
//HS mode
always @(IO or IOB or HSEN)
begin
if(HSEN)
begin
if (IO == 1'b1 && IOB == 1'b0)
begin
OH <= IO;
end else if (IO == 1'b0 && IOB == 1'b1)
begin
OH <= IO;
end else if (IO == 1'bx || IOB == 1'bx)
begin
OH <= 1'bx;
end
end
end
endmodule
//OBUF for mipi output, gw5a-25
module MIPI_OBUF_A (O, OB, IO, IOB, I, IB, IL, OEN, OENB, MODESEL);
output O, OB;
input I, IB, IL, MODESEL;
inout IO, IOB;
input OEN, OENB;
//LP mode
bufif0 IL_INST (IO, IL, (OEN || MODESEL));
bufif0 IB_INST (IOB, IB, (OENB || MODESEL));
bufif0 (O, IO, MODESEL); //LP RX
bufif0 (OB, IOB, MODESEL);
//HS mode
bufif1 I_HS (I_hs, I, MODESEL);