2021-09-25 20:00:36 +02:00
|
|
|
module n64_cfg (
|
2022-05-15 15:47:12 +02:00
|
|
|
input clk,
|
|
|
|
input reset,
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2022-05-15 15:47:12 +02:00
|
|
|
n64_reg_bus.cfg reg_bus,
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2022-05-15 15:47:12 +02:00
|
|
|
n64_scb.cfg n64_scb,
|
2021-09-25 20:00:36 +02:00
|
|
|
|
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;
|
2021-09-25 20:00:36 +02:00
|
|
|
|
|
|
|
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
|
2021-09-25 20:00:36 +02:00
|
|
|
end
|
|
|
|
|
2022-05-15 15:47:12 +02:00
|
|
|
always_ff @(posedge clk) begin
|
|
|
|
if (reset) begin
|
|
|
|
n64_scb.cfg_pending <= 1'b0;
|
2022-07-30 19:39:49 +02:00
|
|
|
n64_scb.cfg_cmd <= 8'h00;
|
2022-05-15 15:47:12 +02:00
|
|
|
irq <= 1'b0;
|
|
|
|
end else begin
|
|
|
|
if (n64_scb.cfg_done) begin
|
|
|
|
n64_scb.cfg_pending <= 1'b0;
|
|
|
|
end
|
2021-09-25 20:00:36 +02:00
|
|
|
|
2022-05-15 15:47:12 +02:00
|
|
|
if (n64_scb.cfg_irq) begin
|
|
|
|
irq <= 1'b1;
|
|
|
|
end
|
2021-09-25 20:00:36 +02:00
|
|
|
|
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];
|
2021-09-25 20:00:36 +02:00
|
|
|
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
|
2021-09-25 20:00:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|