Add irq status register

Upon receiving an interrupt, the corresponding bit in the interrupt
status register will be set and an IRQ will be raised for the CPU. The
cpu can then respond to the interrupt and clear the interrupt by writing
back to the interrupt status register.
This commit is contained in:
Byron Lathi
2022-03-14 13:16:09 -05:00
parent 26070313f4
commit e70fffb472
5 changed files with 126 additions and 4 deletions

View File

@@ -42,11 +42,13 @@ assign cpu_data = cpu_rwb ? cpu_data_out : 'z;
logic [7:0] rom_data_out;
logic [7:0] ram_data_out;
logic [7:0] uart_data_out;
logic [7:0] irq_data_out;
logic ram_cs;
logic rom_cs;
logic hex_cs;
logic uart_cs;
logic irq_cs;
cpu_clk cpu_clk(
.inclk0(clk_50),
@@ -62,14 +64,15 @@ assign cpu_sob = '0;
assign cpu_resb = rst_n;
assign cpu_be = '1;
assign cpu_nmib = '1;
assign cpu_irqb = button_1;
assign cpu_irqb = irq_data_out == 0;
addr_decode decode(
.addr(cpu_addr),
.ram_cs(ram_cs),
.rom_cs(rom_cs),
.hex_cs(hex_cs),
.uart_cs(uart_cs)
.uart_cs(uart_cs),
.irq_cs(irq_cs)
);
@@ -80,6 +83,8 @@ always_comb begin
cpu_data_out = rom_data_out;
else if (uart_cs)
cpu_data_out = uart_data_out;
else if (irq_cs)
cpu_data_out = irq_data_out;
else
cpu_data_out = 'x;
end
@@ -124,6 +129,16 @@ uart uart(
.TXD(UART_TXD),
.data_out(uart_data_out)
);
always_ff @(posedge clk_50) begin
if (rst)
irq_data_out <= '0;
else if (irq_cs && ~cpu_rwb)
irq_data_out <= irq_data_out & cpu_data_in;
else if (~button_1)
irq_data_out <= {irq_data_out[7:1], ~button_1};
end
endmodule