vhdl case语句中,如何处理4值逻辑?

in vhdl case statements,how to deal with 4 value logic?

我是 vhdl 的新手,我正在为一个项目工作。

但最近有事阻碍了我:

   if reset='0' then 
      prstate<="00";
      else if rising_edge(clock)  then
      case  prstate  is
          when "00"=> 
               if wd_link='1'   then
               prstate<="01";
          when "01"=> 
               (do something and) prstate<="10";
          when "10"=> 
                (do something and) prstate<="11";  
          when "11"=> 
                (do something and) prstate<="00";  
          when others=>   prstate<="00"; ----please pay attention to this line

RTL 模拟:

起初,我删除了最后一行,但是modelsim告诉我只有4个case语句81.My上帝,我研究了1位包含9 values.maybe最后一行被使用纠正错误?也许当 prstate 是“0x”或 "xx" 时,这条线将它带到 00?好吧,也许吧。

用synopsys DC综合后,有一个警告(关于case):case的default branch cannot be reached。 哈!我不知道为什么,我不在乎。

Post仿真(使用相同的测试平台和网表):

在我设置并释放复位输入后,modelsim 显示另一个模块给 wd_link 一个 "x",这会导致一个大错误=>prstate<="xx" 和xx,and xx,and end to xx...even wd_link recover to 0 or 1.

我guess:DC不同意4值逻辑(01xz)或9值logic.so最后一行是killed.but我能做什么?

请帮帮我,你都是我的god.Thank你! 此致

如果prstate的值总是要明确定义("00""01""10""11"),那么你可以传播如果您使用任何未定义的值:

when others => prstate <= (others => "XX");

如果出现错误,模拟将在更多地方显示 'X's,从而更容易捕捉。

综合通常会使用 'X's 作为使网表更小或更快的自由,具体取决于要求。

std_logic是一个有9个值的多值逻辑系统。

案例陈述(IEEE Std 1076-2008 10.9 案例陈述)要求所有值都表示为选项(第 5 段)。

除了 Morten 的回答之外,您还可以做一些其他的事情。您可以通过包 std_logic_1164 函数 to_bitvector 将 std_logic_vector case 表达式转换为 bit_vector 变量(注意您还没有演示 prstate 的声明)。

architecture fum of others_case is
    signal wd_link:     std_logic;
    signal prstate:     std_logic_vector(1 downto 0);

   function do_something return boolean is
    begin
        return true;
    end function;
begin

    process (reset, clock)
        variable prstate_proxy: bit_vector (1 downto 0); -- locally static range
    begin
        if reset = '0' then 
            prstate <= "00";
        elsif rising_edge(clock)  then
            prstate_proxy := to_bitvector(prstate);
            case  prstate_proxy  is
                when "00" => 
                    if wd_link = '1'   then
                        prstate <= "01";
                    end if;  -- ADDED
               when "01" => 
                     if do_something then
                         prstate <= "10";
                     end if;
               when "10" => 
                   if do_something then
                       prstate <= "11";
                   end if; 
               when "11" => 
                   if do_something then
                       prstate <= "10";
                   end if; 
               -- when others =>  ----please pay attention to this line
           end case;
       end if;
    end process;
end architecture;

请注意,在分析时需要知道用作 case 语句表达式的一维数组的范围(局部静态)。这通过变量声明来满足。

您也可以将其他选项的 'sequence of statements' 留空,并显示所有二进制值选项:

library ieee;
use ieee.std_logic_1164.all;

entity others_case is
    port (
        reset:  in  std_logic;
        clock:  in  std_logic
    );
end entity;

architecture foo of others_case is
    signal wd_link:     std_logic;
    signal prstate:     std_logic_vector(1 downto 0);

   function do_something return boolean is
    begin
        return true;
    end function;
begin

    process (reset, clock)
    begin
        if reset = '0' then 
            prstate <= "00";
        elsif rising_edge(clock)  then
            case  prstate  is
                when "00" => 
                    if wd_link = '1'   then
                        prstate <= "01";
                    end if;  -- ADDED
               when "01" => 
                     if do_something then
                         prstate <= "10";
                     end if;
               when "10" => 
                   if do_something then
                       prstate <= "11";
                   end if; 
               when "11" => 
                   if do_something then
                       prstate <= "10";
                   end if; 
               when others =>  ----please pay attention to this line
           end case;
       end if;
    end process;

end architecture;

请注意,当结束语句之前没有语句时,others 选项中缺少分号(语句分隔符)。这提供了与 Morten 的回答相同的效果。

这些架构和实体声明代表了一个Minimal, Complete, and Verifiable example并且在模拟时没有做任何有趣的事情应该对合成有效。

在没有看到设计规范的其余部分的情况下,您不需要在重置 prstate 时处理 case 语句中的元逻辑值。元逻辑值的赋值对综合无效。

others 选项代表前面 case 语句备选方案中未具体提及的所有可能选项,或者可能代表 none。

将9值std_ulogic表示归类为三个类进行综合。映射到二进制值、元逻辑值和高阻抗值 ('Z') 的值。

'H'和'L'分别映射到'1'和'0'进行合成。

元逻辑值('U'、'W'、'X' 和“-”)在综合期间不用作评估 VHDL 代码的输入。

'Z' 表示可以被其他驱动程序覆盖的值。

无法根据逻辑门级 (RTL) 原语库中的 'Z' 值进行分配或驱动选择。他们本可以很容易地发现其他选择代表别无选择。

IEEE 标准 1076-2008,10.9 案例陈述第 9 段:

The choice others is only allowed for the last alternative and as its only choice; it stands for all values (possibly none) not given in the choices of previous alternatives.

16.8.2.4.10高阻值解读('Z')第4段:

Whenever a static high-impedance value occurs in any context other than a value expression in an assignment statement, a synthesis tool shall treat it as equivalent to a static metalogical value.

16.8.2.4.5 元逻辑值作为案例陈述中的选择,第 1 段:

If a metalogical value occurs as a choice, or as an element of a choice, in a case statement that is interpreted by a synthesis tool, the synthesis tool shall interpret the choice as one that can never occur. That is, the interpretation that is generated is not required to contain any constructs corresponding to the presence or absence of the sequence of statements associated with the choice.

Synopsys 警告 RTL 综合中不存在的问题(另请参阅已撤销的 IEEE Std-1076.6-2004,5。验证方法,验证综合设计规范不依赖于输入元逻辑值)。