generating within a case statement

C

colin

Guest
Hi

I have written some code that I hate and would like some help

I have an array of registers which I have generated of static size
(comes into the entity via a generic. I now need to read the registers
as follows:-

READ_REGS: process (reset,clk)
begin
if (reset='1') then
reg <= (others => '0');
elsif (clk'event and clk='1') then

if ( read_oe = '1' ) then

case (addr(4 downto 2)) is
when ("000") =>
read_data <= register(0);
when ("001") =>
read_data <= register(1);
when ("010") =>
read_data <= register(2);
when ("011") =>
read_data <= register(3);

when others => read_data <= (others => 'X'); end case;

end if;

Obviously I want the case statement to be able to read an unknown
number of registers. Converting addr(4 downto 0) to an integer is easy
but then I'm stuck as to how to put a generate into a case statement.

Any help appreciated

Colin
 
"colin" <colin_toogood@yahoo.com> wrote in message
news:885a4a4a.0503020537.223a924@posting.google.com...
Hi

I have written some code that I hate and would like some help

I have an array of registers which I have generated of static size
(comes into the entity via a generic. I now need to read the registers
as follows:-

READ_REGS: process (reset,clk)
begin
if (reset='1') then
reg <= (others => '0');
elsif (clk'event and clk='1') then

if ( read_oe = '1' ) then

case (addr(4 downto 2)) is
when ("000") =
read_data <= register(0);
when ("001") =
read_data <= register(1);
when ("010") =
read_data <= register(2);
when ("011") =
read_data <= register(3);

when others => read_data <= (others => 'X'); end case;

end if;

Obviously I want the case statement to be able to read an unknown
number of registers. Converting addr(4 downto 0) to an integer is easy
but then I'm stuck as to how to put a generate into a case statement.

Any help appreciated

Colin
I have the feeling the case statement is not needed at all.
Probably the following replaces the case:
read_data <= register(to_integer(unsigned(addr(4 downto 2))));

Egbert Molenkamp
 

Welcome to EDABoard.com

Sponsor

Back
Top