2017-03-12 27 views
0

在VHDL中的伪代码我想达到的目的是:如何将记录写入内存并将其恢复为VHDL?

type tTest is record 
    A : std_logic_vector(3 downto 0); 
    B : std_logic_vector(7 downto 0); 
    C : std_logic_vector(0 downto 0); 
end record tTest; 
. . . 
signal sTestIn  : tTest; 
signal sMemWrData : std_logic_vector(fRecordLen(tTest)-1 downto 0); 
signal sMemRdData : std_logic_vector(fRecordLen(tTest)-1 downto 0); 
signal sTestOut  : tTest; 
. . . 
sMemWrData <= fRecordToVector(sTestIn); 
-- At some point sMemRdData gets the data in sMemWrData... 
sTestOut <= fVectorToRecord(sMemRdData); 

fRecordLen是直接从型和fRecordToVector和fVectorToRecord是希望自我解释返回记录的聚集长度的假想功能。目标是可合成的代码,不会产生任何额外的逻辑。我发布当前的解决方案作为进一步澄清操作的答案。然而,这是非常尴尬的方法,由于锅炉板代码的数量,我不认为它是一个可行的解决方案。

我知道record introspection proposal但并不屏住呼吸,甚至提出的方法似乎非常繁琐。

我已经放弃了一个完全一般的解决方案的希望,所以一些让步是可以接受的。例如,只允许记录中的std_logic_vectors并使用几个函数/过程调用。但是,避免使用任何必须手动或根据每个记录进行外部脚本调整的任何锅炉代码将是非常好的。另外,如果有任何可以直接输入/输出记录并且达到相同的Verilog/SystemVerilog包装,则非常欢迎指针。

+0

哇。没有评论的投票 - 对不要问作业抱歉,但如果这太明显或示例答案不显示研究,请做出评论或回答! – FritzDC

+0

*哇。没有意见的投票 - 对不要求作业抱歉,但如果这太明显或示例答案没有显示研究,请做出评论或回答!*你有没有“放弃希望”?每个人都抱怨天气,但没有人愿意为此做任何事情。写一个包。你的例子是两个案例之一,作为记录内省的理由。转换机制到/从任意记录类型是不可能的。该子集不符合该语言的条件。而不是使用记录如何使用定义字段的子类型? – user1155120

+0

_“如何使用子类型定义字段”_你会有指针或照顾举个例子吗?该记录不是主要观点,但不知何故,必须从std_logic_vectors中获取不同信号的更多可读数据,因此使用其他记录是我愿意采取的让步之一。 – FritzDC

回答

0

这是一种实现要求的方法。评论中有缺点/改进的想法。

library ieee; 
use ieee.std_logic_1164.all; 
package TestPck is 
    type tTest is record 
     A : std_logic_vector(3 downto 0); 
     B : std_logic_vector(7 downto 0); 
     C : std_logic_vector(0 downto 0); 
    end record tTest; 
    procedure pSliceToFrom (
     signal vec_to : out std_logic_vector; 
     signal vec_from : in std_logic_vector; 
     position  : inout integer 
    ); 
end package TestPck; 

package body TestPck is 
    procedure pSliceToFrom (
    signal vec_to : out std_logic_vector; 
    signal vec_from : in std_logic_vector; 
    position  : inout integer 
    ) is 
    begin 
    vec_to <= vec_from(position-1 downto position-vec_to'length); 
    position := position-vec_to'length; 
    end pSliceToFrom; 
end package body 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; 
    -- How to create this constant in the package, 
    -- i.e. without needing the signal? 
    constant cTestLength : integer := sTestIn.A'length + sTestIn.B'length + sTestIn.C'length; 
    signal sMemWrData : std_logic_vector(cTestLength-1 downto 0); 
    signal sMemRdData : std_logic_vector(cTestLength-1 downto 0); 
    signal sTestOut  : tTest; 
begin 
    -- How to make this without needing to know what 
    -- is inside tTest? 
    sMemWrData <= sTestIn.A & sTestIn.B & sTestIn.C; 
    -- Memory, Fifo, communication link, doesn't matter... 
    sMemRdData <= sMemWrData after 5 ns; 
    -- How to get the data back without needing this 
    -- process (and the procedure)? 
    slice_data_to_item : process (all) is 
    variable vPosition : integer := 0; 
    begin 
    vPosition := cTestLength; 
    pSliceToFrom(sTestOut.A, sMemRdData, vPosition); 
    pSliceToFrom(sTestOut.B, sMemRdData, vPosition); 
    pSliceToFrom(sTestOut.C, sMemRdData, vPosition); 
    end process slice_data_to_item; 

process is 
    begin 
     wait for 10 ns; 
     sTestIn <= (x"E", x"A7", "1"); 
     wait for 10 ns; 
     sTestIn <= (x"7", x"AC", "0"); 
     wait; 
    end process; 
end architecture sim; 
+0

您似乎有[错过](https://i.stack.imgur.com/0VZNM.png)fVectorToRecord部分。 – user1155120

+0

它的slice_data_to_item,[wave here](http://imgur.com/a/AOwgP)自然不是函数 - 这是我试图找出如何去做的问题。 – FritzDC

1

将数据从矢量(线性数组)转换为记录的一种方法是通过使用聚合。

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

因此可以使用级联用于组装的矢量值(或在-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; 

这可能是更容易一些阅读。它会产生上面相同的波形。

+0

这整齐地摆脱了切片机程序,并允许包内的常量声明 - 所以解决了3个问题中的2个!然而,代码可能有点整洁,声明子类型为stA,然后在记录中只有A:stA。这似乎工作 - 在记录中使用std_logic_vector(A'range)而不是子类型会有一些好处吗? – FritzDC

+0

现在我可以看到,最大的垮台是事实上,范围不是0°。我能够做到这一点,没有手动计算功能,但现在使用这些元素,“downto 0”在第二个自然,我不断在切片记录元素上犯错误。 – FritzDC

+0

啊!我想我知道了 - 使用常量而不是子类型,'长度为1'的downto 0代替记录中的范围。此外,函数调用(from)和(to),而不是一个函数调用它。我可以发布完整答案,但不要踩在user1155120的脚趾上 - 解决方案肯定是他/她的。 – FritzDC

相关问题