Address decoding with casez
The bus decoder routes transactions to the correct peripheral:
module bus_decoder (
input logic [31:0] addr,
output logic sel_imem, sel_dmem,
sel_uart, sel_timer,
sel_gpio, sel_accel
);
always_comb begin
{sel_imem, sel_dmem, sel_uart,
sel_timer, sel_gpio, sel_accel} = 6'b0;
casez (addr[31:8])
24'h000000: sel_imem = 1;
24'h000100: sel_dmem = 1;
24'h000200: sel_uart = 1;
24'h000201: sel_timer = 1;
24'h000202: sel_gpio = 1;
24'h000203: sel_accel = 1;
default: ;
endcase
end
endmodule
Each sel_* signal enables one peripheral's ready and rdata to connect to the bus.