SummerCart64/fw/rtl/cpu/cpu_cfg.sv

128 lines
4.1 KiB
Systemverilog
Raw Normal View History

2021-08-23 21:40:37 +02:00
module cpu_cfg (
if_system.sys sys,
if_cpu_bus bus,
if_config.cpu cfg
);
2021-09-13 22:16:19 +02:00
logic skip_bootloader;
2021-08-23 21:40:37 +02:00
typedef enum bit [2:0] {
R_SCR,
R_DD_OFFSET,
R_SAVE_OFFSET,
R_COMMAND,
2021-08-27 21:43:30 +02:00
R_DATA_0,
2021-09-01 17:21:41 +02:00
R_DATA_1,
R_VERSION
2021-08-23 21:40:37 +02:00
} e_reg_id;
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
case (bus.address[4:2])
R_SCR: bus.rdata = {
2021-08-27 21:43:30 +02:00
cfg.cpu_ready,
2021-08-23 21:40:37 +02:00
cfg.cpu_busy,
2021-09-01 17:21:41 +02:00
cfg.usb_waiting,
cfg.cmd_error,
2021-09-13 22:16:19 +02:00
21'd0,
skip_bootloader,
2021-08-23 21:40:37 +02:00
cfg.flashram_enabled,
2021-08-28 02:37:02 +02:00
cfg.sram_banked,
2021-08-23 21:40:37 +02:00
cfg.sram_enabled,
cfg.dd_enabled,
cfg.sdram_writable,
cfg.sdram_switch
};
R_DD_OFFSET: bus.rdata = {6'd0, cfg.dd_offset};
R_SAVE_OFFSET: bus.rdata = {6'd0, cfg.save_offset};
2021-08-27 21:43:30 +02:00
R_COMMAND: bus.rdata = {24'd0, cfg.cmd};
R_DATA_0: bus.rdata = cfg.data[0];
R_DATA_1: bus.rdata = cfg.data[1];
2021-09-01 17:21:41 +02:00
R_VERSION: bus.rdata = sc64::SC64_VER;
2021-08-27 21:43:30 +02:00
default: bus.rdata = 32'd0;
2021-08-23 21:40:37 +02:00
endcase
end
end
2021-08-27 21:43:30 +02:00
always_comb begin
cfg.wdata = bus.wdata;
cfg.data_write = 2'b00;
if (bus.request && (&bus.wmask)) begin
cfg.data_write[0] = bus.address[4:2] == R_DATA_0;
cfg.data_write[1] = bus.address[4:2] == R_DATA_1;
end
end
2021-08-23 21:40:37 +02:00
always_ff @(posedge sys.clk) begin
if (sys.reset) begin
2021-08-27 21:43:30 +02:00
cfg.cpu_ready <= 1'b0;
2021-08-23 21:40:37 +02:00
cfg.cpu_busy <= 1'b0;
2021-09-01 17:21:41 +02:00
cfg.usb_waiting <= 1'b0;
cfg.cmd_error <= 1'b0;
2021-08-23 21:40:37 +02:00
cfg.sdram_switch <= 1'b0;
cfg.sdram_writable <= 1'b0;
cfg.dd_enabled <= 1'b0;
cfg.sram_enabled <= 1'b0;
2021-08-28 02:37:02 +02:00
cfg.sram_banked <= 1'b0;
2021-08-23 21:40:37 +02:00
cfg.flashram_enabled <= 1'b0;
cfg.dd_offset <= 26'h3BE_0000;
cfg.save_offset <= 26'h3FE_0000;
2021-09-13 22:16:19 +02:00
skip_bootloader <= 1'b0;
2021-08-23 21:40:37 +02:00
end else begin
if (sys.n64_soft_reset) begin
2021-09-13 22:16:19 +02:00
cfg.sdram_switch <= skip_bootloader;
2021-08-27 21:43:30 +02:00
cfg.sdram_writable <= 1'b0;
2021-08-23 21:40:37 +02:00
end
2021-08-27 21:43:30 +02:00
if (cfg.cmd_request) begin
2021-08-23 21:40:37 +02:00
cfg.cpu_busy <= 1'b1;
end
if (bus.request) begin
case (bus.address[4:2])
R_SCR: begin
if (bus.wmask[3]) begin
2021-09-01 17:21:41 +02:00
{
cfg.cpu_ready,
cfg.cpu_busy,
cfg.usb_waiting,
cfg.cmd_error
} <= bus.wdata[31:28];
2021-08-23 21:40:37 +02:00
end
if (bus.wmask[0]) begin
{
2021-09-13 22:16:19 +02:00
skip_bootloader,
2021-08-23 21:40:37 +02:00
cfg.flashram_enabled,
2021-08-28 02:37:02 +02:00
cfg.sram_banked,
2021-08-23 21:40:37 +02:00
cfg.sram_enabled,
cfg.dd_enabled,
cfg.sdram_writable,
cfg.sdram_switch
2021-09-13 22:16:19 +02:00
} <= bus.wdata[6:0];
2021-08-23 21:40:37 +02:00
end
end
R_DD_OFFSET: begin
if (&bus.wmask) begin
cfg.dd_offset <= bus.wdata[25:0];
end
end
R_SAVE_OFFSET: begin
if (&bus.wmask) begin
cfg.save_offset <= bus.wdata[25:0];
end
end
endcase
end
end
end
endmodule