I have created a module which accepts a single parameter specifying the byte width of the module's data lines. It looks something like:
module wrapper#
(
parameter DATA_BYTE_WIDTH = 1
)
(
din, dout, ..
);
localparam DATA_BIT_WIDTH = 8*DATA_BYTE_WIDTH;
input [DATA_BIT_WIDTH-1:0] din;
output [DATA_BIT_WIDTH-1:0] dout;
.....
generate
if( DATA_BYTE_WIDTH == 1 ) begin
// Various modules and interconnects for 1-byte data
else if( DATA_BYTE_WIDTH == 2) begin
// Various modules and interconnects for 2-byte data
else if....
// and so on, for 4, 8, and 16
else
// DATA_BYTE_WIDTH is not a valid value
// HERE is where I want to throw an error
end
endgenerate
// other code
endmodule
The problem is that the only valid widths are 1, 2, 4, 8 or 16 bytes. If any other value is used for DATA_BYTE_WIDTH, the interconnects will not be generated at all. But Xilinx doesn't seem to care about that. It will happily "generate" nothing if an invalid value is supplied: the resulting design synthesizes but simply does not work.
Is there a way to check the value of a parameter and throw an error if it is invalid? I've tried $error
and assert
(as discussed here), as well as $display
(as mentioned here). Xilinx refuses to use any of these functions, instead throwing syntax errors and refusing to continiue.
Ideally, I'd like something to throw in the final else
within the generate
, but I'll settle for pretty much anything at this point.