SummerCart64/fw/rtl/n64/n64_cfg.sv

70 lines
2.1 KiB
Systemverilog
Raw Normal View History

module n64_cfg (
2022-05-15 15:47:12 +02:00
input clk,
input reset,
2022-05-15 15:47:12 +02:00
n64_reg_bus.cfg reg_bus,
2022-05-15 15:47:12 +02:00
n64_scb.cfg n64_scb,
2022-05-15 15:47:12 +02:00
output logic irq
);
typedef enum bit [2:0] {
REG_STATUS,
REG_COMMAND,
REG_DATA_0_H,
REG_DATA_0_L,
REG_DATA_1_H,
REG_DATA_1_L,
REG_VERSION_H,
REG_VERSION_L
} e_reg;
always_comb begin
2022-05-15 15:47:12 +02:00
reg_bus.rdata = 16'd0;
case (reg_bus.address[3:1])
REG_STATUS: reg_bus.rdata = {
n64_scb.cfg_pending,
n64_scb.cfg_error,
14'd0
};
REG_DATA_0_H: reg_bus.rdata = n64_scb.cfg_wdata[0][31:16];
REG_DATA_0_L: reg_bus.rdata = n64_scb.cfg_wdata[0][15:0];
REG_DATA_1_H: reg_bus.rdata = n64_scb.cfg_wdata[1][31:16];
REG_DATA_1_L: reg_bus.rdata = n64_scb.cfg_wdata[1][15:0];
REG_VERSION_H: reg_bus.rdata = n64_scb.cfg_version[31:16];
REG_VERSION_L: reg_bus.rdata = n64_scb.cfg_version[15:0];
endcase
end
2022-05-15 15:47:12 +02:00
always_ff @(posedge clk) begin
if (reset) begin
n64_scb.cfg_pending <= 1'b0;
irq <= 1'b0;
end else begin
if (n64_scb.cfg_done) begin
n64_scb.cfg_pending <= 1'b0;
end
2022-05-15 15:47:12 +02:00
if (n64_scb.cfg_irq) begin
irq <= 1'b1;
end
2022-05-15 15:47:12 +02:00
if (reg_bus.write) begin
case (reg_bus.address[3:1])
REG_COMMAND: begin
n64_scb.cfg_pending <= 1'b1;
n64_scb.cfg_cmd <= reg_bus.wdata[7:0];
end
2022-05-15 15:47:12 +02:00
REG_DATA_0_H: n64_scb.cfg_rdata[0][31:16] <= reg_bus.wdata;
REG_DATA_0_L: n64_scb.cfg_rdata[0][15:0] <= reg_bus.wdata;
REG_DATA_1_H: n64_scb.cfg_rdata[1][31:16] <= reg_bus.wdata;
REG_DATA_1_L: n64_scb.cfg_rdata[1][15:0] <= reg_bus.wdata;
REG_VERSION_L: irq <= 1'b0;
endcase
end
end
end
endmodule