Not really. I wrote pack/unpack functions that I get a lot of use of
when I have to cast a record type into an SLV, usually because I have
to work with some generated core. Then I wind up writing functions for
each direction as:
function TO_SLV(rec : t_pvme_request) return
t_pvme_request_slv is variable slv : t_pvme_request_slv;
variable idx : integer;
begin
slv := (others => 'U');
idx := 0;
pack(slv, idx, rec.data);
pack(slv, idx, rec.address);
pack(slv, idx, rec.timing);
pack(slv, idx,
rec.am);
pack(slv, idx,
rec.dm);
pack(slv, idx, rec.req);
return slv;
end function TO_SLV;
function TO_REQUEST (slv : t_pvme_request_slv) return
t_pvme_request is variable rec : t_pvme_request;
variable idx : integer;
begin
idx := 0;
unpack(slv, idx, rec.data);
unpack(slv, idx, rec.address);
unpack(slv, idx, rec.timing);
unpack(slv, idx,
rec.am);
unpack(slv, idx,
rec.dm);
unpack(slv, idx, rec.req);
return rec;
end function TO_REQUEST;
I'll put all my overloads on the pack/unpack functions here in case
anyone ever wants them.
-----------------------------------------------------------------------
-- Record conversion functions
-----------------------------------------------------------------------
procedure pack(
target : inout std_logic_vector;
idx : inout integer;
nd : in std_logic_vector
) is
begin
target(idx + nd'length - 1 downto idx) := nd;
idx := idx + nd'length;
end procedure pack;
procedure pack(
target : inout std_logic_vector;
idx : inout integer;
nd : in std_logic
) is
begin
target(idx) := nd;
idx := idx + 1;
end procedure pack;
procedure pack(
target : inout std_logic_vector;
idx : inout integer;
nd : in unsigned
) is
begin
target(idx + nd'length - 1 downto idx) :=
STD_LOGIC_VECTOR(nd); idx := idx + nd'length;
end procedure pack;
procedure pack(
target : inout std_logic_vector;
idx : inout integer;
nd : in signed
) is
begin
target(idx + nd'length - 1 downto idx) :=
STD_LOGIC_VECTOR(nd); idx := idx + nd'length;
end procedure pack;
----------------------------------------------------------------------
procedure unpack (
source : in std_logic_vector;
idx : inout integer;
dat : out std_logic_vector
) is
begin
dat := source(idx + dat'length - 1 downto idx);
idx := idx + dat'length;
end procedure unpack;
procedure unpack (
source : in std_logic_vector;
idx : inout integer;
dat : out std_logic
) is
begin
dat := source(idx);
idx := idx + 1;
end procedure unpack;
procedure unpack (
source : in std_logic_vector;
idx : inout integer;
dat : out unsigned
) is
begin
dat := UNSIGNED(source(idx + dat'length - 1 downto
idx)); idx := idx + dat'length;
end procedure unpack;
procedure unpack (
source : in std_logic_vector;
idx : inout integer;
dat : out signed
) is
begin
dat := SIGNED(source(idx + dat'length - 1 downto idx));
idx := idx + dat'length;
end procedure unpack;
--
Rob Gaddi, Highland Technology --
www.highlandtechnology.com
Email address domain is currently out of order. See above to fix.