VRAM.v 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Dual port, Dual clock VRAM implementation
  3. * One port is accessed by the CPU, the other is accessed by the GPU
  4. */
  5. module VRAM
  6. #(
  7. parameter WIDTH = 32,
  8. parameter WORDS = 1056,
  9. parameter ADDR_BITS = 11,
  10. parameter LIST = "/home/bart/Documents/FPGA/FPGC6/Verilog/memory/vram32.list"
  11. )
  12. (
  13. input cpu_clk,
  14. input [WIDTH-1:0] cpu_d,
  15. input [ADDR_BITS-1:0] cpu_addr,
  16. input cpu_we,
  17. output reg [WIDTH-1:0] cpu_q,
  18. input gpu_clk,
  19. input [WIDTH-1:0] gpu_d,
  20. input [ADDR_BITS-1:0] gpu_addr,
  21. input gpu_we,
  22. output reg [WIDTH-1:0] gpu_q
  23. );
  24. reg [WIDTH-1:0] ram [0:WORDS-1]; //basically the memory cells
  25. //cpu port
  26. always @(posedge cpu_clk)
  27. begin
  28. cpu_q <= ram[cpu_addr];
  29. if (cpu_we)
  30. begin
  31. cpu_q <= cpu_d;
  32. ram[cpu_addr] <= cpu_d;
  33. end
  34. end
  35. //gpu port
  36. always @(posedge gpu_clk)
  37. begin
  38. gpu_q <= ram[gpu_addr];
  39. if (gpu_we)
  40. begin
  41. gpu_q <= gpu_d;
  42. ram[gpu_addr] <= gpu_d;
  43. end
  44. end
  45. //initialize VRAM
  46. initial
  47. begin
  48. $readmemb(LIST, ram);
  49. end
  50. endmodule