FPGC_tb.v 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Testbench
  3. * Simulates the entire FPGC
  4. */
  5. // Set timescale
  6. `timescale 1 ns/1 ns
  7. // tld
  8. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/FPGC6.v"
  9. // other logic
  10. `include "/home/bart/Documents/FPGA/FPGC5/Verilog/modules/MultiStabilizer.v"
  11. `include "/home/bart/Documents/FPGA/FPGC5/Verilog/modules/DtrReset.v"
  12. // cpu
  13. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/CPU.v"
  14. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/ALU.v"
  15. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/ControlUnit.v"
  16. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/InstructionDecoder.v"
  17. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/Regbank.v"
  18. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/Stack.v"
  19. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/InstrMem.v"
  20. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/DataMem.v"
  21. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/Regr.v"
  22. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/Arbiter.v"
  23. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/CPU/IntController.v"
  24. // memory
  25. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/VRAM.v"
  26. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/mt48lc16m16a2.v"
  27. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/w25q128jv.v"
  28. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/SDRAMcontroller.v"
  29. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/SPIreader.v"
  30. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/ROM.v"
  31. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/MemoryUnit.v"
  32. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/L2cache.v"
  33. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/L1Icache.v"
  34. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/Memory/L1Dcache.v"
  35. // io
  36. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/Keyboard.v"
  37. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/OStimer.v"
  38. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/UARTtx.v"
  39. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/UARTrx.v"
  40. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/SimpleSPI.v"
  41. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/LEDvisualizer.v"
  42. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/IO/Divider.v"
  43. // gpu
  44. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/FSX.v"
  45. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/BGWrenderer.v"
  46. //`include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/Spriterenderer.v"
  47. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/PixelEngine.v"
  48. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/TimingGenerator.v"
  49. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/HDMI/RGB2HDMI.v"
  50. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/HDMI/TMDSenc.v"
  51. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/HDMI/lvds.v"
  52. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/HDMI/ddr.v"
  53. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/NTSC/NTSC.v"
  54. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/NTSC/PhaseGen.v"
  55. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/NTSC/RGB332toNTSC.v"
  56. `include "/home/bart/Documents/FPGA/FPGC6/Verilog/modules/GPU/NTSC/RGBtoYPhaseAmpl.v"
  57. // Define testmodule
  58. module FPGC_tb;
  59. //Clock I/O
  60. reg clk;
  61. reg clk_SDRAM;
  62. reg nreset;
  63. //SPI0 Flash
  64. wire SPI0_clk;
  65. wire SPI0_cs;
  66. wire SPI0_data;
  67. wire SPI0_wp;
  68. wire SPI0_q;
  69. wire SPI0_hold;
  70. W25Q128JV spiFlash (
  71. .CLK (SPI0_clk),
  72. .DIO (SPI0_data),
  73. .CSn (SPI0_cs),
  74. .WPn (SPI0_wp),
  75. .HOLDn (SPI0_hold),
  76. .DO (SPI0_q)
  77. );
  78. //SDRAM
  79. wire SDRAM_CLK; // SDRAM clock
  80. wire [31 : 0] SDRAM_DQ; // SDRAM I/O
  81. wire [12 : 0] SDRAM_A; // SDRAM Address
  82. wire [1 : 0] SDRAM_BA; // Bank Address
  83. wire SDRAM_CKE; // Synchronous Clock Enable
  84. wire SDRAM_CSn; // CS#
  85. wire SDRAM_RASn; // RAS#
  86. wire SDRAM_CASn; // CAS#
  87. wire SDRAM_WEn; // WE#
  88. wire [3 : 0] SDRAM_DQM; // Mask
  89. assign SDRAM_CLK = clk_SDRAM;
  90. mt48lc16m16a2 sdram1 (
  91. .Dq (SDRAM_DQ[15:0]),
  92. .Addr (SDRAM_A),
  93. .Ba (SDRAM_BA),
  94. .Clk (SDRAM_CLK),
  95. .Cke (SDRAM_CKE),
  96. .Cs_n (SDRAM_CSn),
  97. .Ras_n (SDRAM_RASn),
  98. .Cas_n (SDRAM_CASn),
  99. .We_n (SDRAM_WEn),
  100. .Dqm (SDRAM_DQM[1:0])
  101. );
  102. mt48lc16m16a2 sdram2 (
  103. .Dq (SDRAM_DQ[31:16]),
  104. .Addr (SDRAM_A),
  105. .Ba (SDRAM_BA),
  106. .Clk (SDRAM_CLK),
  107. .Cke (SDRAM_CKE),
  108. .Cs_n (SDRAM_CSn),
  109. .Ras_n (SDRAM_RASn),
  110. .Cas_n (SDRAM_CASn),
  111. .We_n (SDRAM_WEn),
  112. .Dqm (SDRAM_DQM[3:2])
  113. );
  114. //HDMI
  115. wire [3:0] TMDS_p;
  116. wire [3:0] TMDS_n;
  117. //SPI1
  118. wire SPI1_clk;
  119. wire SPI1_cs;
  120. wire SPI1_mosi;
  121. wire SPI1_miso;
  122. assign SPI1_miso = 1'b1;
  123. wire SPI1_rst;
  124. reg SPI1_nint;
  125. //SPI2
  126. wire SPI2_clk;
  127. wire SPI2_cs;
  128. wire SPI2_mosi;
  129. wire SPI2_miso;
  130. wire SPI2_rst;
  131. reg SPI2_nint;
  132. //SPI3
  133. wire SPI3_clk;
  134. wire SPI3_cs;
  135. wire SPI3_mosi;
  136. wire SPI3_miso;
  137. wire SPI3_nrst;
  138. reg SPI3_int;
  139. //SPI4
  140. wire SPI4_clk;
  141. wire SPI4_cs;
  142. wire SPI4_mosi;
  143. wire SPI4_miso;
  144. reg SPI4_gp;
  145. //UART0
  146. reg UART0_in;
  147. wire UART0_out;
  148. reg UART0_dtr;
  149. //UART1
  150. //reg UART1_in;
  151. //wire UART1_out;
  152. //UART2
  153. reg UART2_in;
  154. wire UART2_out;
  155. //PS/2
  156. reg PS2_clk;
  157. reg PS2_data;
  158. //Led
  159. wire led;
  160. //GPIO
  161. wire [3:0] GPO;
  162. reg [3:0] GPI;
  163. //DIP Switch
  164. reg [3:0] DIPS;
  165. FPGC6 fpgc (
  166. .clk(clk),
  167. .clk_SDRAM(clk_SDRAM),
  168. .nreset(nreset),
  169. //HDMI
  170. .TMDS_p(TMDS_p),
  171. .TMDS_n(TMDS_n),
  172. //SDRAM
  173. .SDRAM_CLK(SDRAM_CLK),
  174. .SDRAM_CSn(SDRAM_CSn),
  175. .SDRAM_WEn(SDRAM_WEn),
  176. .SDRAM_CASn(SDRAM_CASn),
  177. .SDRAM_RASn(SDRAM_RASn),
  178. .SDRAM_CKE(SDRAM_CKE),
  179. .SDRAM_A(SDRAM_A),
  180. .SDRAM_BA(SDRAM_BA),
  181. .SDRAM_DQM(SDRAM_DQM),
  182. .SDRAM_DQ(SDRAM_DQ),
  183. //SPI0 flash
  184. .SPI0_clk(SPI0_clk),
  185. .SPI0_cs(SPI0_cs),
  186. .SPI0_data(SPI0_data),
  187. .SPI0_q(SPI0_q),
  188. .SPI0_wp(SPI0_wp),
  189. .SPI0_hold(SPI0_hold),
  190. //SPI1 CH376 bottom
  191. .SPI1_clk(SPI1_clk),
  192. .SPI1_cs(SPI1_cs),
  193. .SPI1_mosi(SPI1_mosi),
  194. .SPI1_miso(SPI1_miso),
  195. .SPI1_nint(SPI1_nint),
  196. .SPI1_rst(SPI1_rst),
  197. //SPI2 CH376 top
  198. .SPI2_clk(SPI2_clk),
  199. .SPI2_cs(SPI2_cs),
  200. .SPI2_mosi(SPI2_mosi),
  201. .SPI2_miso(SPI2_miso),
  202. .SPI2_nint(SPI2_nint),
  203. .SPI2_rst(SPI2_rst),
  204. //SPI3 W5500
  205. .SPI3_clk(SPI3_clk),
  206. .SPI3_cs(SPI3_cs),
  207. .SPI3_mosi(SPI3_mosi),
  208. .SPI3_miso(SPI3_miso),
  209. .SPI3_int(SPI3_int),
  210. .SPI3_nrst(SPI3_nrst),
  211. //SPI4 GP
  212. .SPI4_clk(SPI4_clk),
  213. .SPI4_cs(SPI4_cs),
  214. .SPI4_mosi(SPI4_mosi),
  215. .SPI4_miso(SPI4_miso),
  216. .SPI4_gp(SPI4_gp),
  217. //UART0
  218. .UART0_in(UART0_in),
  219. .UART0_out(UART0_out),
  220. .UART0_dtr(UART0_dtr),
  221. //UART1
  222. //.UART1_in(UART1_in),
  223. //.UART1_out(UART1_out),
  224. //UART2
  225. .UART2_in(UART2_in),
  226. .UART2_out(UART2_out),
  227. //PS/2
  228. .PS2_clk(PS2_clk),
  229. .PS2_data(PS2_data),
  230. //Led for debugging
  231. .led(led),
  232. //GPIO
  233. .GPI(GPI),
  234. .GPO(GPO),
  235. //DIP switch
  236. .DIPS(DIPS)
  237. );
  238. initial
  239. begin
  240. //Dump everything for GTKwave
  241. $dumpfile("/home/bart/Documents/FPGA/FPGC6/Verilog/output/wave.vcd");
  242. $dumpvars;
  243. clk = 0;
  244. clk_SDRAM = 0;
  245. nreset = 1;
  246. SPI1_nint = 1;
  247. SPI2_nint = 1;
  248. SPI3_int = 0;
  249. SPI4_gp = 1;
  250. UART0_in = 1;
  251. UART0_dtr = 1;
  252. //UART1_in = 1;
  253. UART2_in = 1;
  254. PS2_clk = 1;
  255. PS2_data = 0;
  256. GPI = 4'b1111;
  257. DIPS = 4'b0000;
  258. DIPS[0] = 0; // spi = 0, uart = 1
  259. repeat(10)
  260. begin
  261. #5 clk_SDRAM = ~clk_SDRAM; clk = ~clk; //50MHz
  262. #5 clk_SDRAM = ~clk_SDRAM; //100MHz
  263. end
  264. nreset = 0;
  265. repeat(10)
  266. begin
  267. #5 clk_SDRAM = ~clk_SDRAM; clk = ~clk; //50MHz
  268. #5 clk_SDRAM = ~clk_SDRAM; //100MHz
  269. end
  270. nreset = 1;
  271. repeat(30000)
  272. begin
  273. #5 clk_SDRAM = ~clk_SDRAM; clk = ~clk; //50MHz
  274. #5 clk_SDRAM = ~clk_SDRAM; //100MHz
  275. end
  276. repeat(20000)
  277. begin
  278. #5 clk_SDRAM = ~clk_SDRAM; clk = ~clk; //50MHz
  279. #5 clk_SDRAM = ~clk_SDRAM; //100MHz
  280. end
  281. #1 $finish;
  282. end
  283. endmodule