将数据从矢量(线性数组)转换为记录的一种方法是通过使用聚合。
library ieee;
use ieee.std_logic_1164.all;
package TestPck is
subtype A is std_logic_vector (12 downto 9);
subtype B is std_logic_vector (8 downto 1);
subtype C is std_logic_vector (0 downto 0);
constant ABC_len: natural := A'length + B'length + C'length;
type tTest is record
A: std_logic_vector (A'RANGE);
B: std_logic_vector (B'RANGE);
C: std_logic_vector (C'RANGE);
end record tTest;
type tTests is array (natural range <>) of tTest;
end package TestPck;
library ieee;
use ieee.std_logic_1164.all;
use work.TestPck.all;
entity tb is
end entity tb;
architecture sim of tb is
signal sTestIn: tTest;
signal sMemWrData: std_logic_vector(ABC_len - 1 downto 0);
signal sMemRdData: std_logic_vector(ABC_len - 1 downto 0);
signal sTestOut: tTest;
constant tests: tTests (0 to 1) :=
(0 => (x"E", x"A7", "1"), 1 => (x"7", x"AC", "0"));
begin
sMemWrData <= sTestIn.A & sTestIn.B & sTestIn.C;
sMemRdData <= sMemWrData after 5 ns;
sTestOut <=
tTest'(sMemRdData(A'range), sMemRdData(B'range), SMemRdData(C'range));
process is
begin
wait for 10 ns;
sTestIn <= tests(0);
wait for 10 ns;
sTestIn <= tests(1);
wait for 10 ns;
wait;
end process;
end architecture sim;
合格表达集合体定义为t检验记录的与位置相关联,其被分配给该记录类型sTestOut的值。
这给出:
![tb.png](https://i.stack.imgur.com/Oms3X.png)
因此可以使用级联用于组装的矢量值(或在-2008的聚集体),并使用聚合为合格的表达式来sMemRdData转移到sTestOut。
如果您还没有计划宣布的A,B或C亚型的对象,你可以声明为整数亚型:
library ieee;
use ieee.std_logic_1164.all;
package TestPck is
subtype A is natural range 12 downto 9;
subtype B is natural range 8 downto 1;
subtype C is natural range 0 downto 0;
constant ABC_len: natural := A'left + 1;
type tTest is record
A: std_logic_vector (A);
B: std_logic_vector (B);
C: std_logic_vector (C);
end record tTest;
type tTests is array (natural range <>) of tTest;
end package TestPck;
library ieee;
use ieee.std_logic_1164.all;
use work.TestPck.all;
entity tb is
end entity tb;
architecture sim of tb is
signal sTestIn: tTest;
signal sMemWrData: std_logic_vector(ABC_len - 1 downto 0);
signal sMemRdData: std_logic_vector(ABC_len - 1 downto 0);
signal sTestOut: tTest;
constant tests: tTests (0 to 1) :=
(0 => (x"E", x"A7", "1"), 1 => (x"7", x"AC", "0"));
begin
sMemWrData <= sTestIn.A & sTestIn.B & sTestIn.C;
sMemRdData <= sMemWrData after 5 ns;
sTestOut <=
tTest'(sMemRdData(A), sMemRdData(B), SMemRdData(C));
process is
begin
wait for 10 ns;
sTestIn <= tests(0);
wait for 10 ns;
sTestIn <= tests(1);
wait for 10 ns;
wait;
end process;
end architecture sim;
这可能是更容易一些阅读。它会产生上面相同的波形。
哇。没有评论的投票 - 对不要问作业抱歉,但如果这太明显或示例答案不显示研究,请做出评论或回答! – FritzDC
*哇。没有意见的投票 - 对不要求作业抱歉,但如果这太明显或示例答案没有显示研究,请做出评论或回答!*你有没有“放弃希望”?每个人都抱怨天气,但没有人愿意为此做任何事情。写一个包。你的例子是两个案例之一,作为记录内省的理由。转换机制到/从任意记录类型是不可能的。该子集不符合该语言的条件。而不是使用记录如何使用定义字段的子类型? – user1155120
_“如何使用子类型定义字段”_你会有指针或照顾举个例子吗?该记录不是主要观点,但不知何故,必须从std_logic_vectors中获取不同信号的更多可读数据,因此使用其他记录是我愿意采取的让步之一。 – FritzDC