A
alb
Hi everyone,
I have declared a set of constants in the following way:
<code>
constant AB : unsigned(data_t'range) := x"01";
constant CD : unsigned(data_t'range) := x"02";
constant EF : unsigned(data_t'range) := x"04";
constant GH : unsigned(data_t'range) := x"08";
constant IJ : unsigned(data_t'range) := x"10";
constant KL : unsigned(data_t'range) := x"20";
constant MN : unsigned(data_t'range) := x"40";
constant OP : unsigned(data_t'range) := x"80";
</code>
where data_t is a constrained std_logic_vector(7 downto 0) type.
If we declare a signal/variable foo of data_t type and we want to test
if bit 'IJ' is set or not, what I'm currently doing is the following:
<code>
if foo(to_integer(IJ) - 1) then
-- do stuff
end if;
</code>
which I find rather ugly... And if the constant is an slv than I would
need to do something like
<code>
if foo(to_integer(unsigned(IJ) - 1)) then
-- do stuff
end if;
</code>
which is even uglier!
Is there a more readable way to do that?
True I can write my function to handle the conversions and return a
natural, but I didn't want to reinvent the wheel
On top of this, the limitation of this approach is that if data_t change
bus width the constants definitions will not work anymore. Any idea?
Thanks a lot,
Al
I have declared a set of constants in the following way:
<code>
constant AB : unsigned(data_t'range) := x"01";
constant CD : unsigned(data_t'range) := x"02";
constant EF : unsigned(data_t'range) := x"04";
constant GH : unsigned(data_t'range) := x"08";
constant IJ : unsigned(data_t'range) := x"10";
constant KL : unsigned(data_t'range) := x"20";
constant MN : unsigned(data_t'range) := x"40";
constant OP : unsigned(data_t'range) := x"80";
</code>
where data_t is a constrained std_logic_vector(7 downto 0) type.
If we declare a signal/variable foo of data_t type and we want to test
if bit 'IJ' is set or not, what I'm currently doing is the following:
<code>
if foo(to_integer(IJ) - 1) then
-- do stuff
end if;
</code>
which I find rather ugly... And if the constant is an slv than I would
need to do something like
<code>
if foo(to_integer(unsigned(IJ) - 1)) then
-- do stuff
end if;
</code>
which is even uglier!
Is there a more readable way to do that?
True I can write my function to handle the conversions and return a
natural, but I didn't want to reinvent the wheel
On top of this, the limitation of this approach is that if data_t change
bus width the constants definitions will not work anymore. Any idea?
Thanks a lot,
Al