Files
stack/testbram.v
2026-03-07 23:45:11 -05:00

39 lines
893 B
Verilog

module testbram
(input i_clk,
input i_rst,
input i_dir,
input [1:0] i_act,
input [31:0] i_addr,
input [31:0] i_data,
output reg [31:0] o_data,
output o_we);
(* ram_style = "block" *)
reg [31:0] sram [4095:0];
(* ram_style = "block" *)
reg [31:0] srom [4095:0];
wire use_ram = (i_addr >= 32'h00004000) && (i_addr < 32'h00008000);
wire use_rom = (i_addr < 32'h00004000);
assign o_we = ~i_dir && (i_act != 2'b00);
// WRITE - simplest possible
always @(posedge i_clk) begin
if (i_dir && use_ram)
sram[i_addr[13:2]] <= i_data;
end
// READ - simplest possible
always @(posedge i_clk) begin
if (use_ram)
o_data <= sram[i_addr[13:2]];
else if (use_rom)
o_data <= srom[i_addr[13:2]];
else
o_data <= 32'h0;
end
endmodule