2021-09-25 20:00:36 +02:00
|
|
|
module cpu_ram (
|
|
|
|
if_system.sys sys,
|
2022-02-02 19:07:43 +01:00
|
|
|
if_cpu_bus bus
|
2021-09-25 20:00:36 +02:00
|
|
|
);
|
|
|
|
|
2022-02-02 19:07:43 +01:00
|
|
|
logic [3:0][7:0] ram [0:8191];
|
|
|
|
logic [31:0] q;
|
2021-09-25 20:00:36 +02:00
|
|
|
|
|
|
|
always_ff @(posedge sys.clk) begin
|
|
|
|
bus.ack <= 1'b0;
|
|
|
|
if (bus.request) begin
|
|
|
|
bus.ack <= 1'b1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
always_comb begin
|
|
|
|
bus.rdata = 32'd0;
|
|
|
|
if (bus.ack) begin
|
2022-02-02 19:07:43 +01:00
|
|
|
bus.rdata = q;
|
2021-09-25 20:00:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-20 20:28:59 +01:00
|
|
|
always_ff @(posedge sys.clk) begin
|
2022-02-02 19:07:43 +01:00
|
|
|
q <= ram[bus.address[14:2]];
|
2021-09-25 20:00:36 +02:00
|
|
|
if (bus.request) begin
|
2022-02-02 19:07:43 +01:00
|
|
|
if (bus.wmask[0]) ram[bus.address[14:2]][0] <= bus.wdata[7:0];
|
|
|
|
if (bus.wmask[1]) ram[bus.address[14:2]][1] <= bus.wdata[15:8];
|
|
|
|
if (bus.wmask[2]) ram[bus.address[14:2]][2] <= bus.wdata[23:16];
|
|
|
|
if (bus.wmask[3]) ram[bus.address[14:2]][3] <= bus.wdata[31:24];
|
2022-01-20 20:28:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-25 20:00:36 +02:00
|
|
|
endmodule
|