Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repetitive code (Newbie)

Status
Not open for further replies.

smuaie

Technical User
Jun 13, 2003
8
FR
I try to find a elegant way to code a component in order to employ it with different value of a constant.

The code is :

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity c_nibble is
Port ( input : in std_logic_vector(3 downto 0);
output : out std_logic_vector(3 downto 0));
end c_nibble;

architecture c_nibble_a of c_nibble is
component rom16x1
port( a3, a2, a1, a0 : in std_logic;
o : out std_logic);
end component;
attribute init : string;
attribute init of rom3 : label is "926C";
attribute init of rom2 : label is "4B5A";
attribute init of rom1 : label is "99CC";
attribute init of rom0 : label is "552A";
begin
rom3: rom16x1 port map ( a3 => input(3), a2 => input(2), a1 => input(1), a0 => input(0), o => output(3));
rom2: rom16x1 port map ( a3 => input(3), a2 => input(2), a1 => input(1), a0 => input(0), o => output(2));
rom1: rom16x1 port map ( a3 => input(3), a2 => input(2), a1 => input(1), a0 => input(0), o => output(1));
rom0: rom16x1 port map ( a3 => input(3), a2 => input(2), a1 => input(1), a0 => input(0), o => output(0));
end c_nibble_a;

If I want another instance of xc_nibblex with an output on 16 bits, my way of coding obliges me to create a new component. Does there exist a method to be able to change the number of bit of output as well as the constants at the time of instanciation?

Thank in advance

smu
 
You can instantiate your component using a 'generate' statement:

rom_generate: for i in 0 to 3 generate
dummy: rom16x1
port map ( a3 => input(3),
a2 => input(2),
a1 => input(1),
a0 => input(0),
o => output(i)
);
end rom_generate;

The instantiations will be called:
rom_generate__0\dummy
rom_generate__1\dummy
rom_generate__2\dummy
rom_generate__3\dummy


You can also play number games with the i. For instance:
(i-1) or ((i*2)-2), etc -- as long as it doesn't violate the for statement.

As for the init... This is MUCH harder. Sadly, there is no SIMPLE way of doing it. We were forced to find a way, since we have an array of a hundred or so primatives. It's too complicated to even go into. Suffice it to say, it requires using generics and the integer'image function. It's just nasty...

Because you have only four blocks, your way works fine -- it is the easiest way of using both an array and INITs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top