Skip to content

Commit

Permalink
axi_pkg: Add iomsb to avoid underflow in array lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilKoe committed Oct 29, 2024
1 parent 853ede2 commit d864a8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/axi_id_serialize.sv
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module axi_id_serialize #(
/// Number of Entries in the explicit ID map (default: None)
parameter int unsigned IdMapNumEntries = 32'd0,
/// Explicit ID map; index [0] in each entry is the input ID to match, index [1] the output ID.
parameter int unsigned IdMap [IdMapNumEntries-1:0][0:1] = '{default: {32'b0, 32'b0}}
parameter int unsigned IdMap [axi_pkg::iomsb(IdMapNumEntries):0][0:1] = '{default: {32'b0, 32'b0}}
) (
/// Rising-edge clock of both ports
input logic clk_i,
Expand Down
5 changes: 5 additions & 0 deletions src/axi_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -532,4 +532,9 @@ package axi_pkg;
logic [31:0] end_addr;
} xbar_rule_32_t;

// Return either the argument minus 1 or 0 if 0; useful for IO vector width declaration
function automatic integer unsigned iomsb (input integer unsigned width);
return (width != 32'd0) ? unsigned'(width-1) : 32'd0;
endfunction

endpackage

0 comments on commit d864a8a

Please sign in to comment.