封装程序要求测试台激励
Package procedure calls for testbench stimulus
我有多种设计,在带有微控制器的并行总线上使用 FPGA。对于每个设计,我都有一个测试台,我使用模拟 MCU 时序的程序模拟总线上的几个 Read/write 操作。
我想知道一种将这些程序打包以便于重用的好方法。现在,程序已定义并作用于测试台实体范围内的信号。我宁愿有这样的东西。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mcu_sim.all; -- contains MCU component and procedures for bus R/W operations
entity tb is
end tb;
architecture a of tb is
-- DUT
component fpga is
port (
clk, rst: in std_logic;
Data: inout std_logic_vector(7 downto 0);
Addr: in std_logic_vector(15 downto 0);
wr: in std_logic;
rd: in std_logic);
end component;
signal clk, rst: std_logic;
-- Bus signals
signal Data: std_logic_vector(7 downto 0);
signal Addr: std_logic_vector(15 downto 0);
signal rd: std_logic;
signal wr: std_logic;
begin
dut: fpga
port map (
clk => clk,
rst => rst,
Data => Data,
Addr => Addr,
wr => wr,
rd => rd
);
mcu1: mcu
port map (
clk => clk,
rst => rst,
Data => Data,
Addr => Addr,
wr => wr,
rd => rd
);
process
begin
clk <= '0';
wait for 0.5 us;
clk <= '1';
wait for 0.5 us;
end process;
stimulus: process
begin
rst <= '1', '0' after 1 us;
-- A list of nice, easy-to-read procedure calls to control the MCU
-- Defined in package mcu_sim: procedure buswrite(data: in std_logic_vector(7 downto 0); addr: in std_logic_vector(15 downto 0));
buswrite(X"01", X"0000"); -- Command for mcu to take control of bus and do a write operation to the fpga
buswrite(X"02", X"0001"); -- Command for mcu to take control of bus and do a write operation to the fpga
wait;
end process;
end a;
包 mcu_sim 将包含模拟 MCU 总线操作所需的一切,我可以使用过程调用轻松定制我的刺激程序。我意识到它需要程序来控制 mcu1 内部发生的事情。可以这样做吗?
如果没有,您将如何制作可重复使用的测试刺激程序?
您可以将程序放在一个包中。但是,要这样做,您需要做两件事:
i) 您必须将程序分成两部分。过程声明,包括名称、参数和 return 类型,放在包声明中。程序体,重复子程序的声明,加上子程序的实现,放在包体中。
ii) 你的过程必须有一个完整的参数列表:参数列表必须包括过程读取的所有信号和变量以及分配给它的所有信号和变量。
package mcu_sim is
procedure buswrite(
data_in : in std_logic_vector(7 downto 0);
addr_in : in std_logic_vector(15 downto 0);
-- you will need to add all the MCU I/O here to give you a complete parameter list, eg
signal Data : out std_logic_vector(7 downto 0);
signal Addr : out std_logic_vector(15 downto 0);
signal rd : out std_logic;
signal wr : out std_logic
);
end package mcu_sim;
package body mcu_sim is
procedure buswrite(
data_in : in std_logic_vector(7 downto 0);
addr_in : in std_logic_vector(15 downto 0);
-- you will need to add all the MCU I/O here to give you a complete parameter list, eg
signal Data : out std_logic_vector(7 downto 0);
signal Addr : out std_logic_vector(15 downto 0);
signal rd : out std_logic;
signal wr : out std_logic
) is
begin
-- the code
end procedure buswrite;
end package body mcu_sim;
所以,你的刺激过程会变成这样:
stimulus: process
begin
rst <= '1', '0' after 1 us;
buswrite(X"01", X"0000", Data, Addr, rd, wr);
buswrite(X"02", X"0001", Data, Addr, rd, wr);
wait;
end process;
Matthew Taylor 的回答基本上是关于如何打包程序的正确方法。
它的缺点是会导致测试平台更加混乱,例如
buswrite(X"01", X"0000", Data, Addr, rd, wr);
buswrite(X"02", X"0001", Data, Addr, rd, wr);
当你想写一些更简洁的东西时,比如
buswrite(X"01", X"0000");
buswrite(X"02", X"0001");
但不能,因为信号 Data, Addr, rd, wr
不在包的范围内。
如果您记得 VHDL 允许基于参数和 return 类型签名的运算符和子程序重载,您会发现您可以添加更简单的过程调用来调用打包形式,而不会产生歧义。
无论是在您的测试平台的声明区域(在信号声明之后),还是您的刺激过程声明区域,所有这些信号都在范围内。
所以你可以在这些声明区域中的任何一个中编写一个简单的过程(取决于有多少进程需要看到它)
procedure buswrite(
data_in : in std_logic_vector(7 downto 0);
addr_in: in std_logic_vector(15 downto 0)) is
begin
buswrite( data_in, addr_in, Data, Addr, rd, wr);
end busWrite;
现在您可以保持您的测试平台代码干净。
我有多种设计,在带有微控制器的并行总线上使用 FPGA。对于每个设计,我都有一个测试台,我使用模拟 MCU 时序的程序模拟总线上的几个 Read/write 操作。
我想知道一种将这些程序打包以便于重用的好方法。现在,程序已定义并作用于测试台实体范围内的信号。我宁愿有这样的东西。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mcu_sim.all; -- contains MCU component and procedures for bus R/W operations
entity tb is
end tb;
architecture a of tb is
-- DUT
component fpga is
port (
clk, rst: in std_logic;
Data: inout std_logic_vector(7 downto 0);
Addr: in std_logic_vector(15 downto 0);
wr: in std_logic;
rd: in std_logic);
end component;
signal clk, rst: std_logic;
-- Bus signals
signal Data: std_logic_vector(7 downto 0);
signal Addr: std_logic_vector(15 downto 0);
signal rd: std_logic;
signal wr: std_logic;
begin
dut: fpga
port map (
clk => clk,
rst => rst,
Data => Data,
Addr => Addr,
wr => wr,
rd => rd
);
mcu1: mcu
port map (
clk => clk,
rst => rst,
Data => Data,
Addr => Addr,
wr => wr,
rd => rd
);
process
begin
clk <= '0';
wait for 0.5 us;
clk <= '1';
wait for 0.5 us;
end process;
stimulus: process
begin
rst <= '1', '0' after 1 us;
-- A list of nice, easy-to-read procedure calls to control the MCU
-- Defined in package mcu_sim: procedure buswrite(data: in std_logic_vector(7 downto 0); addr: in std_logic_vector(15 downto 0));
buswrite(X"01", X"0000"); -- Command for mcu to take control of bus and do a write operation to the fpga
buswrite(X"02", X"0001"); -- Command for mcu to take control of bus and do a write operation to the fpga
wait;
end process;
end a;
包 mcu_sim 将包含模拟 MCU 总线操作所需的一切,我可以使用过程调用轻松定制我的刺激程序。我意识到它需要程序来控制 mcu1 内部发生的事情。可以这样做吗?
如果没有,您将如何制作可重复使用的测试刺激程序?
您可以将程序放在一个包中。但是,要这样做,您需要做两件事:
i) 您必须将程序分成两部分。过程声明,包括名称、参数和 return 类型,放在包声明中。程序体,重复子程序的声明,加上子程序的实现,放在包体中。
ii) 你的过程必须有一个完整的参数列表:参数列表必须包括过程读取的所有信号和变量以及分配给它的所有信号和变量。
package mcu_sim is
procedure buswrite(
data_in : in std_logic_vector(7 downto 0);
addr_in : in std_logic_vector(15 downto 0);
-- you will need to add all the MCU I/O here to give you a complete parameter list, eg
signal Data : out std_logic_vector(7 downto 0);
signal Addr : out std_logic_vector(15 downto 0);
signal rd : out std_logic;
signal wr : out std_logic
);
end package mcu_sim;
package body mcu_sim is
procedure buswrite(
data_in : in std_logic_vector(7 downto 0);
addr_in : in std_logic_vector(15 downto 0);
-- you will need to add all the MCU I/O here to give you a complete parameter list, eg
signal Data : out std_logic_vector(7 downto 0);
signal Addr : out std_logic_vector(15 downto 0);
signal rd : out std_logic;
signal wr : out std_logic
) is
begin
-- the code
end procedure buswrite;
end package body mcu_sim;
所以,你的刺激过程会变成这样:
stimulus: process
begin
rst <= '1', '0' after 1 us;
buswrite(X"01", X"0000", Data, Addr, rd, wr);
buswrite(X"02", X"0001", Data, Addr, rd, wr);
wait;
end process;
Matthew Taylor 的回答基本上是关于如何打包程序的正确方法。
它的缺点是会导致测试平台更加混乱,例如
buswrite(X"01", X"0000", Data, Addr, rd, wr);
buswrite(X"02", X"0001", Data, Addr, rd, wr);
当你想写一些更简洁的东西时,比如
buswrite(X"01", X"0000");
buswrite(X"02", X"0001");
但不能,因为信号 Data, Addr, rd, wr
不在包的范围内。
如果您记得 VHDL 允许基于参数和 return 类型签名的运算符和子程序重载,您会发现您可以添加更简单的过程调用来调用打包形式,而不会产生歧义。
无论是在您的测试平台的声明区域(在信号声明之后),还是您的刺激过程声明区域,所有这些信号都在范围内。
所以你可以在这些声明区域中的任何一个中编写一个简单的过程(取决于有多少进程需要看到它)
procedure buswrite(
data_in : in std_logic_vector(7 downto 0);
addr_in: in std_logic_vector(15 downto 0)) is
begin
buswrite( data_in, addr_in, Data, Addr, rd, wr);
end busWrite;
现在您可以保持您的测试平台代码干净。