MemoryUnitSimplified.v 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module MemoryUnit(
  2. // Clocks
  3. input clk,
  4. input reset,
  5. // Bus
  6. input [26:0] bus_addr,
  7. input [31:0] bus_data,
  8. input bus_we,
  9. input bus_start,
  10. output [31:0] bus_q,
  11. output bus_done,
  12. output bus_ready
  13. );
  14. reg bus_done_reg = 1'b0;
  15. reg bus_done_next = 1'b0;
  16. reg bus_ready_reg = 1'b0;
  17. //---------------------------SRAM---------------------------------
  18. //SRAM I/O
  19. wire sram_cpu_clk;
  20. wire [11:0] sram_cpu_addr;
  21. wire [31:0] sram_cpu_d;
  22. wire sram_cpu_we;
  23. wire [31:0] sram_cpu_q;
  24. assign sram_cpu_addr = bus_addr;
  25. assign sram_cpu_d = bus_data;
  26. assign sram_cpu_we = bus_we;
  27. assign bus_q = sram_cpu_q;
  28. SRAM #(
  29. .WIDTH(32),
  30. .WORDS(4096),
  31. .ADDR_BITS(12),
  32. .LIST("/home/bart/Documents/FPGA/FPGC6/Verilog/memory/sram.list")
  33. ) sram(
  34. //CPU port
  35. .cpu_clk (clk),
  36. .cpu_d (sram_cpu_d),
  37. .cpu_addr (sram_cpu_addr),
  38. .cpu_we (sram_cpu_we),
  39. .cpu_q (sram_cpu_q)
  40. );
  41. parameter SLOW_ADDR = 100;
  42. assign bus_done = (bus_addr < SLOW_ADDR) ? bus_start || bus_done_reg : bus_done_reg;
  43. assign bus_ready = bus_ready_reg;
  44. always @(posedge clk)
  45. begin
  46. if (reset)
  47. begin
  48. bus_done_reg <= 1'b0;
  49. bus_ready_reg <= 1'b0;
  50. bus_done_next <= 1'b0;
  51. end
  52. else
  53. begin
  54. bus_done_reg <= 1'b0;
  55. bus_ready_reg <= 1'b1;
  56. if (bus_done_next)
  57. begin
  58. bus_done_next <= 1'b0;
  59. bus_ready_reg <= 1'b0;
  60. bus_done_reg <= 1'b1;
  61. end
  62. else if (bus_addr >= SLOW_ADDR)
  63. begin
  64. if (bus_start)
  65. begin
  66. bus_ready_reg <= 1'b0;
  67. end
  68. else if (!bus_ready_reg)
  69. begin
  70. bus_done_next <= 1'b1;
  71. bus_ready_reg <= 1'b1;
  72. end
  73. end
  74. end
  75. end
  76. endmodule