將數據從矢量(線性數組)轉換爲記錄的一種方法是通過使用聚合。
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的值。
這給出:
因此可以使用級聯用於組裝的矢量值(或在-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