SummerCart64/fw/rtl/memory/memory_flash.sv

77 lines
1.9 KiB
Systemverilog
Raw Normal View History

2021-08-20 19:51:55 +02:00
module memory_flash (
if_system.sys sys,
2021-08-21 04:35:40 +02:00
input request,
output ack,
input [31:0] address,
output [15:0] rdata
2021-08-20 19:51:55 +02:00
);
logic flash_enable;
logic flash_request;
logic flash_busy;
logic flash_ack;
logic [31:0] flash_rdata;
logic dummy_ack;
always_comb begin
2021-08-21 04:35:40 +02:00
flash_enable = address < 32'h10016800;
2021-08-20 19:51:55 +02:00
2021-08-21 04:35:40 +02:00
ack = flash_ack | dummy_ack;
2021-08-20 19:51:55 +02:00
2021-08-21 04:35:40 +02:00
rdata = 16'd0;
if (ack && flash_enable) begin
if (address[1]) rdata = {flash_rdata[23:16], flash_rdata[31:24]};
else rdata = {flash_rdata[7:0], flash_rdata[15:8]};
2021-08-20 19:51:55 +02:00
end
end
2021-08-21 04:35:40 +02:00
typedef enum bit [0:0] {
S_IDLE,
S_WAIT
} e_state;
e_state state;
2021-08-20 19:51:55 +02:00
always_ff @(posedge sys.clk) begin
2021-08-21 23:51:54 +02:00
dummy_ack <= 1'b0;
2021-08-21 04:35:40 +02:00
2021-08-20 19:51:55 +02:00
if (sys.reset) begin
2021-08-21 04:35:40 +02:00
state <= S_IDLE;
2021-08-20 19:51:55 +02:00
flash_request <= 1'b0;
end else begin
2021-08-21 04:35:40 +02:00
case (state)
S_IDLE: begin
if (request) begin
state <= S_WAIT;
flash_request <= flash_enable;
dummy_ack <= !flash_enable;
end
end
S_WAIT: begin
if (!flash_busy) begin
flash_request <= 1'b0;
end
if (ack) begin
state <= S_IDLE;
end
2021-08-20 19:51:55 +02:00
end
2021-08-21 04:35:40 +02:00
endcase
2021-08-20 19:51:55 +02:00
end
end
intel_flash intel_flash_inst (
.clock(sys.clk),
.reset_n(~sys.reset),
2021-08-21 04:35:40 +02:00
.avmm_data_addr(address[31:2]),
.avmm_data_read(flash_request),
2021-08-20 19:51:55 +02:00
.avmm_data_readdata(flash_rdata),
.avmm_data_waitrequest(flash_busy),
.avmm_data_readdatavalid(flash_ack),
.avmm_data_burstcount(2'd1)
);
endmodule