FPGC5.v 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Top level design of the FPGC5
  3. */
  4. module FPGC5(
  5. input clock, //50MHz
  6. input nreset, nBtnl, nBtnr,
  7. //HDMI
  8. output [3:0] TMDS_p,
  9. output [3:0] TMDS_n,
  10. //NTSC composite video signal
  11. output [7:0] composite,
  12. //SDRAM
  13. output SDRAM_CLK,
  14. output SDRAM_CSn,
  15. output SDRAM_WEn,
  16. output SDRAM_CASn,
  17. output SDRAM_RASn,
  18. output SDRAM_CKE,
  19. output [12:0] SDRAM_A,
  20. output [1:0] SDRAM_BA,
  21. output [1:0] SDRAM_DQM,
  22. inout [15:0] SDRAM_DQ,
  23. //SPI0 flash
  24. output SPI0_clk,
  25. output SPI0_cs,
  26. inout SPI0_data,
  27. inout SPI0_q,
  28. inout SPI0_wp,
  29. inout SPI0_hold,
  30. //SPI1 CH376 bottom
  31. output SPI1_clk,
  32. output SPI1_cs,
  33. output SPI1_mosi,
  34. input SPI1_miso,
  35. input SPI1_nint,
  36. output SPI1_rst,
  37. //SPI2 CH376 top
  38. output SPI2_clk,
  39. output SPI2_cs,
  40. output SPI2_mosi,
  41. input SPI2_miso,
  42. input SPI2_nint,
  43. output SPI2_rst,
  44. //SPI3 W5500
  45. output SPI3_clk,
  46. output SPI3_cs,
  47. output SPI3_mosi,
  48. input SPI3_miso,
  49. input SPI3_int,
  50. output SPI3_nrst,
  51. //SPI4 GP
  52. output SPI4_clk,
  53. output SPI4_cs,
  54. output SPI4_mosi,
  55. input SPI4_miso,
  56. input SPI4_gp,
  57. //UART0
  58. input UART0_in,
  59. output UART0_out,
  60. input UART0_dtr,
  61. //UART1 (currently unused because no UART midi synth anymore)
  62. //input UART1_in,
  63. //output UART1_out,
  64. //UART2
  65. input UART2_in,
  66. output UART2_out,
  67. //PS/2
  68. input PS2_clk, PS2_data,
  69. //Led for debugging
  70. output led,
  71. //GPIO
  72. input [3:0] GPI,
  73. output [3:0] GPO,
  74. //DIP switch
  75. input [3:0] DIPS,
  76. //I2S audio
  77. output I2S_SDIN, I2S_SCLK, I2S_LRCLK, I2S_MCLK,
  78. //Status leds
  79. output led_Booted, led_Eth, led_Flash, led_USB0, led_USB1, led_PS2, led_HDMI, led_QSPI, led_GPU, led_I2S
  80. );
  81. // TMP FIXES FOR NEW PCB
  82. assign I2S_SDIN = 1'b0;
  83. assign I2S_SCLK = 1'b0;
  84. assign I2S_LRCLK = 1'b0;
  85. assign I2S_MCLK = 1'b0;
  86. //-------------------CLK-------------------------
  87. // Clock generator PLL
  88. wire clkPixel; // Pixel clock (25MHz)
  89. wire clkTMDShalf; // TMDS clock (pre-DDR), 5x pixel clock (125MHz)
  90. wire clk_SDRAM; // SDRAM clock (100MHz)
  91. wire clk; // System clock (50MHz)
  92. clock_pll clkPll(
  93. .inclk0 (clock),
  94. //.c0 (clkPixel),
  95. //.c1 (clkTMDShalf),
  96. .c2 (clk_SDRAM),
  97. .c3 (SDRAM_CLK),
  98. .c4 (clk)
  99. );
  100. wire clk14; //14.31818MHz (50*63/220)
  101. wire clk114; //14.31818 * 8 MHz = 114.5454MHz (50*(63*2)/55)
  102. NTSC_pll ntscPll(
  103. .inclk0 (clock),
  104. .c0 (clk14),
  105. .c1 (clk114),
  106. .c2 (clkPixel), // 25.2MHz dirty fix to allow ALTCLKBUF
  107. .c3 (clkTMDShalf)
  108. );
  109. wire clkMuxOut;
  110. wire selectOutput; // 1 -> HDMI, 0 -> Composite
  111. clkMux clkmux(
  112. .inclk0x(clk14),
  113. .inclk1x(clkPixel),
  114. .clkselect(selectOutput),
  115. .outclk(clkMuxOut)
  116. );
  117. //assign clkMuxOut = clk14;
  118. //--------------------Reset&Stabilizers-----------------------
  119. // Reset signals
  120. wire nreset_stable, UART0_dtr_stable;
  121. wire nreset_unstable;
  122. assign nreset_unstable = nreset & nBtnl & nBtnr;
  123. // Dip switch
  124. wire boot_mode_stable;
  125. // GPU: High when frame just rendered (needs to be stabilized)
  126. wire frameDrawn, frameDrawn_stable;
  127. // Stabilized SPI interrupt signals
  128. wire SPI1_nint_stable, SPI2_nint_stable, SPI3_int_stable, SPI4_gp_stable;
  129. MultiStabilizer multistabilizer(
  130. .clk (clk),
  131. .u0 (nreset_unstable),
  132. .s0 (nreset_stable),
  133. .u1 (UART0_dtr),
  134. .s1 (UART0_dtr_stable),
  135. .u2 (SPI1_nint),
  136. .s2 (SPI1_nint_stable),
  137. .u3 (SPI2_nint),
  138. .s3 (SPI2_nint_stable),
  139. .u4 (SPI3_int),
  140. .s4 (SPI3_int_stable),
  141. .u5 (SPI4_gp),
  142. .s5 (SPI4_gp_stable),
  143. .u6 (frameDrawn),
  144. .s6 (frameDrawn_stable),
  145. .u7 (DIPS[0]),
  146. .s7 (boot_mode_stable),
  147. .u8 (DIPS[1]),
  148. .s8 (selectOutput)
  149. );
  150. //assign selectOutput = 1'b0;
  151. // Debug: indicator for opened Serial port
  152. assign led = UART0_dtr_stable;
  153. // DTR to reset pulse
  154. wire dtrRst;
  155. DtrReset dtrReset(
  156. .clk (clk),
  157. .dtr (UART0_dtr_stable),
  158. .dtrRst (dtrRst)
  159. );
  160. wire reset = (~nreset_stable) || dtrRst; // Global reset
  161. // External reset outputs
  162. assign SPI1_rst = reset;
  163. assign SPI2_rst = reset;
  164. assign SPI3_nrst = ~reset;
  165. //---------------------------VRAM32---------------------------------
  166. // VRAM32 I/O
  167. wire vram32_gpu_clk;
  168. wire [13:0] vram32_gpu_addr;
  169. wire [31:0] vram32_gpu_d;
  170. wire vram32_gpu_we;
  171. wire [31:0] vram32_gpu_q;
  172. wire vram32_cpu_clk;
  173. wire [13:0] vram32_cpu_addr;
  174. wire [31:0] vram32_cpu_d;
  175. wire vram32_cpu_we;
  176. wire [31:0] vram32_cpu_q;
  177. // FSX will not write to VRAM
  178. assign vram32_gpu_we = 1'b0;
  179. assign vram32_gpu_d = 32'd0;
  180. VRAM #(
  181. .WIDTH(32),
  182. .WORDS(1056),
  183. .LIST("memory/vram32.list")
  184. ) vram32(
  185. // CPU port
  186. .cpu_clk (clk),
  187. .cpu_d (vram32_cpu_d),
  188. .cpu_addr (vram32_cpu_addr),
  189. .cpu_we (vram32_cpu_we),
  190. .cpu_q (vram32_cpu_q),
  191. // GPU port
  192. .gpu_clk (clkMuxOut),
  193. .gpu_d (vram32_gpu_d),
  194. .gpu_addr (vram32_gpu_addr),
  195. .gpu_we (vram32_gpu_we),
  196. .gpu_q (vram32_gpu_q)
  197. );
  198. //---------------------------VRAM322--------------------------------
  199. // VRAM322 I/O
  200. wire vram322_gpu_clk;
  201. wire [13:0] vram322_gpu_addr;
  202. wire [31:0] vram322_gpu_d;
  203. wire vram322_gpu_we;
  204. wire [31:0] vram322_gpu_q;
  205. // FSX will not write to VRAM
  206. assign vram322_gpu_we = 1'b0;
  207. assign vram322_gpu_d = 32'd0;
  208. VRAM #(
  209. .WIDTH(32),
  210. .WORDS(1056),
  211. .LIST("memory/vram32.list")
  212. ) vram322(
  213. // CPU port
  214. .cpu_clk (clk),
  215. .cpu_d (vram32_cpu_d),
  216. .cpu_addr (vram32_cpu_addr),
  217. .cpu_we (vram32_cpu_we),
  218. .cpu_q (),
  219. // GPU port
  220. .gpu_clk (clkMuxOut),
  221. .gpu_d (vram322_gpu_d),
  222. .gpu_addr (vram322_gpu_addr),
  223. .gpu_we (vram322_gpu_we),
  224. .gpu_q (vram322_gpu_q)
  225. );
  226. //--------------------------VRAM8--------------------------------
  227. //VRAM8 I/O
  228. wire vram8_gpu_clk;
  229. wire [13:0] vram8_gpu_addr;
  230. wire [7:0] vram8_gpu_d;
  231. wire vram8_gpu_we;
  232. wire [7:0] vram8_gpu_q;
  233. wire vram8_cpu_clk;
  234. wire [13:0] vram8_cpu_addr;
  235. wire [7:0] vram8_cpu_d;
  236. wire vram8_cpu_we;
  237. wire [7:0] vram8_cpu_q;
  238. // FSX will not write to VRAM
  239. assign vram8_gpu_we = 1'b0;
  240. assign vram8_gpu_d = 8'd0;
  241. VRAM #(
  242. .WIDTH(8),
  243. .WORDS(8194),
  244. .LIST("memory/vram8.list")
  245. ) vram8(
  246. // CPU port
  247. .cpu_clk (clk),
  248. .cpu_d (vram8_cpu_d),
  249. .cpu_addr (vram8_cpu_addr),
  250. .cpu_we (vram8_cpu_we),
  251. .cpu_q (vram8_cpu_q),
  252. // GPU port
  253. .gpu_clk (clkMuxOut),
  254. .gpu_d (vram8_gpu_d),
  255. .gpu_addr (vram8_gpu_addr),
  256. .gpu_we (vram8_gpu_we),
  257. .gpu_q (vram8_gpu_q)
  258. );
  259. //--------------------------VRAMSPR--------------------------------
  260. //VRAMSPR I/O
  261. wire vramSPR_gpu_clk;
  262. wire [13:0] vramSPR_gpu_addr;
  263. wire [8:0] vramSPR_gpu_d;
  264. wire vramSPR_gpu_we;
  265. wire [8:0] vramSPR_gpu_q;
  266. wire vramSPR_cpu_clk;
  267. wire [13:0] vramSPR_cpu_addr;
  268. wire [8:0] vramSPR_cpu_d;
  269. wire vramSPR_cpu_we;
  270. wire [8:0] vramSPR_cpu_q;
  271. // FSX will not write to VRAM
  272. assign vramSPR_gpu_we = 1'b0;
  273. assign vramSPR_gpu_d = 9'd0;
  274. VRAM #(
  275. .WIDTH(9),
  276. .WORDS(256),
  277. .LIST("memory/vramSPR.list")
  278. ) vramSPR(
  279. // CPU port
  280. .cpu_clk (clk),
  281. .cpu_d (vramSPR_cpu_d),
  282. .cpu_addr (vramSPR_cpu_addr),
  283. .cpu_we (vramSPR_cpu_we),
  284. .cpu_q (vramSPR_cpu_q),
  285. // GPU port
  286. .gpu_clk (clkMuxOut),
  287. .gpu_d (vramSPR_gpu_d),
  288. .gpu_addr (vramSPR_gpu_addr),
  289. .gpu_we (vramSPR_gpu_we),
  290. .gpu_q (vramSPR_gpu_q)
  291. );
  292. //-------------------ROM-------------------------
  293. // ROM I/O
  294. wire [8:0] rom_addr;
  295. wire [31:0] rom_q;
  296. ROM rom(
  297. .clk (clk),
  298. .reset (reset),
  299. .address (rom_addr),
  300. .q (rom_q)
  301. );
  302. //-----------------------FSX-------------------------
  303. // FSX I/O
  304. //wire [7:0] composite; // NTSC composite video signal
  305. FSX fsx(
  306. // Clocks
  307. .clkPixel (clkPixel),
  308. .clkTMDShalf (clkTMDShalf),
  309. .clk14 (clk14),
  310. .clk114 (clk114),
  311. .clkMuxOut (clkMuxOut),
  312. // HDMI
  313. .TMDS_p (TMDS_p),
  314. .TMDS_n (TMDS_n),
  315. // NTSC composite
  316. .composite (composite),
  317. // Select output method
  318. .selectOutput (selectOutput),
  319. // VRAM32
  320. .vram32_addr (vram32_gpu_addr),
  321. .vram32_q (vram32_gpu_q),
  322. // VRAM32
  323. .vram322_addr (vram322_gpu_addr),
  324. .vram322_q (vram322_gpu_q),
  325. // VRAM8
  326. .vram8_addr (vram8_gpu_addr),
  327. .vram8_q (vram8_gpu_q),
  328. // VRAMSPR
  329. .vramSPR_addr (vramSPR_gpu_addr),
  330. .vramSPR_q (vramSPR_gpu_q),
  331. // Interrupt signal
  332. .frameDrawn (frameDrawn)
  333. );
  334. //----------------Memory Unit--------------------
  335. // Memory Unit I/O
  336. // Bus
  337. wire [26:0] bus_addr;
  338. wire [31:0] bus_data;
  339. wire bus_we;
  340. wire bus_start;
  341. wire [31:0] bus_q;
  342. wire bus_done;
  343. // Interrupt signals
  344. wire OST1_int, OST2_int, OST3_int;
  345. wire UART0_rx_int, UART2_rx_int;
  346. wire PS2_int;
  347. wire SPI0_QSPI;
  348. MemoryUnit mu(
  349. // Clocks
  350. .clk (clk),
  351. .clk_SDRAM (clk_SDRAM),
  352. .reset (reset),
  353. // Bus
  354. .bus_addr (bus_addr),
  355. .bus_data (bus_data),
  356. .bus_we (bus_we),
  357. .bus_start (bus_start),
  358. .bus_q (bus_q),
  359. .bus_done (bus_done),
  360. /********
  361. * MEMORY
  362. ********/
  363. // SPI Flash / SPI0
  364. .SPIflash_data (SPI0_data),
  365. .SPIflash_q (SPI0_q),
  366. .SPIflash_wp (SPI0_wp),
  367. .SPIflash_hold (SPI0_hold),
  368. .SPIflash_cs (SPI0_cs),
  369. .SPIflash_clk (SPI0_clk),
  370. // SDRAM
  371. .SDRAM_CSn (SDRAM_CSn),
  372. .SDRAM_WEn (SDRAM_WEn),
  373. .SDRAM_CASn (SDRAM_CASn),
  374. .SDRAM_CKE (SDRAM_CKE),
  375. .SDRAM_RASn (SDRAM_RASn),
  376. .SDRAM_A (SDRAM_A),
  377. .SDRAM_BA (SDRAM_BA),
  378. .SDRAM_DQM (SDRAM_DQM),
  379. .SDRAM_DQ (SDRAM_DQ),
  380. // VRAM32 cpu port
  381. .VRAM32_cpu_d (vram32_cpu_d),
  382. .VRAM32_cpu_addr (vram32_cpu_addr),
  383. .VRAM32_cpu_we (vram32_cpu_we),
  384. .VRAM32_cpu_q (vram32_cpu_q),
  385. // VRAM8 cpu port
  386. .VRAM8_cpu_d (vram8_cpu_d),
  387. .VRAM8_cpu_addr (vram8_cpu_addr),
  388. .VRAM8_cpu_we (vram8_cpu_we),
  389. .VRAM8_cpu_q (vram8_cpu_q),
  390. // VRAMspr cpu port
  391. .VRAMspr_cpu_d (vramSPR_cpu_d),
  392. .VRAMspr_cpu_addr (vramSPR_cpu_addr),
  393. .VRAMspr_cpu_we (vramSPR_cpu_we),
  394. .VRAMspr_cpu_q (vramSPR_cpu_q),
  395. // ROM
  396. .ROM_addr (rom_addr),
  397. .ROM_q (rom_q),
  398. /********
  399. * I/O
  400. ********/
  401. // UART0 (Main USB)
  402. .UART0_in (UART0_in),
  403. .UART0_out (UART0_out),
  404. .UART0_rx_interrupt (UART0_rx_int),
  405. // UART1 (APU)
  406. /*
  407. .UART1_in (),
  408. .UART1_out (),
  409. .UART1_rx_interrupt (),
  410. */
  411. // UART2 (GP)
  412. .UART2_in (UART2_in),
  413. .UART2_out (UART2_out),
  414. .UART2_rx_interrupt (UART2_rx_int),
  415. //SPI0 (Flash)
  416. //declared under MEMORY
  417. .SPI0_QSPI (SPI0_QSPI),
  418. // SPI1 (USB0/CH376T, bottom)
  419. .SPI1_clk (SPI1_clk),
  420. .SPI1_cs (SPI1_cs),
  421. .SPI1_mosi (SPI1_mosi),
  422. .SPI1_miso (SPI1_miso),
  423. .SPI1_nint (SPI1_nint_stable),
  424. // SPI2 (USB1/CH376T, top)
  425. .SPI2_clk (SPI2_clk),
  426. .SPI2_cs (SPI2_cs),
  427. .SPI2_mosi (SPI2_mosi),
  428. .SPI2_miso (SPI2_miso),
  429. .SPI2_nint (SPI2_nint_stable),
  430. // SPI3 (W5500)
  431. .SPI3_clk (SPI3_clk),
  432. .SPI3_cs (SPI3_cs),
  433. .SPI3_mosi (SPI3_mosi),
  434. .SPI3_miso (SPI3_miso),
  435. .SPI3_int (SPI3_int_stable),
  436. // SPI4 (EXT/GP)
  437. .SPI4_clk (SPI4_clk),
  438. .SPI4_cs (SPI4_cs),
  439. .SPI4_mosi (SPI4_mosi),
  440. .SPI4_miso (SPI4_miso),
  441. .SPI4_GP (SPI4_gp_stable),
  442. // GPIO (Separated GPI and GPO until GPIO module is implemented)
  443. .GPI (GPI[3:0]),
  444. .GPO (GPO[3:0]),
  445. // OStimers
  446. .OST1_int (OST1_int),
  447. .OST2_int (OST2_int),
  448. .OST3_int (OST3_int),
  449. // SNESpad
  450. /*
  451. .SNES_clk (),
  452. .SNES_latch (),
  453. .SNES_data (),
  454. */
  455. // PS/2
  456. .PS2_clk (PS2_clk),
  457. .PS2_data (PS2_data),
  458. .PS2_int (PS2_int), //Scan code ready signal
  459. // Boot mode
  460. .boot_mode (boot_mode_stable)
  461. );
  462. //---------------CPU----------------
  463. // CPU I/O
  464. wire [26:0] PC;
  465. CPU cpu(
  466. // Clock/reset
  467. .clk (clk),
  468. .reset (reset),
  469. .int1 (OST1_int), //OStimer1
  470. .int2 (OST2_int), //OStimer2
  471. .int3 (UART0_rx_int), //UART0 rx (MAIN)
  472. .int4 (frameDrawn_stable), //GPU Frame Drawn
  473. .int5 (OST3_int), //OStimer3
  474. .int6 (PS2_int), //PS/2 scancode ready
  475. .int7 (1'b0), //UART1 rx (APU)
  476. .int8 (UART2_rx_int), //UART2 rx (EXT)
  477. // Bus
  478. .bus_addr (bus_addr),
  479. .bus_data (bus_data),
  480. .bus_we (bus_we),
  481. .bus_start (bus_start),
  482. .bus_q (bus_q),
  483. .bus_done (bus_done),
  484. .PC (PC)
  485. );
  486. //-----------STATUS LEDS-----------
  487. assign led_Booted = (PC >= 27'hC02522 | reset);
  488. assign led_HDMI = (~selectOutput | reset);
  489. assign led_QSPI = (~SPI0_QSPI | reset);
  490. LEDvisualizer #(.MIN_CLK(100000))
  491. LEDvisUSB0
  492. (
  493. .clk(clk),
  494. .reset(reset),
  495. .activity(~SPI1_cs),
  496. .LED(led_USB0)
  497. );
  498. LEDvisualizer #(.MIN_CLK(100000))
  499. LEDvisUSB1
  500. (
  501. .clk(clk),
  502. .reset(reset),
  503. .activity(~SPI2_cs),
  504. .LED(led_USB1)
  505. );
  506. LEDvisualizer #(.MIN_CLK(100000))
  507. LEDvisEth
  508. (
  509. .clk(clk),
  510. .reset(reset),
  511. .activity(~SPI3_cs),
  512. .LED(led_Eth)
  513. );
  514. LEDvisualizer #(.MIN_CLK(100000))
  515. LEDvisPS2
  516. (
  517. .clk(clk),
  518. .reset(reset),
  519. .activity(PS2_int),
  520. .LED(led_PS2)
  521. );
  522. LEDvisualizer #(.MIN_CLK(100000))
  523. LEDvisFlash
  524. (
  525. .clk(clk),
  526. .reset(reset),
  527. .activity(~SPI0_cs),
  528. .LED(led_Flash)
  529. );
  530. LEDvisualizer #(.MIN_CLK(100000))
  531. LEDvisGPU
  532. (
  533. .clk(clk),
  534. .reset(reset),
  535. .activity(vram32_cpu_we|vram8_cpu_we|vramSPR_cpu_we),
  536. .LED(led_GPU)
  537. );
  538. LEDvisualizer #(.MIN_CLK(100000))
  539. LEDvisI2S
  540. (
  541. .clk(clk),
  542. .reset(reset),
  543. .activity(I2S_SDIN),
  544. .LED(led_I2S)
  545. );
  546. endmodule