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



我是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告诉我,81个中只有4个case语句。天哪,我研究了1位包含9个值。也许最后一行是用来纠正错误的?也许当prstate是"0x"或"xx"时,这一行会使它变为00?好吧,也许吧。

在synopsys DC合成后,出现了一个警告(关于案例):无法到达案例的默认分支。哈哈!我不知道为什么,我也不在乎。

模拟后(使用相同的测试台和网表):

在我设置并释放重置输入后,modelsim显示另一个模块给wd_link一个"x",这导致了一个大错误=>prstate<"xx"和xx,和xx,并以xx结尾。。。甚至wd_link恢复到0或1。

我想:DC不同意4值逻辑(01xz)或9值逻辑。所以最后一行被杀了。但我该怎么办?

请帮帮我,你们都是我的上帝。非常感谢。真诚地

如果prstate的值总是定义良好("00""01""10""11"),那么如果使用,则可以传播任何未定义的值

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

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

Synthesis通常会使用'X's作为一种自由,根据需求使网表更小或更快。

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

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

除了莫顿的回答,你还可以做其他几件事。您可以通过包std_logic_1164函数to_bitvector将std_logic_vector大小写表达式转换为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;

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

您也可以将其他选项的"语句序列"留空,同时显示所有二进制值选项:

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;

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

这些体系结构和实体声明代表了一个最小、完整和可验证的示例,虽然在模拟时没有做任何有趣的事情,但对于合成来说应该是有效的。

在重置prstate时,如果没有看到设计规范的其余部分,就不需要处理case语句中的metalogical值。对metalogical值的赋值对于合成无效。

其他选项代表前面案例陈述备选方案中没有具体提及的所有可能的选择,或者可能不代表。

9值的std_ulogic表示分为三类进行合成。映射为二进制值、金属值和高阻抗值("Z")的值。

"H"one_answers"L"分别映射到"1"one_answers"0"进行合成。

在合成过程中,元逻辑值('U'、'W'、'X'和'-')不会用作评估VHDL代码的输入。

"Z"表示可以由其他驱动程序重写的值。

不可能基于逻辑门级(RTL)基元库中的"Z"值进行分配或驱动选择。他们本可以很容易地发现,其他人的选择代表着没有选择。

IEEE Std 1076-2008,10.9案例说明第9段:

选择others只允许作为最后一个备选方案,并且是其唯一的选择;它代表以前的备选方案中没有给出的所有值(可能没有)。

16.8.2.4.10高阻抗值('Z')的解释第4段:

当静态高阻抗值出现在赋值语句中的值表达式之外的任何上下文中时,合成工具应将其视为等效于静态金属值。

16.8.2.4.5案例陈述中选择的Metalogic值,第1段:

如果一个元逻辑值作为一个选择或选择的一个元素出现,在由合成工具解释的案例陈述中,合成工具应将该选择解释为永远不会发生的选择。也就是说,生成的解释不需要包含与选择相关联的语句序列的存在或不存在相对应的任何构造。

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

最新更新