2021-09-25 20:00:36 +02:00
|
|
|
module cpu_cfg (
|
|
|
|
if_system.sys sys,
|
|
|
|
if_cpu_bus bus,
|
|
|
|
if_config.cpu cfg
|
|
|
|
);
|
|
|
|
|
|
|
|
logic skip_bootloader;
|
2021-10-29 00:19:17 +02:00
|
|
|
logic trigger_reconfiguration;
|
2021-09-25 20:00:36 +02:00
|
|
|
|
|
|
|
typedef enum bit [2:0] {
|
|
|
|
R_SCR,
|
2021-12-10 00:44:21 +01:00
|
|
|
R_DDIPL_OFFSET,
|
2021-09-25 20:00:36 +02:00
|
|
|
R_SAVE_OFFSET,
|
|
|
|
R_COMMAND,
|
|
|
|
R_DATA_0,
|
|
|
|
R_DATA_1,
|
2021-10-29 00:19:17 +02:00
|
|
|
R_VERSION,
|
|
|
|
R_RECONFIGURE
|
2021-09-25 20:00:36 +02:00
|
|
|
} e_reg_id;
|
|
|
|
|
2021-10-29 00:19:17 +02:00
|
|
|
const logic [31:0] RECONFIGURE_MAGIC = 32'h52535446;
|
|
|
|
|
2021-09-25 20:00:36 +02:00
|
|
|
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 = {
|
|
|
|
cfg.cpu_ready,
|
|
|
|
cfg.cpu_busy,
|
2021-10-26 23:44:09 +02:00
|
|
|
1'b0,
|
2021-09-25 20:00:36 +02:00
|
|
|
cfg.cmd_error,
|
|
|
|
21'd0,
|
|
|
|
skip_bootloader,
|
|
|
|
cfg.flashram_enabled,
|
|
|
|
cfg.sram_banked,
|
|
|
|
cfg.sram_enabled,
|
|
|
|
cfg.dd_enabled,
|
|
|
|
cfg.sdram_writable,
|
|
|
|
cfg.sdram_switch
|
|
|
|
};
|
2021-12-10 00:44:21 +01:00
|
|
|
R_DDIPL_OFFSET: bus.rdata = {6'd0, cfg.ddipl_offset};
|
2021-09-25 20:00:36 +02:00
|
|
|
R_SAVE_OFFSET: bus.rdata = {6'd0, cfg.save_offset};
|
|
|
|
R_COMMAND: bus.rdata = {24'd0, cfg.cmd};
|
|
|
|
R_DATA_0: bus.rdata = cfg.data[0];
|
|
|
|
R_DATA_1: bus.rdata = cfg.data[1];
|
|
|
|
R_VERSION: bus.rdata = sc64::SC64_VER;
|
2021-11-10 02:05:51 +01:00
|
|
|
R_RECONFIGURE: bus.rdata = RECONFIGURE_MAGIC;
|
2021-09-25 20:00:36 +02:00
|
|
|
default: bus.rdata = 32'd0;
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
always_ff @(posedge sys.clk) begin
|
|
|
|
if (sys.reset) begin
|
|
|
|
cfg.cpu_ready <= 1'b0;
|
|
|
|
cfg.cpu_busy <= 1'b0;
|
|
|
|
cfg.cmd_error <= 1'b0;
|
|
|
|
cfg.sdram_switch <= 1'b0;
|
|
|
|
cfg.sdram_writable <= 1'b0;
|
|
|
|
cfg.dd_enabled <= 1'b0;
|
|
|
|
cfg.sram_enabled <= 1'b0;
|
|
|
|
cfg.sram_banked <= 1'b0;
|
|
|
|
cfg.flashram_enabled <= 1'b0;
|
2021-12-10 00:44:21 +01:00
|
|
|
cfg.ddipl_offset <= 26'h3BE_0000;
|
2021-09-25 20:00:36 +02:00
|
|
|
cfg.save_offset <= 26'h3FE_0000;
|
|
|
|
skip_bootloader <= 1'b0;
|
2021-10-29 00:19:17 +02:00
|
|
|
trigger_reconfiguration <= 1'b0;
|
2021-09-25 20:00:36 +02:00
|
|
|
end else begin
|
|
|
|
if (sys.n64_soft_reset) begin
|
|
|
|
cfg.sdram_switch <= skip_bootloader;
|
|
|
|
cfg.sdram_writable <= 1'b0;
|
|
|
|
end
|
|
|
|
if (cfg.cmd_request) begin
|
|
|
|
cfg.cpu_busy <= 1'b1;
|
|
|
|
end
|
|
|
|
if (bus.request) begin
|
|
|
|
case (bus.address[4:2])
|
|
|
|
R_SCR: begin
|
|
|
|
if (bus.wmask[3]) begin
|
|
|
|
{
|
|
|
|
cfg.cpu_ready,
|
|
|
|
cfg.cpu_busy,
|
|
|
|
cfg.cmd_error
|
2021-10-26 23:44:09 +02:00
|
|
|
} <= {bus.wdata[31:30], bus.wdata[28]};
|
2021-09-25 20:00:36 +02:00
|
|
|
end
|
|
|
|
if (bus.wmask[0]) begin
|
|
|
|
{
|
|
|
|
skip_bootloader,
|
|
|
|
cfg.flashram_enabled,
|
|
|
|
cfg.sram_banked,
|
|
|
|
cfg.sram_enabled,
|
|
|
|
cfg.dd_enabled,
|
|
|
|
cfg.sdram_writable,
|
|
|
|
cfg.sdram_switch
|
|
|
|
} <= bus.wdata[6:0];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-10 00:44:21 +01:00
|
|
|
R_DDIPL_OFFSET: begin
|
2021-09-25 20:00:36 +02:00
|
|
|
if (&bus.wmask) begin
|
2021-12-10 00:44:21 +01:00
|
|
|
cfg.ddipl_offset <= bus.wdata[25:0];
|
2021-09-25 20:00:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
R_SAVE_OFFSET: begin
|
|
|
|
if (&bus.wmask) begin
|
|
|
|
cfg.save_offset <= bus.wdata[25:0];
|
|
|
|
end
|
|
|
|
end
|
2021-10-29 00:19:17 +02:00
|
|
|
|
|
|
|
R_RECONFIGURE: begin
|
|
|
|
if (&bus.wmask && bus.wdata == RECONFIGURE_MAGIC) begin
|
|
|
|
trigger_reconfiguration <= 1'b1;
|
|
|
|
end
|
|
|
|
end
|
2021-09-25 20:00:36 +02:00
|
|
|
endcase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
logic [1:0] ru_clk;
|
|
|
|
logic ru_rconfig;
|
|
|
|
logic ru_regout;
|
2021-10-29 00:19:17 +02:00
|
|
|
|
|
|
|
always_ff @(posedge sys.clk) begin
|
|
|
|
if (sys.reset) begin
|
2021-11-10 02:05:51 +01:00
|
|
|
ru_clk <= 2'd0;
|
|
|
|
ru_rconfig <= 1'b0;
|
2021-10-29 00:19:17 +02:00
|
|
|
end else begin
|
2021-11-10 02:05:51 +01:00
|
|
|
ru_clk <= ru_clk + 1'd1;
|
2021-10-29 00:19:17 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
if (ru_clk == 2'd1) begin
|
|
|
|
ru_rconfig <= trigger_reconfiguration;
|
2021-10-29 00:19:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
fiftyfivenm_rublock fiftyfivenm_rublock_inst (
|
|
|
|
.clk(ru_clk[1]),
|
|
|
|
.shiftnld(1'b0),
|
|
|
|
.captnupdt(1'b0),
|
|
|
|
.regin(1'b0),
|
|
|
|
.rsttimer(1'b0),
|
|
|
|
.rconfig(ru_rconfig),
|
|
|
|
.regout(ru_regout)
|
2021-10-29 00:19:17 +02:00
|
|
|
);
|
|
|
|
|
2021-09-25 20:00:36 +02:00
|
|
|
endmodule
|