I was wondering is there was a way to defined a type with a size parameter in VHDL. e.g.
type count_vector(size: Natural) is unsigned (size-1 downto 0);
and then later on do something like
variable int : count_vector(32) := (others => '0');
variable nibble : count_vector(4) := (others => '0');
Essentially, is there a way to defined an "array-like" type, or is that not allowed by syntax?
I am currently trying to use generics for re-usability, but I would like to be able to take maximal advantage of generic typing (ie: Is it possible to write type-generic entities in VHDL? ).
Thanks in advance!
Added:
This is in response to BennyBarns assertion in a comment on the question: "I would like to add that while you can use n-dimensional arrays in VHDL, only the first one may be unconstrained".
Contrary to the assertion:
The statement is imprecise and relates in the example subtype declaration to the deferred range constraint in the type declaration of UNSIGNED in package numeric_std. The subtype indication requires a constraint either supplied by the type mark or explicitly. It's only valid for a subtype indication type mark that is an unconstrained type.
A subtype declaration of an unconstrained type must provide a constraint just as if you had added
as an architecture declarative item to fum of entity foo:
And just to make things interesting things interface lists can be special:
The 'rules' can be found in the LRM section on Index constraints and discrete ranges, IEEE Std 1076-2008 5.3.2.2, -2002/-1993 3.2.1.1.