1
0

mu.v 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. assign bus_done = (bus_addr < 8) ? bus_start : bus_done_reg;
  42. assign bus_ready = bus_ready_reg;
  43. always @(posedge clk)
  44. begin
  45. if (reset)
  46. begin
  47. bus_done_reg <= 1'b0;
  48. bus_ready_reg <= 1'b0;
  49. bus_done_next <= 1'b0;
  50. end
  51. else
  52. begin
  53. bus_done_reg <= 1'b0;
  54. bus_ready_reg <= 1'b1;
  55. if (bus_done_next)
  56. begin
  57. bus_done_next <= 1'b0;
  58. bus_ready_reg <= 1'b0;
  59. bus_done_reg <= 1'b1;
  60. end
  61. else if (bus_addr >= 8)
  62. begin
  63. if (bus_start)
  64. begin
  65. bus_ready_reg <= 1'b0;
  66. end
  67. else if (!bus_ready_reg)
  68. begin
  69. bus_done_next <= 1'b1;
  70. bus_ready_reg <= 1'b1;
  71. end
  72. end
  73. end
  74. end
  75. endmodule