Vhdl &引用;“强迫未知”;测试中输出的值
我正在尝试用VHDL写寄存器文件。首先,我定义N位的存储元素。其次实现寄存器文件,包括WA(写地址)、RA(读地址)、WDR/RDP(写/读数据端口)等。之后,为regfile生成testbench,但在测试中,当通过RA地址获取任何数据时,会得到“X”。我怎样才能解决这个问题?也许我的regfile的实现有问题 a) 存储数据的元素Vhdl &引用;“强迫未知”;测试中输出的值,vhdl,Vhdl,我正在尝试用VHDL写寄存器文件。首先,我定义N位的存储元素。其次实现寄存器文件,包括WA(写地址)、RA(读地址)、WDR/RDP(写/读数据端口)等。之后,为regfile生成testbench,但在测试中,当通过RA地址获取任何数据时,会得到“X”。我怎样才能解决这个问题?也许我的regfile的实现有问题 a) 存储数据的元素 library ieee; use ieee.std_logic_1164.all; entity REGn is generic(INITREG:
library ieee;
use ieee.std_logic_1164.all;
entity REGn is
generic(INITREG: std_logic_vector:="1001");
port(Din : in std_logic_vector(INITREG'range);
EN : in std_logic;
INIT: in std_logic;
CLK : in std_logic;
OE : in std_logic;
Dout: out std_logic_vector(INITREG'range));
end REGn;
architecture beh_regn of REGn is
signal reg: std_logic_vector(INITREG'range);
constant ALLZ: std_logic_vector(INITREG'range):=(others => 'Z');
begin
Main: process(Din, EN, INIT, CLK)
begin
if INIT = '1' then
reg <= INITREG;
elsif EN = '1' then
if rising_edge(CLK) then
reg <= Din;
end if;
end if;
end process;
Dout <= reg when OE='0' else ALLZ;
end beh_regn;
ieee库;
使用ieee.std_logic_1164.all;
实体注册号为
通用(INITREG:std_logic_vector:=“1001”);
端口(Din:标准逻辑向量(INITREG'范围);
EN:标准逻辑;
INIT:在标准逻辑中;
CLK:标准逻辑中;
OE:标准逻辑;
Dout:out标准逻辑向量(INITREG'range);
结束注册;
regn的架构beh_regn是
信号寄存器:标准逻辑向量(初始寄存器范围);
常量ALLZ:std_逻辑_向量(INITREG'range):=(其他=>'Z');
开始
主要:工艺(Din、EN、INIT、CLK)
开始
如果INIT='1',则
reg'1',WDP=>“0000”,WA=>“00”,RA=>“00”,WE=>“0”),
(初始=>'1',WDP=>'0000',WA=>'01',RA=>'01',WE=>'0'),
(初始=>'1',WDP=>'0000',WA=>'10',RA=>'10',WE=>'0'),
(INIT=>“1”,WDP=>“0000”,WA=>“11”,RA=>“11”,WE=>“0”),
---测试向量
(初始=>'0',WDP=>'1000',WA=>'00',RA=>'00',WE=>'1'),
(初始=>'0',WDP=>'1000',WA=>'00',RA=>'00',WE=>'0')
);
开始
--被测单元端口图
UUT:regfile
通用地图(
INITREG=>INITREG,
a=>a
)
港口地图(
INIT=>INIT,
WDP=>WDP,
WA=>WA,
RA=>RA,
我们=>我们,
RDP=>RDP
);
--在这里添加你的刺激。。。
过程
变量向量:TEST_REC;
开始
对于模式范围循环中的i
向量:=模式(i);
初始化您的输出不正确:
(图像链接到全尺寸图像)
请注意,对于所有四个Regn实例,三个实例同时处于低位,它们会导致不同的READ位发生冲突
在regn的架构beh_regn中:
Dout <= reg when OE='0' else ALLZ;
Dout深入到您的代码中,查看哪个信号正在驱动位0上具有未知值的RDP。将更多信号添加到较低级别的波形中。为什么要将我们连接到Clk信号?我认为中电应该有自己的专用中电?
library ieee;
library std;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use std.textio.all;
-- Add your library and packages declaration here ...
entity regfile_tb is
-- Generic declarations of the tested unit
generic(
INITREG : STD_LOGIC_VECTOR := "0000";
a : INTEGER := 2 );
end regfile_tb;
architecture TB_ARCHITECTURE of regfile_tb is
-- Component declaration of the tested unit
component regfile
generic(
INITREG : STD_LOGIC_VECTOR := "0000";
a : INTEGER := 2 );
port(
INIT : in STD_LOGIC;
WDP : in STD_LOGIC_VECTOR(INITREG'range);
WA : in STD_LOGIC_VECTOR(a-1 downto 0);
RA : in STD_LOGIC_VECTOR(a-1 downto 0);
WE : in STD_LOGIC;
RDP : out STD_LOGIC_VECTOR(INITREG'range) );
end component;
-- Stimulus signals - signals mapped to the input and inout ports of tested entity
signal INIT : STD_LOGIC;
signal WDP : STD_LOGIC_VECTOR(INITREG'range);
signal WA : STD_LOGIC_VECTOR(a-1 downto 0);
signal RA : STD_LOGIC_VECTOR(a-1 downto 0);
signal WE : STD_LOGIC;
-- Observed signals - signals mapped to the output ports of tested entity
signal RDP : STD_LOGIC_VECTOR(INITREG'range);
-- Add your code here ...
type TEST_REC is record
INIT : STD_LOGIC;
WDP : STD_LOGIC_VECTOR(INITREG'range);
WA : STD_LOGIC_VECTOR(a-1 downto 0);
RA : STD_LOGIC_VECTOR(a-1 downto 0);
WE : STD_LOGIC;
end record;
type TEST_ARRAY is array(positive range <>) of TEST_REC;
constant PATTERN : test_array:= (
-- initialize
(INIT=>'1', WDP=>"0000", WA=>"00", RA=>"00", WE=>'0'),
(INIT=>'1', WDP=>"0000", WA=>"01", RA=>"01", WE=>'0'),
(INIT=>'1', WDP=>"0000", WA=>"10", RA=>"10", WE=>'0'),
(INIT=>'1', WDP=>"0000", WA=>"11", RA=>"11", WE=>'0'),
--- test vectors
(INIT=>'0', WDP=>"1000", WA=>"00", RA=>"00", WE=>'1'),
(INIT=>'0', WDP=>"1000", WA=>"00", RA=>"00", WE=>'0')
);
begin
-- Unit Under Test port map
UUT : regfile
generic map (
INITREG => INITREG,
a => a
)
port map (
INIT => INIT,
WDP => WDP,
WA => WA,
RA => RA,
WE => WE,
RDP => RDP
);
-- Add your stimulus here ...
process
variable VECTOR: TEST_REC;
begin
for i in PATTERN'range loop
VECTOR:= PATTERN(i);
INIT <= VECTOR.INIT;
WDP <= VECTOR.WDP;
WA <= VECTOR.WA;
RA <= VECTOR.RA;
WE <= VECTOR.WE;
wait for 100 ns;
end loop;
end process;
process
variable my_line: line;
begin
wait for 5ns;
write(my_line,"WDP=");
write(my_line,WDP);
write(my_line," INIT=");
write(my_line,INIT);
write(my_line," WA=");
write(my_line,WA);
write(my_line," RA=");
write(my_line,RA);
write(my_line," RDP=");
write(my_line,RDP);
writeline(output,my_line);
wait for 96ns;
end process;
end TB_ARCHITECTURE;
configuration TESTBENCH_FOR_regfile of regfile_tb is
for TB_ARCHITECTURE
for UUT : regfile
use entity work.regfile(beh_regfile);
end for;
end for;
end TESTBENCH_FOR_regfile;
Dout <= reg when OE='0' else ALLZ;
-- Read decoder
RAD: process(RA)
begin
for i in 0 to 2**a-1 loop
if i = CONV_INTEGER(RA) then
ren(i) <= '0'; -- was '1'
else
ren(i) <= '1'; -- was '0'
end if;
end loop;
end process;