2021-08-20 19:51:55 +02:00
|
|
|
module cpu_ram (
|
|
|
|
if_system.sys sys,
|
|
|
|
if_cpu_bus bus
|
|
|
|
);
|
2021-08-12 21:07:47 +02:00
|
|
|
|
2021-08-20 19:51:55 +02:00
|
|
|
logic [3:0][7:0] ram [0:4095];
|
|
|
|
logic [31:0] q;
|
2021-08-05 19:50:29 +02:00
|
|
|
|
2021-08-20 19:51:55 +02:00
|
|
|
always_ff @(posedge sys.clk) begin
|
|
|
|
bus.ack <= 1'b0;
|
|
|
|
if (bus.request) begin
|
|
|
|
bus.ack <= 1'b1;
|
|
|
|
end
|
|
|
|
end
|
2021-08-15 21:49:02 +02:00
|
|
|
|
|
|
|
always_comb begin
|
|
|
|
bus.rdata = 32'd0;
|
|
|
|
if (bus.ack) begin
|
2021-08-20 19:51:55 +02:00
|
|
|
bus.rdata = q;
|
2021-08-15 21:49:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-20 19:51:55 +02:00
|
|
|
always_ff @(posedge sys.clk) begin
|
|
|
|
q <= ram[bus.address[13:2]];
|
2021-08-15 21:49:02 +02:00
|
|
|
if (bus.request) begin
|
2021-08-20 19:51:55 +02:00
|
|
|
if (bus.wmask[0]) ram[bus.address[13:2]][0] <= bus.wdata[7:0];
|
|
|
|
if (bus.wmask[1]) ram[bus.address[13:2]][1] <= bus.wdata[15:8];
|
|
|
|
if (bus.wmask[2]) ram[bus.address[13:2]][2] <= bus.wdata[23:16];
|
|
|
|
if (bus.wmask[3]) ram[bus.address[13:2]][3] <= bus.wdata[31:24];
|
2021-08-15 21:49:02 +02:00
|
|
|
end
|
|
|
|
end
|
2021-08-05 19:50:29 +02:00
|
|
|
|
|
|
|
endmodule
|