wrote:
> On Dec 10, 6:27 pm, Ken Cecka <cec...@alumni.washington.edu> wrote:
>> Hi All,
>>
>> I was trying to get something similar to the following to compile today
>> without success:
>>
>> ENTITY ent IS
>> GENERIC
>> (
>> bits : INTEGER := 4;
>> val : STD_LOGIC_VECTOR((bits - 1) DOWNTO 0) := (OTHERS => '0')
>> );
>> PORT
>> (
>> reset : IN STD_LOGIC;
>> clk : IN STD_LOGIC;
>> din : IN STD_LOGIC_VECTOR((bits - 1) DOWNTO 0);
>> dout : OUT STD_LOGIC_VECTOR((bits - 1) DOWNTO 0)
>> );
>> END ent;
>>
>> The compilers don't seem to like me using 'bits' in the type for val
>> (probably because bits is not considered defined while inside the GENERIC
>> block?).
>>
>
> That's exactly right. The language effectively says that says the
> names of the generics are visible until you get to the ports section.
>
>
>> I can remove the dimensions on val, but then I can't default it to all 0s
>> with (OTHERS => '0').
>>
>> Is there any way to achieve what I'm trying to do here? I want a
>> component with a generic bus width that also takes a generic constant
>> which is required to match that bus width and defaults to all 0s.
>>
>> I've considered passing the constant in as an integer and then using
>> CONV_STD_LOGIC_VECTOR internally, but as I understand it, integers have a
>> fixed width of 32 in the compiler, so the entity would not scale to
>> designs with (bits > 32).
>>
>> Thanks,
>> Ken
>
> It's ugly, but the code below compiles OK.
>
> - Kenn
>
> -----------------------------------------------
>
> library IEEE;
> use IEEE.std_logic_1164.all;
>
> entity foo is
>
> generic (
> n : integer;
> g1 : std_logic_vector
> );
Thanks for the suggestion. That's pretty much what I finally settled on. I don't really mind the unconstrained vector - at least I can cover that with an assert. The piece that's still irritating me is the lack of a default value for g1. If you have any inspirations on how to fit that in, I'm all ears.
Ken