module inram_controller(
input rst,
input clk,
input os_write_lock,
input [31:0] addr,
input [31:0] data2mem,
output reg [31:0] data2cpu,
input re,
input we,
output reg done
);
wire p=re|we;
reg [9:0] mem_addr;
reg [1:0] state;
reg [31:0] tmp_mem;
parameter [1:0] inram_idle = 2'd0;
parameter [1:0] inram_op = 2'd1;
parameter [1:0] inram_skip = 2'd2;
reg [31:0] memory[1023:0]; //1024*4=4kb
integer n;
initial begin
for (n = 0; n < 1024; n = n + 1) memory[n] = 0;
memory[0] = 32'h0B0B0B0B;
memory[1] = 32'h80A00894;
memory[2] = 32'h0B0C0A81;
memory[3] = 32'h800B0B0B;
memory[4] = 32'h00000004;
memory[5] = 32'hFFFFFFFF;
end
always @(posedge clk)
begin
if (rst) begin
//$display("inram_reset");
state <= inram_idle;
data2cpu <= 0;
done <= 0;
mem_addr <= 0;
end else begin
case (state)
inram_idle: begin
//$display("inram_idle: we=%d, re=%d", we, re);
done <= 0;
if (p) begin
state <= inram_op;
mem_addr <=a ddr[11:2];
tmp_mem <= data2mem;
end
end
inram_op: begin
$display("inram_op: %d(%d), we=%d, re=%d", addr, mem_addr, we, re);
if (we) memory[mem_addr] <= tmp_mem;
else if (re) data2cpu <= memory[mem_addr];
done <= 1;
state <= inram_skip;
end
inram_skip: begin
done <= 0;
state <= inram_idle;
mem_addr <= 0;
end
endcase
end
end
endmodule