Generic depending on generics?

J

jjohnson

I need to have generics in lower-level designs that are *conditionally*
assigned based on generics in the top level. Can I do this without a
configuration? If not, how is it done with configurations? The more I
work on it, the more confused I get...

Overview:
Top declares generics A,B,C,D, which are
passed down to instantiated components.

A is given a default value, which can be overridden.

B,C,D need to get whatever A turns out to be as their
default value, but get values from command line if specified.

ModelSim complains (error vcom-1137) that A is not visible when it
tries to set B,C,D := A.

Details follow below

Thanks in advance...
jmj


Details: I have an A/D converter behavioral model that reads samples
from a file:

entity adc_model is
generic(
inp_file := "adc_in.dat"; -- default name to test adc by itself
) -- Name can be overridden on command
line
port(
....
)
end entity adc_model;


Top-level testbench instantiates 3 adc_models: adc1, adc2, adc3.

In one case, I want all 3 models to read input from the same file.
In one case, I want all 3 models to read input from different files.
In last case, I want some to read default file, others to read unique
files, all controlled via the ModelSim command line.

Logic I'm trying to implement is:

entity top_level_tb is
generic(
common_input_file := common.dat;
adc1_infile := common_input_file; -- lower names based on first
generic
adc2_infile := common_input_file;
adc3_infile := common_input_file;
)
end entity top-level_tb;

architecture
begin

-- For each instance, if an individual filename was given on vsim
-- command line, use it; otherwise, use common file; e.g.,
-- vsim -g common_input_file=FOO.DAT -g adc3_infile=BAR.DAT
-- (adc1 and adc2 read from FOO, adc3 reads from BAR)

adc1: adc_model
generic map (
inp_file => adc1_infile
)

adc2: adc_model
generic map (
inp_file => adc2_infile
)

adc3: adc_model
generic map (
inp_file => adc3_infile
)

end architecture;
 
J

jjohnson

Mike, thanks very much for pointing that out! Apparently "-g" will
override defaults specified in declarations, but "-G" is required to
override explicit values given in generic maps and instantiations. That
solves a couple problems I was having.

[To be proper, I was also showing a space between "-g" and the
"Name=Value" for clarity, but ModelSim does not allow that space on the
vsim command line.]

ModelSim's vsim command line can assign generics at all levels of
hierarchy (so I just discovered), on a single-instance basis, on
certain instances, or on all instances of the generic, controlled by
the amount of hierarchical path info you prepend to the generic name.
e.g. from the docs, for the benefit of our readers:

-g/top/u1/tpd=20ns affects ONLY the generic tpd in instance u1
-g/u1/tpd=20ns affects tpd on SOME instances (on all named u1)
-gtpd=20ns affects ALL generics named tpd

-g/top/u1/tpd=20ns -gtpd=15ns
sets the one instance (in u1) to 20ns, and all others to 15ns

This implies I'm better off not mapping unique file names to each ADC;
just keep one and override each instance on the command line. It also
means I don't have to pass generics from the top down thru every level
of hierarchy to where they're finally used.

However, the above is simulator-dependent, so I still wonder how to
make one generic depend on another as in my example, especially without
resorting to "artificial" or unnecessary packages or configurations.
Thanks again,

mj
 
M

Mike Treseler

However, the above is simulator-dependent, so I still wonder how to
make one generic depend on another as in my example, especially without
resorting to "artificial" or unnecessary packages or configurations.

A generic is just a constant to your code.
The value may come from the code or be forced
in from the command line, but once it is bound,
the value is fixed for the simulation run.

Maybe some of the constants ought to be variables,
or maybe you need to use tcl to script multiple vsim runs
to cover the generic permutations, or maybe you
need multiple UUT instances in your testbench.

-- Mike Treseler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top