1
0

FPGC.v 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /*
  2. * Top level design of the FPGC
  3. */
  4. module FPGC(
  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 [3:0] SDRAM_DQM,
  22. inout [31: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_v clkPll(
  93. //.refclk (clock),
  94. //.outclk_0 (clkPixel),
  95. //.outclk_1 (clkTMDShalf),
  96. //.outclk_2 (clk_SDRAM),
  97. //.outclk_3 (SDRAM_CLK),
  98. //.outclk_4 (clk)
  99. //);
  100. clock_pll clkPll(
  101. .inclk0 (clock),
  102. .areset (1'b0),
  103. .c0 (clk_SDRAM),
  104. .c1 (SDRAM_CLK),
  105. .c2 (clk)
  106. );
  107. wire clk14; //14.31818MHz (50*63/220)
  108. wire clk114; //14.31818 * 8 MHz = 114.5454MHz (50*(63*2)/55)
  109. //NTSC_pll ntscPll(
  110. //.refclk (clock),
  111. //.outclk_0 (clk14),
  112. //.outclk_1 (clk114),
  113. //.outclk_2 (clkPixel), // 25.2MHz dirty fix to allow ALTCLKBUF
  114. //.outclk_3 (clkTMDShalf)
  115. //);
  116. NTSC_pll ntscPll(
  117. .inclk0 (clk),
  118. .areset (1'b0),
  119. .c0 (clk14),
  120. .c1 (clk114),
  121. .c2 (clkPixel), // 25.2MHz dirty fix to allow ALTCLKBUF
  122. .c3 (clkTMDShalf)
  123. );
  124. wire clkMuxOut;
  125. wire selectOutput; // 1 -> HDMI, 0 -> Composite
  126. clkMux clkmux(
  127. .inclk0x(clock),
  128. .inclk1x(clock),
  129. .inclk2x(clk14),
  130. .inclk3x(clkPixel),
  131. .clkselect({1'b1, selectOutput}),
  132. .outclk(clkMuxOut)
  133. );
  134. //--------------------Reset&Stabilizers-----------------------
  135. // Reset signals
  136. wire nreset_stable, UART0_dtr_stable;
  137. wire nreset_unstable;
  138. assign nreset_unstable = nreset & nBtnl & nBtnr;
  139. // Dip switch
  140. wire boot_mode_stable;
  141. // GPU: High when frame just rendered (needs to be stabilized)
  142. wire frameDrawn, frameDrawn_stable;
  143. // Stabilized SPI interrupt signals
  144. wire SPI1_nint_stable, SPI2_nint_stable, SPI3_int_stable, SPI4_gp_stable;
  145. MultiStabilizer multistabilizer(
  146. .clk (clk),
  147. .u0 (nreset_unstable),
  148. .s0 (nreset_stable),
  149. .u1 (UART0_dtr),
  150. .s1 (UART0_dtr_stable),
  151. .u2 (SPI1_nint),
  152. .s2 (SPI1_nint_stable),
  153. .u3 (SPI2_nint),
  154. .s3 (SPI2_nint_stable),
  155. .u4 (SPI3_int),
  156. .s4 (SPI3_int_stable),
  157. .u5 (SPI4_gp),
  158. .s5 (SPI4_gp_stable),
  159. .u6 (frameDrawn),
  160. .s6 (frameDrawn_stable),
  161. .u7 (DIPS[0]),
  162. .s7 (boot_mode_stable),
  163. .u8 (DIPS[1]),
  164. .s8 (selectOutput)
  165. );
  166. //assign selectOutput = 1'b0;
  167. // Debug: indicator for opened Serial port
  168. assign led = UART0_dtr_stable;
  169. // DTR to reset pulse
  170. wire dtrRst;
  171. DtrReset dtrReset(
  172. .clk (clk),
  173. .dtr (UART0_dtr_stable),
  174. .dtrRst (dtrRst)
  175. );
  176. wire reset = (~nreset_stable) || dtrRst; // Global reset
  177. // External reset outputs
  178. assign SPI1_rst = reset;
  179. assign SPI2_rst = reset;
  180. assign SPI3_nrst = ~reset;
  181. //---------------------------VRAM32---------------------------------
  182. // VRAM32 I/O
  183. wire vram32_gpu_clk;
  184. wire [13:0] vram32_gpu_addr;
  185. wire [31:0] vram32_gpu_d;
  186. wire vram32_gpu_we;
  187. wire [31:0] vram32_gpu_q;
  188. wire vram32_cpu_clk;
  189. wire [13:0] vram32_cpu_addr;
  190. wire [31:0] vram32_cpu_d;
  191. wire vram32_cpu_we;
  192. wire [31:0] vram32_cpu_q;
  193. // FSX will not write to VRAM
  194. assign vram32_gpu_we = 1'b0;
  195. assign vram32_gpu_d = 32'd0;
  196. VRAM #(
  197. .WIDTH(32),
  198. .WORDS(1056),
  199. .ADDR_BITS(14),
  200. .LIST("memory/vram32.list")
  201. ) vram32(
  202. // CPU port
  203. .cpu_clk (clk),
  204. .cpu_d (vram32_cpu_d),
  205. .cpu_addr (vram32_cpu_addr),
  206. .cpu_we (vram32_cpu_we),
  207. .cpu_q (vram32_cpu_q),
  208. // GPU port
  209. .gpu_clk (clkMuxOut),
  210. .gpu_d (vram32_gpu_d),
  211. .gpu_addr (vram32_gpu_addr),
  212. .gpu_we (vram32_gpu_we),
  213. .gpu_q (vram32_gpu_q)
  214. );
  215. //---------------------------VRAM322--------------------------------
  216. // VRAM322 I/O
  217. wire vram322_gpu_clk;
  218. wire [13:0] vram322_gpu_addr;
  219. wire [31:0] vram322_gpu_d;
  220. wire vram322_gpu_we;
  221. wire [31:0] vram322_gpu_q;
  222. // FSX will not write to VRAM
  223. assign vram322_gpu_we = 1'b0;
  224. assign vram322_gpu_d = 32'd0;
  225. VRAM #(
  226. .WIDTH(32),
  227. .WORDS(1056),
  228. .ADDR_BITS(14),
  229. .LIST("memory/vram32.list")
  230. ) vram322(
  231. // CPU port
  232. .cpu_clk (clk),
  233. .cpu_d (vram32_cpu_d),
  234. .cpu_addr (vram32_cpu_addr),
  235. .cpu_we (vram32_cpu_we),
  236. .cpu_q (),
  237. // GPU port
  238. .gpu_clk (clkMuxOut),
  239. .gpu_d (vram322_gpu_d),
  240. .gpu_addr (vram322_gpu_addr),
  241. .gpu_we (vram322_gpu_we),
  242. .gpu_q (vram322_gpu_q)
  243. );
  244. //--------------------------VRAM8--------------------------------
  245. //VRAM8 I/O
  246. wire vram8_gpu_clk;
  247. wire [13:0] vram8_gpu_addr;
  248. wire [7:0] vram8_gpu_d;
  249. wire vram8_gpu_we;
  250. wire [7:0] vram8_gpu_q;
  251. wire vram8_cpu_clk;
  252. wire [13:0] vram8_cpu_addr;
  253. wire [7:0] vram8_cpu_d;
  254. wire vram8_cpu_we;
  255. wire [7:0] vram8_cpu_q;
  256. // FSX will not write to VRAM
  257. assign vram8_gpu_we = 1'b0;
  258. assign vram8_gpu_d = 8'd0;
  259. VRAM #(
  260. .WIDTH(8),
  261. .WORDS(8194),
  262. .ADDR_BITS(14),
  263. .LIST("memory/vram8.list")
  264. ) vram8(
  265. // CPU port
  266. .cpu_clk (clk),
  267. .cpu_d (vram8_cpu_d),
  268. .cpu_addr (vram8_cpu_addr),
  269. .cpu_we (vram8_cpu_we),
  270. .cpu_q (vram8_cpu_q),
  271. // GPU port
  272. .gpu_clk (clkMuxOut),
  273. .gpu_d (vram8_gpu_d),
  274. .gpu_addr (vram8_gpu_addr),
  275. .gpu_we (vram8_gpu_we),
  276. .gpu_q (vram8_gpu_q)
  277. );
  278. //--------------------------VRAMSPR--------------------------------
  279. //VRAMSPR I/O
  280. wire vramSPR_gpu_clk;
  281. wire [13:0] vramSPR_gpu_addr;
  282. wire [8:0] vramSPR_gpu_d;
  283. wire vramSPR_gpu_we;
  284. wire [8:0] vramSPR_gpu_q;
  285. wire vramSPR_cpu_clk;
  286. wire [13:0] vramSPR_cpu_addr;
  287. wire [8:0] vramSPR_cpu_d;
  288. wire vramSPR_cpu_we;
  289. wire [8:0] vramSPR_cpu_q;
  290. // FSX will not write to VRAM
  291. assign vramSPR_gpu_we = 1'b0;
  292. assign vramSPR_gpu_d = 9'd0;
  293. VRAM #(
  294. .WIDTH(9),
  295. .WORDS(256),
  296. .ADDR_BITS(14),
  297. .LIST("memory/vramSPR.list")
  298. ) vramSPR(
  299. // CPU port
  300. .cpu_clk (clk),
  301. .cpu_d (vramSPR_cpu_d),
  302. .cpu_addr (vramSPR_cpu_addr),
  303. .cpu_we (vramSPR_cpu_we),
  304. .cpu_q (vramSPR_cpu_q),
  305. // GPU port
  306. .gpu_clk (clkMuxOut),
  307. .gpu_d (vramSPR_gpu_d),
  308. .gpu_addr (vramSPR_gpu_addr),
  309. .gpu_we (vramSPR_gpu_we),
  310. .gpu_q (vramSPR_gpu_q)
  311. );
  312. //--------------------------VRAMPX--------------------------------
  313. //VRAMPX I/O
  314. wire vramPX_gpu_clk;
  315. wire [16:0] vramPX_gpu_addr;
  316. wire [7:0] vramPX_gpu_d;
  317. wire vramPX_gpu_we;
  318. wire [7:0] vramPX_gpu_q;
  319. wire vramPX_cpu_clk;
  320. wire [16:0] vramPX_cpu_addr;
  321. wire [7:0] vramPX_cpu_d;
  322. wire vramPX_cpu_we;
  323. wire [7:0] vramPX_cpu_q;
  324. // FSX will not write to VRAM
  325. assign vramPX_gpu_we = 1'b0;
  326. assign vramPX_gpu_d = 8'd0;
  327. VRAM #(
  328. .WIDTH(8),
  329. .WORDS(76800),
  330. .ADDR_BITS(17),
  331. .LIST("memory/vramPX.list")
  332. ) vramPX(
  333. // CPU port
  334. .cpu_clk (clk),
  335. .cpu_d (vramPX_cpu_d),
  336. .cpu_addr (vramPX_cpu_addr),
  337. .cpu_we (vramPX_cpu_we),
  338. .cpu_q (vramPX_cpu_q),
  339. // GPU port
  340. .gpu_clk (clkMuxOut),
  341. .gpu_d (vramPX_gpu_d),
  342. .gpu_addr (vramPX_gpu_addr),
  343. .gpu_we (vramPX_gpu_we),
  344. .gpu_q (vramPX_gpu_q)
  345. );
  346. //-------------------ROM-------------------------
  347. // ROM I/O
  348. wire [8:0] rom_addr;
  349. wire [31:0] rom_q;
  350. ROM rom(
  351. .clk (clk),
  352. .reset (reset),
  353. .address (rom_addr),
  354. .q (rom_q)
  355. );
  356. //----------------SDRAM Controller------------------
  357. // inputs
  358. wire [23:0] sdc_addr; // address to write or to start reading from
  359. wire [31:0] sdc_data; // data to write
  360. wire sdc_we; // write enable
  361. wire sdc_start; // start trigger
  362. // outputs
  363. wire [31:0] sdc_q; // memory output
  364. wire sdc_done; // output ready
  365. SDRAMcontroller sdramcontroller(
  366. // clock/reset inputs
  367. .clk (clk_SDRAM),
  368. .reset (reset),
  369. // interface inputs
  370. .sdc_addr (sdc_addr),
  371. .sdc_data (sdc_data),
  372. .sdc_we (sdc_we),
  373. .sdc_start (sdc_start),
  374. // interface outputs
  375. .sdc_q (sdc_q),
  376. .sdc_done (sdc_done),
  377. // SDRAM signals
  378. .SDRAM_CKE (SDRAM_CKE),
  379. .SDRAM_CSn (SDRAM_CSn),
  380. .SDRAM_WEn (SDRAM_WEn),
  381. .SDRAM_CASn (SDRAM_CASn),
  382. .SDRAM_RASn (SDRAM_RASn),
  383. .SDRAM_A (SDRAM_A),
  384. .SDRAM_BA (SDRAM_BA),
  385. .SDRAM_DQM (SDRAM_DQM),
  386. .SDRAM_DQ (SDRAM_DQ)
  387. );
  388. //-----------------------FSX-------------------------
  389. // FSX I/O
  390. //wire [7:0] composite; // NTSC composite video signal
  391. FSX fsx(
  392. // Clocks
  393. .clkPixel (clkPixel),
  394. .clkTMDShalf (clkTMDShalf),
  395. .clk14 (clk14),
  396. .clk114 (clk114),
  397. .clkMuxOut (clkMuxOut),
  398. // HDMI
  399. .TMDS_p (TMDS_p),
  400. .TMDS_n (TMDS_n),
  401. // NTSC composite
  402. .composite (composite),
  403. // Select output method
  404. .selectOutput (selectOutput),
  405. // VRAM32
  406. .vram32_addr (vram32_gpu_addr),
  407. .vram32_q (vram32_gpu_q),
  408. // VRAM32
  409. .vram322_addr (vram322_gpu_addr),
  410. .vram322_q (vram322_gpu_q),
  411. // VRAM8
  412. .vram8_addr (vram8_gpu_addr),
  413. .vram8_q (vram8_gpu_q),
  414. // VRAMSPR
  415. .vramSPR_addr (vramSPR_gpu_addr),
  416. .vramSPR_q (vramSPR_gpu_q),
  417. //VRAMPX
  418. .vramPX_addr (vramPX_gpu_addr),
  419. .vramPX_q (vramPX_gpu_q),
  420. // Interrupt signal
  421. .frameDrawn (frameDrawn)
  422. );
  423. //----------------Memory Unit--------------------
  424. // Memory Unit I/O
  425. // Bus
  426. wire [26:0] bus_addr;
  427. wire [31:0] bus_data;
  428. wire bus_we;
  429. wire bus_start;
  430. wire [31:0] bus_q;
  431. wire bus_done;
  432. // Interrupt signals
  433. wire OST1_int, OST2_int, OST3_int;
  434. wire UART0_rx_int, UART2_rx_int;
  435. wire PS2_int;
  436. wire SPI0_QSPI;
  437. MemoryUnit mu(
  438. // Clocks
  439. .clk (clk),
  440. .reset (reset),
  441. // Bus
  442. .bus_addr (bus_addr),
  443. .bus_data (bus_data),
  444. .bus_we (bus_we),
  445. .bus_start (bus_start),
  446. .bus_q (bus_q),
  447. .bus_done (bus_done),
  448. /********
  449. * MEMORY
  450. ********/
  451. // SPI Flash / SPI0
  452. .SPIflash_data (SPI0_data),
  453. .SPIflash_q (SPI0_q),
  454. .SPIflash_wp (SPI0_wp),
  455. .SPIflash_hold (SPI0_hold),
  456. .SPIflash_cs (SPI0_cs),
  457. .SPIflash_clk (SPI0_clk),
  458. // VRAM32 cpu port
  459. .VRAM32_cpu_d (vram32_cpu_d),
  460. .VRAM32_cpu_addr (vram32_cpu_addr),
  461. .VRAM32_cpu_we (vram32_cpu_we),
  462. .VRAM32_cpu_q (vram32_cpu_q),
  463. // VRAM8 cpu port
  464. .VRAM8_cpu_d (vram8_cpu_d),
  465. .VRAM8_cpu_addr (vram8_cpu_addr),
  466. .VRAM8_cpu_we (vram8_cpu_we),
  467. .VRAM8_cpu_q (vram8_cpu_q),
  468. // VRAMspr cpu port
  469. .VRAMspr_cpu_d (vramSPR_cpu_d),
  470. .VRAMspr_cpu_addr (vramSPR_cpu_addr),
  471. .VRAMspr_cpu_we (vramSPR_cpu_we),
  472. .VRAMspr_cpu_q (vramSPR_cpu_q),
  473. // VRAMpx cpu port
  474. .VRAMpx_cpu_d (vramPX_cpu_d),
  475. .VRAMpx_cpu_addr (vramPX_cpu_addr),
  476. .VRAMpx_cpu_we (vramPX_cpu_we),
  477. .VRAMpx_cpu_q (vramPX_cpu_q),
  478. // ROM
  479. .ROM_addr (rom_addr),
  480. .ROM_q (rom_q),
  481. /********
  482. * I/O
  483. ********/
  484. // UART0 (Main USB)
  485. .UART0_in (UART0_in),
  486. .UART0_out (UART0_out),
  487. .UART0_rx_interrupt (UART0_rx_int),
  488. // UART1 (APU)
  489. /*
  490. .UART1_in (),
  491. .UART1_out (),
  492. .UART1_rx_interrupt (),
  493. */
  494. // UART2 (GP)
  495. .UART2_in (UART2_in),
  496. .UART2_out (UART2_out),
  497. .UART2_rx_interrupt (UART2_rx_int),
  498. //SPI0 (Flash)
  499. //declared under MEMORY
  500. .SPI0_QSPI (SPI0_QSPI),
  501. // SPI1 (USB0/CH376T, bottom)
  502. .SPI1_clk (SPI1_clk),
  503. .SPI1_cs (SPI1_cs),
  504. .SPI1_mosi (SPI1_mosi),
  505. .SPI1_miso (SPI1_miso),
  506. .SPI1_nint (SPI1_nint_stable),
  507. // SPI2 (USB1/CH376T, top)
  508. .SPI2_clk (SPI2_clk),
  509. .SPI2_cs (SPI2_cs),
  510. .SPI2_mosi (SPI2_mosi),
  511. .SPI2_miso (SPI2_miso),
  512. .SPI2_nint (SPI2_nint_stable),
  513. // SPI3 (W5500)
  514. .SPI3_clk (SPI3_clk),
  515. .SPI3_cs (SPI3_cs),
  516. .SPI3_mosi (SPI3_mosi),
  517. .SPI3_miso (SPI3_miso),
  518. .SPI3_int (SPI3_int_stable),
  519. // SPI4 (EXT/GP)
  520. .SPI4_clk (SPI4_clk),
  521. .SPI4_cs (SPI4_cs),
  522. .SPI4_mosi (SPI4_mosi),
  523. .SPI4_miso (SPI4_miso),
  524. .SPI4_GP (SPI4_gp_stable),
  525. // GPIO (Separated GPI and GPO until GPIO module is implemented)
  526. .GPI (GPI[3:0]),
  527. .GPO (GPO[3:0]),
  528. // OStimers
  529. .OST1_int (OST1_int),
  530. .OST2_int (OST2_int),
  531. .OST3_int (OST3_int),
  532. // SNESpad
  533. /*
  534. .SNES_clk (),
  535. .SNES_latch (),
  536. .SNES_data (),
  537. */
  538. // PS/2
  539. .PS2_clk (PS2_clk),
  540. .PS2_data (PS2_data),
  541. .PS2_int (PS2_int), //Scan code ready signal
  542. // Boot mode
  543. .boot_mode (boot_mode_stable)
  544. );
  545. //------------L2 Cache--------------
  546. //CPU bus
  547. wire [23:0] l2_addr; // address to write or to start reading from
  548. wire [31:0] l2_data; // data to write
  549. wire l2_we; // write enable
  550. wire l2_start; // start trigger
  551. wire [31:0] l2_q; // memory output
  552. wire l2_done; // output ready
  553. L2cache l2cache(
  554. .clk (clk_SDRAM),
  555. .reset (reset),
  556. // CPU bus
  557. .l2_addr (l2_addr),
  558. .l2_data (l2_data),
  559. .l2_we (l2_we),
  560. .l2_start (l2_start),
  561. .l2_q (l2_q),
  562. .l2_done (l2_done),
  563. // sdram bus
  564. .sdc_addr (sdc_addr),
  565. .sdc_data (sdc_data),
  566. .sdc_we (sdc_we),
  567. .sdc_start (sdc_start),
  568. .sdc_q (sdc_q),
  569. .sdc_done (sdc_done)
  570. );
  571. //---------------CPU----------------
  572. // CPU I/O
  573. wire [26:0] PC;
  574. CPU cpu(
  575. // Clock/reset
  576. .clk (clk),
  577. .reset (reset),
  578. .int1 (OST1_int), //OStimer1
  579. .int2 (OST2_int), //OStimer2
  580. .int3 (UART0_rx_int), //UART0 rx (MAIN)
  581. .int4 (frameDrawn_stable), //GPU Frame Drawn
  582. .int5 (OST3_int), //OStimer3
  583. .int6 (PS2_int), //PS/2 scancode ready
  584. .int7 (1'b0), //UART1 rx (APU)
  585. .int8 (UART2_rx_int), //UART2 rx (EXT)
  586. // Bus
  587. .bus_addr (bus_addr),
  588. .bus_data (bus_data),
  589. .bus_we (bus_we),
  590. .bus_start (bus_start),
  591. .bus_q (bus_q),
  592. .bus_done (bus_done),
  593. .PC (PC),
  594. // sdram bus
  595. .sdc_addr (l2_addr),
  596. .sdc_data (l2_data),
  597. .sdc_we (l2_we),
  598. .sdc_start (l2_start),
  599. .sdc_q (l2_q),
  600. .sdc_done (l2_done)
  601. );
  602. //-----------STATUS LEDS-----------
  603. assign led_Booted = (PC >= 27'hC02522 | reset);
  604. assign led_HDMI = (~selectOutput | reset);
  605. assign led_QSPI = (~SPI0_QSPI | reset);
  606. LEDvisualizer #(.MIN_CLK(100000))
  607. LEDvisUSB0
  608. (
  609. .clk(clk),
  610. .reset(reset),
  611. .activity(~SPI1_cs),
  612. .LED(led_USB0)
  613. );
  614. LEDvisualizer #(.MIN_CLK(100000))
  615. LEDvisUSB1
  616. (
  617. .clk(clk),
  618. .reset(reset),
  619. .activity(~SPI2_cs),
  620. .LED(led_USB1)
  621. );
  622. LEDvisualizer #(.MIN_CLK(100000))
  623. LEDvisEth
  624. (
  625. .clk(clk),
  626. .reset(reset),
  627. .activity(~SPI3_cs),
  628. .LED(led_Eth)
  629. );
  630. LEDvisualizer #(.MIN_CLK(100000))
  631. LEDvisPS2
  632. (
  633. .clk(clk),
  634. .reset(reset),
  635. .activity(PS2_int),
  636. .LED(led_PS2)
  637. );
  638. LEDvisualizer #(.MIN_CLK(100000))
  639. LEDvisFlash
  640. (
  641. .clk(clk),
  642. .reset(reset),
  643. .activity(~SPI0_cs),
  644. .LED(led_Flash)
  645. );
  646. LEDvisualizer #(.MIN_CLK(100000))
  647. LEDvisGPU
  648. (
  649. .clk(clk),
  650. .reset(reset),
  651. .activity(vram32_cpu_we|vram8_cpu_we|vramSPR_cpu_we|vramPX_cpu_we),
  652. .LED(led_GPU)
  653. );
  654. LEDvisualizer #(.MIN_CLK(100000))
  655. LEDvisI2S
  656. (
  657. .clk(clk),
  658. .reset(reset),
  659. .activity(I2S_SDIN),
  660. .LED(led_I2S)
  661. );
  662. endmodule