As far as I know, you would have to do something like this:
package dynrec_pkg is
generic (
datatype : type
);
type dynrec_type is record
data : datatype;
someval : natural;
end record dynrec_type;
end package dynrec_pkg;
---------------------
library ieee;
use ieee.math_real.all;
package dynrec_pkg_real is new work.dynrec_pkg generic map (datatype => real);
---------------------
library ieee;
use ieee.std_logic_1164.all;
package dynrec_pkg_sl is new work.dynrec_pkg generic map (datatype => std_logic);
---------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.math_real.all;
use work.dynrec_pkg_real.all;
use work.dynrec_pkg_sl.all;
entity dynrec is
end entity dynrec;
architecture dyn of dynrec is
signal testsig1 : dynrec_pkg_real.dynrec_type;
signal testsig2 : dynrec_pkg_sl.dynrec_type;
begin -- architecture dyn
testsig1 <= (data => 5.0, someval => 12);
testsig2 <= (data => '1', someval => 12);
end architecture dyn;
Since you want to create instances of records with two different types, this would seem to be the best way. Otherwise, you could make datatype
a generic for the entity itself and avoid the extra package, but then you'd only have one dynamic type visible to the entity (of course, you could have multiple generics like datatype1
, datatype2
, etc).
The bottom line is that you can't define a record the way you did with an inline generic type - design elements like packages and entities can have generics, but records cannot.
Note that ModelSim does not seem to support this feature yet anyway (I'm using 10.2c), and I don't have a simulator handy that does, so syntax corrections would be welcome. I think the general idea is sound, though.