Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bus] Return error if decode fails #2142

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions shared/rtl/bus.sv
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,33 @@ module bus #(
localparam int unsigned NumBitsHostSel = NrHosts > 1 ? $clog2(NrHosts) : 1;
localparam int unsigned NumBitsDeviceSel = NrDevices > 1 ? $clog2(NrDevices) : 1;

logic host_sel_valid;
logic device_sel_valid;
logic decode_err_resp;

logic [NumBitsHostSel-1:0] host_sel_req, host_sel_resp;
logic [NumBitsDeviceSel-1:0] device_sel_req, device_sel_resp;

// Master select prio arbiter
always_comb begin
host_sel_valid = 1'b0;
host_sel_req = '0;
for (integer host = NrHosts - 1; host >= 0; host = host - 1) begin
if (host_req_i[host]) begin
host_sel_valid = 1'b1;
host_sel_req = NumBitsHostSel'(host);
end
end
end

// Device select
always_comb begin
device_sel_valid = 1'b0;
device_sel_req = '0;
for (integer device = 0; device < NrDevices; device = device + 1) begin
if ((host_addr_i[host_sel_req] & cfg_device_addr_mask[device])
== cfg_device_addr_base[device]) begin
device_sel_valid = 1'b1;
device_sel_req = NumBitsDeviceSel'(device);
end
end
Expand All @@ -82,16 +90,19 @@ module bus #(
if (!rst_ni) begin
host_sel_resp <= '0;
device_sel_resp <= '0;
decode_err_resp <= 1'b0;
end else begin
// Responses are always expected 1 cycle after the request
device_sel_resp <= device_sel_req;
host_sel_resp <= host_sel_req;
// Decode failed; no device matched?
decode_err_resp <= host_sel_valid & !device_sel_valid;
end
end

always_comb begin
for (integer device = 0; device < NrDevices; device = device + 1) begin
if (NumBitsDeviceSel'(device) == device_sel_req) begin
if (device_sel_valid && NumBitsDeviceSel'(device) == device_sel_req) begin
device_req_o[device] = host_req_i[host_sel_req];
device_we_o[device] = host_we_i[host_sel_req];
device_addr_o[device] = host_addr_i[host_sel_req];
Expand All @@ -111,8 +122,8 @@ module bus #(
for (integer host = 0; host < NrHosts; host = host + 1) begin
host_gnt_o[host] = 1'b0;
if (NumBitsHostSel'(host) == host_sel_resp) begin
host_rvalid_o[host] = device_rvalid_i[device_sel_resp];
host_err_o[host] = device_err_i[device_sel_resp];
host_rvalid_o[host] = device_rvalid_i[device_sel_resp] | decode_err_resp;
host_err_o[host] = device_err_i[device_sel_resp] | decode_err_resp;
host_rdata_o[host] = device_rdata_i[device_sel_resp];
end else begin
host_rvalid_o[host] = 1'b0;
Expand Down
Loading