0

我正在尝试在 DesignWorks 5 中用 VHDL 实现 16 * 37 的高速缓存。代码如下。代码运行,但是当我从 IO 面板更改值甚至模拟时,时序图什么也没有显示,基本上代码由于某种原因没有运行。任何建议都会非常有帮助。

代码:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;

entity Cache is
port(cs, r, clr : in std_logic;
    data : in std_logic_vector(31 downto 0);
    addr : in std_logic_vector(7 downto 0);
    cline : out std_logic_vector(31 downto 0);
    ctag: out std_logic_vector(3 downto 0);
    v : out std_logic);
end Cache;

architecture behav of Cache is
type RAM is array (0 to 15) of std_logic_vector(36 downto 0); 
begin 
 process is
 variable M : RAM; 
 variable locn : natural; 
 variable temp_val : std_logic_vector(36 downto 0); 
 variable cline_val : std_logic_vector(31 downto 0);
 variable ctag_val : std_logic_vector(3 downto 0);
 variable v_val : std_logic;
    begin

        if cs = '1' then
            locn := to_integer(addr); 
            if r = '1' then 
                temp_val := M(locn); 
                cline_val := temp_val(31 downto 0);
                ctag_val := temp_val(35 downto 32);
                v_val := temp_val(36);
            else
                temp_val(31 downto 0) := data;
                temp_val(35 downto 32) := addr(3 downto 0);
                temp_val(36) := '1';
                M(locn) := temp_val;
                v_val := 'Z'; 
                ctag_val:= "ZZZZ"; 
                cline_val:= "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
            end if; 
        end if; 
        if clr ='1' then
            locn := 0;
            while(locn<16) loop
                M(locn) := X"000000000" + "0";
                locn:=locn+1;
            end loop;
        end if;
    cline <= cline_val; 
    ctag <= ctag_val;
    v <= v_val;
    wait on cs; 
end process;

end behav;
4

1 回答 1

0

这一行:

M(locn) := X"000000000" + "0"; 

看起来不正确。

M 是您的 ram 数组类型,元素长度为 37。添加到零的 36 位零仍然是 36 位(看起来您没有达到此语句,这将是运行时错误)。

要制作长度为 37 的 '0' 值向量,请使用 `(others => '0')。

你也可以使用 for 循环来清除内存,你不需要使用 16 的索引,它超出了范围,这告诉我们你也没有达到清除。

我认为您应该向我们展示您的刺激,否则您的问题将无法重现。

您缺少的dataaddr作为敏感性元素(以及,您的情况是 cs 环绕,但您想在这里构建一个硬件模型)。

切换到敏感列表(cs, data, addr)

locn是一个不受约束的自然值,并且应该具有与数组类型 ram 匹配的范围(0 到 15)。注意你的 while 循环达到 16。真的,使用 for 循环(如下所示)。约束的原因locn是为了防止访问时出现绑定错误ram(locn)

请注意,要转换addr为自然 ( locn),您需要addr使用长度为 4 的“1”进行 AND 掩码,以防止正常 ram 操作的范围错误。

ieee=synopsys -fexplict包 numeric_std 是一种矫揉造作,它比在分析和详细说明期间将几个命令行选项传递给 ghdl ( ) 更容易。

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

entity cache is
    port (
        cs, r, clr: in  std_logic;
        data:       in  std_logic_vector(31 downto 0);
        addr:       in  std_logic_vector(7 downto 0);
        cline:      out std_logic_vector(31 downto 0);
        ctag:       out std_logic_vector(3 downto 0);
        v:          out std_logic
    );
end entity;

architecture behav of cache is
    type ram is array (0 to 15) of std_logic_vector(36 downto 0);    
begin 

    process (cs, data, addr)
        variable m : ram; 
        variable locn : natural range (ram'range); 
        variable temp_val : std_logic_vector(36 downto 0); 
        variable cline_val : std_logic_vector(31 downto 0);
        variable ctag_val : std_logic_vector(3 downto 0);
        variable v_val : std_logic;
    begin
        if cs = '1' then
            locn := to_integer(unsigned(addr and x"0F")); 
            if r = '1' then 
                temp_val := m(locn); 
                cline_val := temp_val(31 downto 0);
                ctag_val := temp_val(35 downto 32);
                v_val := temp_val(36);
            else
                temp_val(31 downto 0) := data;
                temp_val(35 downto 32) := addr(3 downto 0);
                temp_val(36) := '1';
                m(locn) := temp_val;
                v_val := 'Z'; 
                ctag_val:= "ZZZZ"; 
                cline_val:= (others => 'Z');
            end if; 
        end if; 
        if clr ='1' then
            for i in ram'range loop
                m(i) := (others => '0');
            end loop;
        end if;
        cline <= cline_val; 
        ctag <= ctag_val;
        v <= v_val;
    end process;
end architecture;

这段代码分析和阐述,你可能在我没有提到的地方出现错误,并且在运行时在赋值中出现绑定(范围)错误(表达式可以不关心)。

最后一点:

            temp_val(31 downto 0) := data;
            temp_val(35 downto 32) := addr(3 downto 0);
            temp_val(36) := '1';

可以表示为:

            temp_val:= '1' & addr(3 downto 0) & data;

也:

            locn := to_integer(addr);

表示为:

            locn := to_integer(addr(3 downto 0));

ram'range如果您使用泛型设置 ram 大小,您还可以创建一个具有算法定义长度的 AND 掩码。

在没有看到你的刺激的情况下,有几个地方可能会导致运行时错误。检查您的控制台输出。

于 2014-12-01T04:40:19.413 回答