How to define a constant of an array of records?

Discussion in 'VHDL' started by mamu, Nov 13, 2008.

  1. mamu

    mamu Guest

    I want to make a lookup table where each entry in the table is record
    type. I can define the types but I can't figure out a way to set the
    (init) values in the declaration of a constant of that type I just
    defined.

    package altera_profile_pkg is

    type profile_record_type is record
    C_NUMBER_OF_SAMPLES : natural range 1 to 15000;
    end record profile_record_type;

    type lookup_table_type is array (natural range <>) of
    profile_record_type;

    constant profiles_table : lookup_table_type(0 to 15) := <what goes
    here?>

    end package altera_profile_pkg;
    mamu, Nov 13, 2008
    #1
    1. Advertising

  2. mamu

    Tricky Guest

    On 13 Nov, 08:09, mamu <> wrote:
    > I want to make a lookup table where each entry in the table is record
    > type. I can define the types but I can't figure out a way to set the
    > (init) values in the declaration of a constant of that type I just
    > defined.
    >
    > package altera_profile_pkg is
    >
    > type profile_record_type is record
    >     C_NUMBER_OF_SAMPLES    : natural range 1 to 15000;
    > end record profile_record_type;
    >
    > type lookup_table_type is array (natural range <>) of
    > profile_record_type;
    >
    > constant profiles_table : lookup_table_type(0 to 15) := <what goes
    > here?>
    >
    > end package altera_profile_pkg;



    if you had more than 1 element in the record,
    eg:

    type profile_record_type is record
    C_NUMBER_OF_SAMPLES : natural range 1 to 15000;
    A : integer;
    end record profile_record_type;

    you can use positional association:

    constant profiles_table : lookup_table_type(0 to 15) :=
    ( (1, 1), --element 0
    (2, 2), --element 1
    (3, 3), --element 2
    etc.....
    );

    but as you've only got 1 element, you have to use named association
    (which is a good idea for readability anyway:

    constant profiles_table : lookup_table_type(0 to 15) :=
    ( (C_NUMBER_OF_SAMPLES => 1), --element 0,
    (C_NUMBER_OF_SAMPLES => 2), --element 1,
    (C_NUMBER_OF_SAMPLES => 3), --element 2,
    etc....
    );

    Inner barckets are important to specify that it is a contained
    element.
    Tricky, Nov 13, 2008
    #2
    1. Advertising

  3. mamu

    Tricky Guest

    Forgot to add: you can also call a function that returns
    "lookup_table_type"

    function create_lookup_table return lookup_table_type is
    variable return_array : lookup_table_type(0 to 15);
    begin
    for i in return_array'range loop
    return_array(i) := (C_NUMBER_OF_SAMPLES => i);
    end loop;

    return return_array;
    end function;

    constant profiles_table : lookup_table_type(0 to 15) :=
    create_lookup_table;
    Tricky, Nov 13, 2008
    #3
  4. mamu

    mamu Guest

    Thanks! It is working fine now. I haven't tested the function option
    yet, but it shouldn't be a problem.
    mamu, Nov 13, 2008
    #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. Luke Airig
    Replies:
    0
    Views:
    776
    Luke Airig
    Dec 31, 2003
  2. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,074
  3. Replies:
    13
    Views:
    12,903
    Kai-Uwe Bux
    Jan 22, 2007
  4. Valli
    Replies:
    0
    Views:
    957
    Valli
    Apr 30, 2009
  5. Fredxx
    Replies:
    3
    Views:
    637
    Martin Thompson
    Jul 15, 2009
Loading...

Share This Page