Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - How to define a constant of an array of records?

 
Thread Tools Search this Thread
Old 11-13-2008, 08:09 AM   #1
Default How to define a constant of an array of records?


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
  Reply With Quote
Old 11-13-2008, 09:34 AM   #2
Tricky
 
Posts: n/a
Default Re: How to define a constant of an array of records?
On 13 Nov, 08:09, mamu <magnem...@yahoo.no> 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
  Reply With Quote
Old 11-13-2008, 09:40 AM   #3
Tricky
 
Posts: n/a
Default Re: How to define a constant of an array of records?
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
  Reply With Quote
Old 11-13-2008, 10:18 AM   #4
mamu
 
Posts: n/a
Default Re: How to define a constant of an array of records?
Thanks! It is working fine now. I haven't tested the function option
yet, but it shouldn't be a problem.


mamu
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL and EDK: Custom IP core containing an array as a port using EDK allsey_1987 Hardware 0 10-27-2009 02:26 PM
constants as of array of integers, for loops octavsly Hardware 0 04-25-2009 11:53 AM
Array Programme rits Software 2 03-04-2009 05:18 PM
DVD Verdict reviews: THE CONSTANT GARDENER, TRANSPORTER 2, and more! DVD Verdict DVD Video 0 01-10-2006 09:21 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46