如何测试 VHDL 文件

发布于 2024-12-16 21:03:31 字数 1083 浏览 1 评论 0 原文

我已经用 VHDL 制作了一个双端口寄存器组,我想测试它以确保它有效。我该怎么做呢?我知道我想做什么(将寄存器 2 设置为常量,在测试程序中读出它,写入寄存器 3 并将其读回,看看是否有相同的结果)。

唯一的问题是,我是 VHDL 新手,所以我不知道是否有控制台,也不知道测试程序是如何构造的,也不知道如何实例化寄存器文件,甚至不知道用什么来编译它(我一直在使用 quartus迄今为止)。

这是我的注册文件:

use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;

-- Register File

entity RF is

port(
    signal clk, we: in std_logic;
    signal ImmediateValue : in std_logic_vector(15 downto 0);
    signal RegisterSelectA, RegisterSelectB : in integer range 0 to 15;

    signal AOut, BOut : out std_logic_vector(15 downto 0)
);

end RF

architecture behavior of RF is

    array std_logic_vector_field is array(15 downto 0) of std_logic_vector(15 downto 0);
    variable registers : std_logic_vector(15 downto 0);

    process (clk, we, RegisterSelectA, RegisterSelectB, ImmediateValue)
        wait until clk'event and clk = '1';
        registers(RegisterSelectA) := ImmediateValue when we = '1';
        AOut <= registers(RegisterSelectA);
        BOut <= registers(RegisterSelectB);
    end process;

end behavior;

I've made a dual port register bank in VHDL, and I want to test it to make sure it works. How would I go about doing this? I know what I want to do (set register 2 to be a constant, read out of it in test program, write to register 3 and read it back out and see if I have the same results).

Only thing is, I'm new to VHDL, so I don't know if there's a console or how a test program is structured or how to instantiate the register file, or even what to compile it in (I've been using quartus so far).

Here's my register file:

use IEEE.STD_LOGIC_ARITH.all;
use IEEE.STD_LOGIC_UNSIGNED.all;

-- Register File

entity RF is

port(
    signal clk, we: in std_logic;
    signal ImmediateValue : in std_logic_vector(15 downto 0);
    signal RegisterSelectA, RegisterSelectB : in integer range 0 to 15;

    signal AOut, BOut : out std_logic_vector(15 downto 0)
);

end RF

architecture behavior of RF is

    array std_logic_vector_field is array(15 downto 0) of std_logic_vector(15 downto 0);
    variable registers : std_logic_vector(15 downto 0);

    process (clk, we, RegisterSelectA, RegisterSelectB, ImmediateValue)
        wait until clk'event and clk = '1';
        registers(RegisterSelectA) := ImmediateValue when we = '1';
        AOut <= registers(RegisterSelectA);
        BOut <= registers(RegisterSelectB);
    end process;

end behavior;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-12-23 21:03:31

首先,如果您是 VHDL 设计的新手,那么您最好从网络教程开始,或者阅读诸如 “VHDL 设计指南”

不管怎样,就像软件设计一样,要测试VHDL设计,你必须编写一些测试代码。在硬件设计中,通常这些测试类似于单元测试,但通常称为“testbenches”

对于您给出的设计,您需要创建如下内容:

library ieee.std_logic_1164.all;
library ieee.numeric_std.all;

entity test_RF is
end entity;

architecture test of test_RF is
  signal clk, we: std_logic;
  signal ImmediateValue : std_logic_vector(15 downto 0);
  signal RegisterSelectA, RegisterSelectB : integer range 0 to 15;
  signal AOut, BOut : std_logic_vector(15 downto 0)
begin

  -- Instantiate the design under test
  u_RF : entity work.RF
  port map (
    clk => clk,
    we  => we,
    ImmediateValue => ImmediateValue,
    RegisterSelectA => RegisterSelectA,
    RegisterSelectB => RegisterSelectB,
    AOut => AOut,
    BOut => BOut
  );

  -- create a clock
  process is
  begin
    clk <= '0';
    loop
      wait for 10 ns;
      clk <= not clk;
    end loop;
  end process;

  -- create one or more processes to drive the inputs and read the outputs
  process is
  begin
    wait until rising_edge(clk);
    -- do stuff
    -- use assert to check things
    -- etc
  end process;

end architecture;

First of all, if you are new to VHDL design, you might be best off starting with a tutorial on the web, or grabbing a book like "The Designer's Guide to VHDL".

Anyway, just like a software design, to test a VHDL design, you have to write some test code. In hardware design, usually these tests are unit-test like, but are often called "testbenches".

For the design you've given, you'll need to create something like this:

library ieee.std_logic_1164.all;
library ieee.numeric_std.all;

entity test_RF is
end entity;

architecture test of test_RF is
  signal clk, we: std_logic;
  signal ImmediateValue : std_logic_vector(15 downto 0);
  signal RegisterSelectA, RegisterSelectB : integer range 0 to 15;
  signal AOut, BOut : std_logic_vector(15 downto 0)
begin

  -- Instantiate the design under test
  u_RF : entity work.RF
  port map (
    clk => clk,
    we  => we,
    ImmediateValue => ImmediateValue,
    RegisterSelectA => RegisterSelectA,
    RegisterSelectB => RegisterSelectB,
    AOut => AOut,
    BOut => BOut
  );

  -- create a clock
  process is
  begin
    clk <= '0';
    loop
      wait for 10 ns;
      clk <= not clk;
    end loop;
  end process;

  -- create one or more processes to drive the inputs and read the outputs
  process is
  begin
    wait until rising_edge(clk);
    -- do stuff
    -- use assert to check things
    -- etc
  end process;

end architecture;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文