I want to create an unsigned in a function whose length is determined by the function parameters. I thought that was a legit thing to do- pretty sure I've even done it before, but maybe not- but ISE 14.7 doesn't think so (I know, I know. I have to use ISE because we're resurrecting an old system).
The purpose of the function is divide by a power of 2 and round the result. ISE doesn't like that I'm subtracting num_bits from the length of the input when declaring truncated. Is there a better way to do this?
function my_round(data_in : in unsigned; num_bits : in integer) return unsigned is
variable truncated : unsigned(data_in'left - num_bits downto 0);
begin
truncated := data_in(data_in'left downto num_bits);
if my_and_reduce(truncated) = '0' and data_in(num_bits-1) = '1' then
truncated := truncated + 1;
end if;
return truncated;
end my_round;
The error message that ISE gives me when trying to synthesize the code is "Constant value expected for expression (31 - num_bits)"
function my_round(truncated : in unsigned; highest_cut_off_bit : in std_logic) .... The parameter highest_cut_off_bit must then be filled with data_in(num_bits-1) when you call the function. The checkdata_in(num_bits-1) = '1'would then behighest_cut_off_bit='1'.