Guest
Hello,
I have a module that I'm trying to implement generically. The problem
stems from the fact that the signal used in the case statement has a
variable width - it gets set by two generic parameters. The
difficulty is that when the width changes, the number of possible
cases changes and all cases must be covered in order for the code to
compile. The code is posted below and essentially boils down to a
priority mux with a variable number of inputs. Is there anyway to
generate the appropriate number of cases based on the width of the
selector?
"bits" and "highbit" are std_logic_vectors
process(clk) is
variable hbit_tmp : natural;
variable bits_tmp : natural;
begin
if(rising_edge(clk)) then
bits_tmp := to_integer(unsigned(bits));
case bits_tmp is
when 1 => hbit_tmp := numOutBits;
when 2#10# to 2#11# => hbit_tmp := numOutBits + 1;
when 2#100# to 2#111# => hbit_tmp := numOutBits + 2;
when 2#1000# to 2#1111# => hbit_tmp := numOutbits + 3;
when 2#10000# to 2#11111# => hbit_tmp := numOutBits +
4;
when 2#100000# to 2#111111# => hbit_tmp := numOutBits +
5;
when others => hbit_tmp := numOutBits - 1;
end case;
highbit <= std_logic_vector(to_unsigned(hbit_tmp,
highbit'length));
end if;
end process;
I have a module that I'm trying to implement generically. The problem
stems from the fact that the signal used in the case statement has a
variable width - it gets set by two generic parameters. The
difficulty is that when the width changes, the number of possible
cases changes and all cases must be covered in order for the code to
compile. The code is posted below and essentially boils down to a
priority mux with a variable number of inputs. Is there anyway to
generate the appropriate number of cases based on the width of the
selector?
"bits" and "highbit" are std_logic_vectors
process(clk) is
variable hbit_tmp : natural;
variable bits_tmp : natural;
begin
if(rising_edge(clk)) then
bits_tmp := to_integer(unsigned(bits));
case bits_tmp is
when 1 => hbit_tmp := numOutBits;
when 2#10# to 2#11# => hbit_tmp := numOutBits + 1;
when 2#100# to 2#111# => hbit_tmp := numOutBits + 2;
when 2#1000# to 2#1111# => hbit_tmp := numOutbits + 3;
when 2#10000# to 2#11111# => hbit_tmp := numOutBits +
4;
when 2#100000# to 2#111111# => hbit_tmp := numOutBits +
5;
when others => hbit_tmp := numOutBits - 1;
end case;
highbit <= std_logic_vector(to_unsigned(hbit_tmp,
highbit'length));
end if;
end process;