1
0

FPGC_tb.v 8.2 KB

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