Generic depending on generics?

Discussion in 'VHDL' started by jjohnson@cs.ucf.edu, Jan 20, 2005.

  1. Guest

    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;
     
    , Jan 20, 2005
    #1
    1. Advertising

  2. vsim -g does not overwrite explicit values.
    vsim -G does.

    -- Mike Treseler
     
    Mike Treseler, Jan 20, 2005
    #2
    1. Advertising

  3. Guest

    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
     
    , Jan 21, 2005
    #3
  4. wrote:

    > 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
     
    Mike Treseler, Jan 22, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov
    Replies:
    1
    Views:
    589
    Jonathan Bromley
    Feb 18, 2004
  2. Juergen Berchtel
    Replies:
    1
    Views:
    6,098
    John C. Bollinger
    May 20, 2005
  3. Replies:
    4
    Views:
    539
  4. Barry
    Replies:
    6
    Views:
    2,518
    Mark McDougall
    Jan 16, 2009
  5. Soul
    Replies:
    0
    Views:
    551
Loading...

Share This Page