-
Notifications
You must be signed in to change notification settings - Fork 1
/
C4RiscVSOCTop.vhd
1724 lines (1225 loc) · 48.1 KB
/
C4RiscVSOCTop.vhd
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
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
library altera_mf;
use altera_mf.altera_mf_components.all;
--https://github.com/nullobject/de0-nano-examples/blob/master/sdram/src/sdram.vhd
--https://www.intel.com/content/www/us/en/docs/programmable/683492/18-1/using-synthesis-attributes.html
--https://github.com/splinedrive/my_sdram/blob/main/my_sdram_ctrl.v
--https://github.com/douggilliland/Retro-Computers/blob/master/68000/TG68_AMR/TG68_AMR_FPGA/RTL/Memory/sdram.vhd
--https://github.com/nullobject/sdram-fpga
--https://www.geocities.ws/mikael262/sdram.html
--https://www.fpga4fun.com/SDRAM2.html
--http://www.pudn.com/Download/item/id/122819.html
--https://github.com/emard/Minimig_ECS/blob/master/rtl_emard/sdram/sdram.vhd
--multicycle paths
--https://github.com/ijor/fx68k/blob/master/fx68k.txt
--creating timing constraints
--https://www.youtube.com/watch?v=SpKAg3JJOs8
--https://community.intel.com/t5/FPGA/ct-p/fpga
--https://community.intel.com/t5/Intel-Quartus-Prime-Software/How-to-improve-Fmax-for-SOPC-System/td-p/46478
--https://github.com/YosysHQ/picorv32
--https://github.com/YosysHQ/nerv/blob/main/firmware.s
--hdmi output example
--https://numato.com/kb/hdmi-output-example-design-for-telesto/
entity C4RiscVSOCTop is
generic(
instHDMIOutput: boolean := true;
instBlitter3DAcceleration: boolean := true;
instFastFloatingMath: boolean := true;
instHidUSBHost: boolean := true
);
port(
--onboard peripherals
--clock
core_board_clk_50: in std_logic;
--reset
core_board_reset: in std_logic;
--user key
core_board_key: in std_logic;
--leds
core_board_leds: out std_logic_vector( 1 downto 0 );
--sdram
sd1_a: out std_logic_vector( 12 downto 0 );
sd1_ba: out std_logic_vector( 1 downto 0 );
sd1_cke: out std_logic;
sd1_clk: out std_logic;
sd1_dqml: out std_logic;
sd1_dqmh: out std_logic;
sd1_cas: out std_logic;
sd1_ras: out std_logic;
sd1_wen: out std_logic;
sd1_csn: out std_logic;
sd1_d: inout std_logic_vector( 15 downto 0 );
--base board peripherals
--vga
red: out std_logic_vector( 4 downto 0 );
green: out std_logic_vector( 4 downto 0 );
blue: out std_logic_vector( 4 downto 0 );
vsync: out std_logic;
hsync: out std_logic;
--ext uart
extUartTx: out std_logic;
extUartRx: in std_logic;
--sd card
sdMciDat: inout std_logic_vector( 3 downto 0 );
sdMciCmd: out std_logic;
sdMciClk: out std_logic;
--usb host
usbHDp: inout std_logic; -- ae17 (I2S_IO0)
usbHDm: inout std_logic; -- af17 (I2S_IO1)
--hdmi output
tmdsOutClk: out std_logic;
tmdsOutClkN: out std_logic;
tmdsOutData: out std_logic_vector( 2 downto 0 );
tmdsOutDataN: out std_logic_vector( 2 downto 0 );
--graphics sram
gds0_7n: out std_logic;
gds8_15n: out std_logic;
gds16_23n: out std_logic;
gds24_31n: out std_logic;
gwen: out std_logic;
goen: out std_logic;
ga: out std_logic_vector( 20 downto 0 );
gd: inout std_logic_vector( 31 downto 0 )
);
end C4RiscVSOCTop;
architecture behavior of C4RiscVSOCTop is
-- components
-- main pll
component mainPll IS
PORT
(
areset : IN STD_LOGIC := '0';
inclk0 : IN STD_LOGIC := '0';
c0 : OUT STD_LOGIC ;
c1 : OUT STD_LOGIC ;
c2 : OUT STD_LOGIC ;
c3 : OUT STD_LOGIC ;
c4 : OUT STD_LOGIC ;
locked : OUT STD_LOGIC
);
END component;
-- gfx pll
component gfxPll IS
PORT
(
areset : IN STD_LOGIC := '0';
inclk0 : IN STD_LOGIC := '0';
c0 : OUT STD_LOGIC ;
c1 : OUT STD_LOGIC ;
c2 : OUT STD_LOGIC ;
locked : OUT STD_LOGIC
);
END component;
-- font prom
component fontProm IS
PORT
(
address : IN STD_LOGIC_VECTOR (10 DOWNTO 0);
clock : IN STD_LOGIC := '1';
q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
);
END component;
-- text mode pixel and sync gen
component pixelGenTxt
port(
--reset
reset: in std_logic;
pgClock: in std_logic;
pgVSync: out std_logic;
pgHSync: out std_logic;
pgDe: out std_logic;
pgR: out std_logic_vector( 7 downto 0 );
pgG: out std_logic_vector( 7 downto 0 );
pgB: out std_logic_vector( 7 downto 0 );
fontRomA: out std_logic_vector( 10 downto 0 );
fontRomDout: in std_logic_vector( 7 downto 0 );
videoRamBA: out std_logic_vector( 13 downto 0 );
videoRamBDout: in std_logic_vector( 15 downto 0 );
pgXCount: out std_logic_vector( 11 downto 0 );
pgYCount: out std_logic_vector( 11 downto 0 );
pgDeX: out std_logic;
pgDeY: out std_logic;
pgPreFetchLine: out std_logic;
pgFetchEnable: out std_logic;
pgVideoMode: in std_logic_vector( 1 downto 0 )
);
end component;
-- gfx pixel gen
component pixelGenGfx is
port(
reset: in std_logic;
pggClock: in std_logic;
pggR: out std_logic_vector( 7 downto 0 );
pggG: out std_logic_vector( 7 downto 0 );
pggB: out std_logic_vector( 7 downto 0 );
--gfx buffer ram
gfxBufRamDOut: in std_logic_vector( 31 downto 0 );
gfxBufRamRdA: out std_logic_vector( 8 downto 0 );
--2 dma requests
pggDMARequest: out std_logic_vector( 1 downto 0 );
--sync gen outputs
pgVSync: in std_logic;
pgHSync: in std_logic;
pgDe: in std_logic;
pgXCount: in std_logic_vector( 11 downto 0 );
pgYCount: in std_logic_vector( 11 downto 0 );
pgDeX: in std_logic;
pgDeY: in std_logic;
pgPreFetchLine: in std_logic;
pgFetchEnable: in std_logic;
pgVideoMode: in std_logic_vector( 1 downto 0 )
);
end component;
-- riscv cpu
component picorv32 is
port
(
clk: in std_logic;
resetn: in std_logic;
trap: out std_logic;
mem_valid: out std_logic;
mem_instr: out std_logic;
mem_ready: in std_logic;
mem_addr: out std_logic_vector( 31 downto 0 );
mem_wdata: out std_logic_vector( 31 downto 0 );
mem_wstrb: out std_logic_vector( 3 downto 0 );
mem_rdata: in std_logic_vector( 31 downto 0 );
--Look-Ahead Interface
mem_la_read: out std_logic;
mem_la_write: out std_logic;
mem_la_addr: out std_logic_vector( 31 downto 0 );
mem_la_wdata: out std_logic_vector( 31 downto 0 );
mem_la_wstrb: out std_logic_vector( 3 downto 0 );
--Pico Co-Processor Interface (PCPI)
pcpi_valid: out std_logic;
pcpi_insn: out std_logic_vector( 31 downto 0 );
pcpi_rs1: out std_logic_vector( 31 downto 0 );
pcpi_rs2: out std_logic_vector( 31 downto 0 );
pcpi_wr: in std_logic;
pcpi_rd: in std_logic_vector( 31 downto 0 );
pcpi_wait: in std_logic;
pcpi_ready: in std_logic;
--IRQ Interface
irq: in std_logic_vector( 31 downto 0 );
eoi: out std_logic_vector( 31 downto 0 );
--Trace Interface
trace_valid: out std_logic;
trace_data: out std_logic_vector( 35 downto 0 )
);
end component;
-- static ram controller and dma
component sramController is
port(
reset: in std_logic;
clock: in std_logic;
--gfx display mode interface ( ch0 )
ch0DmaRequest: in std_logic_vector( 1 downto 0 );
ch0DmaPointerStart: in std_logic_vector( 20 downto 0 );
ch0DmaPointerReset: in std_logic;
ch0BufClk: in std_logic;
ch0BufDout: out std_logic_vector( 31 downto 0 );
ch0BufA: in std_logic_vector( 8 downto 0 );
--audio interface ( ch1 )
--tbd
--blitter interface ( ch2 )
ch2DmaRequest: in std_logic;
ch2A: in std_logic_vector( 21 downto 0 );
ch2Din: in std_logic_vector( 31 downto 0 );
ch2Dout: out std_logic_vector( 31 downto 0 );
ch2RWn: in std_logic;
ch2WordSize: in std_logic;
ch2DataMask: in std_logic_vector( 1 downto 0 );
ch2Ready: out std_logic;
--cpu interface ( ch3 )
a: in std_logic_vector( 20 downto 0 );
din: in std_logic_vector( 31 downto 0 );
dout: out std_logic_vector( 31 downto 0 );
ce: in std_logic;
wr: in std_logic;
dataMask: in std_logic_vector( 3 downto 0 );
ready: out std_logic;
--static ram interface
gds0_7n: out std_logic;
gds8_15n: out std_logic;
gds16_23n: out std_logic;
gds24_31n: out std_logic;
gwen: out std_logic;
goen: out std_logic;
ga: out std_logic_vector( 20 downto 0 );
gd: inout std_logic_vector( 31 downto 0 )
);
end component;
-- UART
component UART
port(
--cpu interface
reset: in std_logic;
clock: in std_logic;
a: in std_logic_vector( 15 downto 0 );
din: in std_logic_vector( 31 downto 0 );
dout: out std_logic_vector( 31 downto 0 );
ce: in std_logic;
wr: in std_logic;
dataMask: in std_logic_vector( 3 downto 0 );
ready: out std_logic;
--uart interface
uartTXD: out std_logic;
uartRXD: in std_logic
);
end component;
-- SPI
component SPI is
port(
--cpu interface
reset: in std_logic;
clock: in std_logic;
a: in std_logic_vector( 15 downto 0 );
din: in std_logic_vector( 31 downto 0 );
dout: out std_logic_vector( 31 downto 0 );
ce: in std_logic;
wr: in std_logic;
dataMask: in std_logic_vector( 3 downto 0 );
ready: out std_logic;
--spi interface
sclk: out std_logic;
mosi: out std_logic;
miso: in std_logic
);
end component;
-- system RAM ( 32K, bootloader, textmode display data, stack )
component systemRam IS
PORT
(
address_a : IN STD_LOGIC_VECTOR (12 DOWNTO 0);
address_b : IN STD_LOGIC_VECTOR (12 DOWNTO 0);
byteena_a : IN STD_LOGIC_VECTOR (3 DOWNTO 0) := (OTHERS => '1');
byteena_b : IN STD_LOGIC_VECTOR (3 DOWNTO 0) := (OTHERS => '1');
clock_a : IN STD_LOGIC := '1';
clock_b : IN STD_LOGIC ;
data_a : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
data_b : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
wren_a : IN STD_LOGIC := '0';
wren_b : IN STD_LOGIC := '0';
q_a : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
q_b : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
END component;
-- fastram (512K)
component fastRam IS
PORT
(
address_a : IN STD_LOGIC_VECTOR (16 DOWNTO 0);
address_b : IN STD_LOGIC_VECTOR (16 DOWNTO 0);
byteena_a : IN STD_LOGIC_VECTOR (3 DOWNTO 0) := (OTHERS => '1');
byteena_b : IN STD_LOGIC_VECTOR (3 DOWNTO 0) := (OTHERS => '1');
clock_a : IN STD_LOGIC := '1';
clock_b : IN STD_LOGIC ;
data_a : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
data_b : IN STD_LOGIC_VECTOR (31 DOWNTO 0);
wren_a : IN STD_LOGIC := '0';
wren_b : IN STD_LOGIC := '0';
q_a : OUT STD_LOGIC_VECTOR (31 DOWNTO 0);
q_b : OUT STD_LOGIC_VECTOR (31 DOWNTO 0)
);
END component;
-- usb host
component usbHost is
port(
--cpu interface
reset: in std_logic;
clock: in std_logic;
a: in std_logic_vector( 15 downto 0 );
din: in std_logic_vector( 31 downto 0 );
dout: out std_logic_vector( 31 downto 0 );
ce: in std_logic;
wr: in std_logic;
dataMask: in std_logic_vector( 3 downto 0 );
ready: out std_logic;
--usb phy clock (12MHz)
usbHClk: in std_logic;
--usb host interfaces
usbH0Dp: inout std_logic;
usbH0Dm: inout std_logic
);
end component;
-- sdram memory controller
component sdramController is
port(
clk: in std_logic;
reset: in std_logic;
--sdram interface
sdramCke: out std_logic;
sdramA: out std_logic_vector( 12 downto 0 );
sdramBa: out std_logic_vector( 1 downto 0 );
sdramD: inout std_logic_vector( 15 downto 0 );
sdramDqml: out std_logic;
sdramDqmh: out std_logic;
sdramCas: out std_logic;
sdramRas: out std_logic;
sdramWen: out std_logic;
sdramCsn: out std_logic;
--cpu interface
cpuSdramCE: in std_logic;
cpuSdramA: in std_logic_vector( 22 downto 0 );
cpuDataOutForCPU: out std_logic_vector( 31 downto 0 );
cpuDataIn: in std_logic_vector( 31 downto 0 );
cpuWr: in std_logic;
cpuDataMask: in std_logic_vector( 3 downto 0 );
cpuSdramReady: out std_logic
);
end component;
-- differential output buffer
component diffBuf IS
port(
datain : IN STD_LOGIC_VECTOR (0 DOWNTO 0);
dataout : OUT STD_LOGIC_VECTOR (0 DOWNTO 0);
dataout_b : OUT STD_LOGIC_VECTOR (0 DOWNTO 0)
);
end component;
-- dvi encoder
component dvid is
Port ( clk : in STD_LOGIC;
clk_pixel : in STD_LOGIC;
red_p : in STD_LOGIC_VECTOR (7 downto 0);
green_p : in STD_LOGIC_VECTOR (7 downto 0);
blue_p : in STD_LOGIC_VECTOR (7 downto 0);
blank : in STD_LOGIC;
hsync : in STD_LOGIC;
vsync : in STD_LOGIC;
red_s : out STD_LOGIC;
green_s : out STD_LOGIC;
blue_s : out STD_LOGIC;
clock_s : out STD_LOGIC);
end component;
-- fp alu
component fpAlu is
port(
reset: in std_logic;
clock: in std_logic;
a: in std_logic_vector( 15 downto 0 );
din: in std_logic_vector( 31 downto 0 );
dout: out std_logic_vector( 31 downto 0 );
ce: in std_logic;
wr: in std_logic;
dataMask: in std_logic_vector( 3 downto 0 );
ready: out std_logic
);
end component;
-- blitter
component blitter is
generic(
inst3DAcceleration: boolean := true
);
port(
--cpu interface
reset: in std_logic;
clock: in std_logic;
a: in std_logic_vector( 15 downto 0 );
din: in std_logic_vector( 31 downto 0 );
dout: out std_logic_vector( 31 downto 0 );
ce: in std_logic;
wr: in std_logic;
dataMask: in std_logic_vector( 3 downto 0 );
ready: out std_logic;
--dma interface
dmaDin: in std_logic_vector( 31 downto 0 );
dmaDout: out std_logic_vector( 31 downto 0 );
dmaA: out std_logic_vector( 21 downto 0 );
dmaRWn: out std_logic;
dmaRequest: out std_logic;
dmaTransferSize: out std_logic;
dmaTransferMask: out std_logic_vector( 1 downto 0 );
dmaReady: in std_logic
);
end component;
-- signals
-- active high async reset
signal reset: std_logic;
-- main pll
signal pllLocked: std_logic;
-- gfx pll
signal gfxPllLocked: std_logic;
-- global clocks
signal clk25: std_logic;
signal clk50: std_logic;
signal clk100: std_logic;
signal clk100ps: std_logic; --100 MHz phase shifted
signal clk12: std_logic; --12 MHz USB clock
signal clk125: std_logic; --hdmi pixel clock
signal clk125ps: std_logic; --hdmi pixel clock phase shifted
-- txt pixel gen signals
signal pgClock: std_logic;
signal pgVSync: std_logic;
signal pgHSync: std_logic;
signal pgDe: std_logic;
signal pgR: std_logic_vector( 7 downto 0 );
signal pgG: std_logic_vector( 7 downto 0 );
signal pgB: std_logic_vector( 7 downto 0 );
signal pgXCount: std_logic_vector( 11 downto 0 );
signal pgYCount: std_logic_vector( 11 downto 0 );
signal pgDeX: std_logic;
signal pgDeY: std_logic;
signal pgPreFetchLine: std_logic;
signal pgFetchEnable: std_logic;
signal videoRamBDout: std_logic_vector( 15 downto 0 );
signal videoRamBA: std_logic_vector( 13 downto 0 );
-- gfx pixel gen signals
signal pggR: std_logic_vector( 7 downto 0 );
signal pggG: std_logic_vector( 7 downto 0 );
signal pggB: std_logic_vector( 7 downto 0 );
signal pggDMARequest: std_logic_vector( 1 downto 0 );
-- font rom signals
signal fontRomA: std_logic_vector( 10 downto 0 );
signal fontRomDout: std_logic_vector( 7 downto 0 );
-- uart signals
signal uartClock: std_logic;
signal uartCE: std_logic;
signal uartDoutForCPU: std_logic_vector( 31 downto 0 );
signal uartReady: std_logic;
signal uartTxd: std_logic;
signal uartRxd: std_logic;
-- system ram signals
signal fpgaCpuMemoryClock: std_logic;
signal systemRamDoutForCPU: std_logic_vector( 31 downto 0 );
signal systemRamDoutForPixelGen: std_logic_vector( 31 downto 0 );
signal systemRAMCE: std_logic;
-- fast ram signals
signal fastRamDoutForCPU: std_logic_vector( 31 downto 0 );
signal fastRAMCE: std_logic;
-- cpu signals
signal cpuClock: std_logic;
signal cpuResetn: std_logic;
signal cpuAOut: std_logic_vector( 29 downto 0 );
signal cpuDOut: std_logic_vector( 31 downto 0 );
signal cpuMemValid: std_logic;
signal cpuMemInstr: std_logic;
signal cpuMemReady: std_logic;
signal cpuAOutFull: std_logic_vector( 31 downto 0 );
signal cpuWrStrobe: std_logic_vector( 3 downto 0 );
signal cpuDin: std_logic_vector( 31 downto 0 );
signal cpuWr: std_logic;
signal cpuDataMask: std_logic_vector( 3 downto 0 );
-- SPI signals
signal spiClock: std_logic;
signal spiCE: std_logic;
signal spiDoutForCPU: std_logic_vector( 31 downto 0 );
signal spiReady: std_logic;
signal spiSClk: std_logic;
signal spiMOSI: std_logic;
signal spiMISO: std_logic;
-- gpo signals
signal gpoRegister: std_logic_vector( 7 downto 0 );
-- registers signals
signal registersClock: std_logic;
type regState_T is ( rsWaitForRegAccess, rsWaitForBusCycleEnd );
signal registerState: regState_T;
signal registersCE: std_logic;
signal registersDoutForCPU: std_logic_vector( 31 downto 0 );
-- video mux signals
signal vmMode: std_logic_vector( 15 downto 0 );
-- dma process signals
signal dmaClock: std_logic;
-- dma ch0 buf ram signals ( for gfx pixel gen )
signal gfxBufRamDOut: std_logic_vector( 31 downto 0 );
signal gfxBufRamRdA: std_logic_vector( 8 downto 0 );
signal dmaDisplayPointerStart: std_logic_vector( 20 downto 0 );
-- dma ch2 signals (blitter)
signal dmaCh2Request: std_logic;
signal dmaCh2Ready: std_logic;
signal dmaCh2RWn: std_logic;
signal dmaCh2Din: std_logic_vector( 31 downto 0 );
signal dmaCh2Dout: std_logic_vector( 31 downto 0 );
signal dmaCh2A: std_logic_vector( 21 downto 0 );
signal dmaCh2TransferSize: std_logic;
signal dmaCh2TransferMask: std_logic_vector( 1 downto 0 );
-- dma ch3 signals ( cpu )
signal dmaMemoryCE: std_logic;
signal cpuDmaReady: std_logic;
signal dmaDoutForCPU: std_logic_vector( 31 downto 0 );
-- tick timer signals
signal tickTimerClock: std_logic;
signal tickTimerReset: std_logic;
signal tickTimerPrescalerCounter: std_logic_vector( 31 downto 0 );
signal tickTimerCounter: std_logic_vector( 31 downto 0 );
constant tickTimerPrescalerValue: integer:= 50000 - 1; --1ms tick timer @50MHz
-- usb host signals
signal usbHostClock: std_logic;
signal usbHostCE: std_logic;
signal usbHostReady: std_logic;
signal usbHostDoutForCPU: std_logic_vector( 31 downto 0 );
-- usb phy clock ( 12 MHz )
signal usbHClk: std_logic;
-- blitter signals
signal blitterClock: std_logic;
signal blitterCE: std_logic;
signal blitterReady: std_logic;
signal blitterDoutForCPU: std_logic_vector( 31 downto 0 );
-- frameTimer signals
signal frameTimerClock: std_logic;
signal frameTimerReset: std_logic;
signal frameTimerPgPrvVSync: std_logic;
signal frameTimerValue: std_logic_vector( 31 downto 0 );
-- sdram controller signals
signal sdramClock: std_logic;
signal sdramCtrlClock: std_logic;
signal sdramCtrlCE: std_logic;
signal sdramCtrlDataOutForCPU: std_logic_vector( 31 downto 0 );
signal sdramCtrlSdramReady: std_logic;
-- hdmi controller signals
signal tmdsClk: std_logic;
signal tmdsData: std_logic_vector( 2 downto 0 );
signal dviClock: std_logic;
signal dviClockps: std_logic;
signal dviRed: std_logic_vector( 7 downto 0 );
signal dviGreen: std_logic_vector( 7 downto 0 );
signal dviBlue: std_logic_vector( 7 downto 0 );
signal dviHSync: std_logic;
signal dviVSync: std_logic;
signal dviBlank: std_logic;
-- fpalu signals
signal fpAluClock: std_logic;
signal fpAluCE: std_logic;
signal fpAluDoutForCPU: std_logic_vector( 31 downto 0 );
signal fpAluReady: std_logic;
begin
-- async reset signals
reset <= not pllLocked;
cpuResetn <= core_board_key and pllLocked;
-- place main pll
mainPllInst: mainPll
port map
(
areset => not core_board_reset,
inclk0 => core_board_clk_50,
-- c0 => clk25,
c1 => clk50,
c2 => clk100,
c3 => clk12,
c4 => clk100ps,
locked => pllLocked
);
-- place gfx pll
gfxPllInst : gfxPll
port map
(
areset => not core_board_reset,
inclk0 => core_board_clk_50,
c0 => clk25, --25 MHz
c1 => clk125, --125 MHz
c2 => clk125ps, --125 MHz 180 degree ps
locked => gfxPllLocked
);
-- connect gpo to leds
core_board_leds <= gpoRegister( 5 downto 4 );
-- clock config
-- txt pixel gen clock
pgClock <= clk25;
-- cpu clock
cpuClock <= clk50;
-- fpga cpu memory clock ( system RAM, fast ram )
fpgaCpuMemoryClock <= not cpuClock;
-- registers process clock
registersClock <= clk100;
-- uart clock
uartClock <= clk100;
-- sram direct memory access process clock
dmaClock <= clk100;
-- tick timer clock
tickTimerClock <= clk50;
-- frame timer process clock (not timer clock)
frameTimerClock <= clk100;
-- blitter clock
blitterClock <= clk100;
-- spi clock
spiClock <= clk50;
-- fpAlu clock
fpAluClock <= clk100;
-- usb host clock
usbHostClock <= clk100;
--usb phy clock ( 12MHz )
usbHClk <= clk12;
-- sdram memory clock
sdramClock <= clk100ps;
-- sdram controller clock
sdramCtrlClock <= clk100;
-- hdmi encoder clocks
dviClock <= clk125;
dviClockPs <= clk125ps;
-- place text mode font rom
fontPromInst: fontProm
port map(
clock => pgClock,
address => fontRomA,
q => fontRomDout
);
--place txt pixel gen
pixelGenInst: pixelGenTxt
port map(
reset => reset,
pgClock => pgClock,
pgVSync => pgVSync,
pgHSync => pgHSync,
pgDe => pgDe,
pgR => pgR,
pgG => pgG,
pgB => pgB,
fontRomA => fontRomA,
fontRomDout => fontRomDout,
videoRamBA => videoRamBA,
videoRamBDout => videoRamBDout,
pgXCount => pgXCount,
pgYCount => pgYCount,
pgDeX => pgDeX,
pgDeY => pgDeY,
pgPreFetchLine => pgPreFetchLine,
pgFetchEnable => pgFetchEnable,
pgVideoMode => vmMode( 3 downto 2 )
);
-- place gfx pixel gen
pixelGenGfxInst: pixelGenGfx
port map(
reset => reset,
pggClock => pgClock,
pggR => pggR,
pggG => pggG,
pggB => pggB,
--gfx buffer ram
gfxBufRamDOut => gfxBufRamDOut,
gfxBufRamRdA => gfxBufRamRdA,
--2 dma requests
pggDMARequest => pggDMARequest,
--sync gen outputs
pgVSync => pgVSync,
pgHSync => pgHSync,
pgDe => pgDe,
pgXCount => pgXCount,
pgYCount => pgYCount,
pgDeX => pgDeX,
pgDeY => pgDeY,
pgPreFetchLine => pgPreFetchLine,
pgFetchEnable => pgFetchEnable,
pgVideoMode => vmMode( 5 downto 4 )
);
--video out mux (pixelGenTxt and pixelGenGfx to analog vga and hdmi)
videoMux: process( all )
begin
if rising_edge( pgClock ) then
if reset = '1' then
else
case vmMode( 1 downto 0 ) is
--text mode
when "00" =>
hsync <= pgHSync;
vsync <= pgVSync;
red <= pgR( 7 downto 3 );
green <= pgG( 7 downto 3 );
blue <= pgB( 7 downto 3 );
dviHSync <= pgHSync;
dviVSync <= pgVSync;
dviBlank <= not pgDE;
dviRed <= pgR( 7 downto 3 ) & "000";
dviGreen <= pgG( 7 downto 2 ) & "00";
dviBlue <= pgB( 7 downto 3 ) & "000";
--gfx mode
when "01" =>
hsync <= pgHSync;
vsync <= pgVSync;
red <= pggR( 7 downto 3 );
green <= pggG( 7 downto 3 );
blue <= pggB( 7 downto 3 );
dviHSync <= pgHSync;
dviVSync <= pgVSync;
dviBlank <= not pgDE;
dviRed <= pggR( 7 downto 3 ) & "000";
dviGreen <= pggG( 7 downto 2 ) & "00";
dviBlue <= pggB( 7 downto 3 ) & "000";
--text over gfx mode
when "10" =>
hsync <= pgHSync;
vsync <= pgVSync;
dviHSync <= pgHSync;
dviVSync <= pgVSync;
dviBlank <= not pgDE;
if pgR = x"00" and pgG = x"00" and pgB = x"00" then
red <= pggR( 7 downto 3 );
green <= pggG( 7 downto 3 );
blue <= pggB( 7 downto 3 );