某些case选项的VHDL嵌套case语句

某些case选项的VHDL嵌套case语句,vhdl,Vhdl,我不熟悉VHDL,并且使用case语句,我有如下内容: process(state) begin case state is when stop => a <= input; b <= output; when move => a <= input_1; b <= output_1; end case; end process; 进程(状态) 开始 案例状态为 何时停止=> 你的问题充满

我不熟悉VHDL,并且使用case语句,我有如下内容:

process(state)
begin
  case state is
    when stop =>
      a <= input;
      b <= output;
    when move =>
      a <= input_1;
      b <= output_1;
  end case;
end process;
进程(状态)
开始
案例状态为
何时停止=>

你的问题充满了危险。将输出分配给内部信号可能需要inout或buffer的输出端口模式或VHDL 2008支持,这对于合成来说不是通用的。通常,模式缓冲区也不受支持

要了解问题的核心,顺序信号分配支持VHDL 2008中何时支持其他功能,但在合成中通常不支持

case语句选择包含顺序语句

您可以改为使用if语句:

library ieee;
use ieee.std_logic_1164.all;

entity foo is
    port (
        signal input:       in      std_logic;
        signal output:      inout   std_logic;
        signal input_1:     in      std_logic;
        signal input_2:     in      std_logic;
        signal output_1:    inout   std_logic;
        signal output_2:    inout   std_logic
    );
end entity;

architecture fum of foo is
    signal a, b:    std_logic;
    signal c:       std_logic;
    type some_state is (stop, move);
    signal state: some_state;
begin
UNLABELED:
    process(state)
    begin
    case state is
        when stop =>
            a <= input;
            b <= output;
        when move =>
            if c = '0' then
                a <= input_1;
                b <= output_1;
            else 
                a <= input_2;
                b <= output_2;
            end if;
        end case;
    end process;
end architecture;
ieee库;
使用ieee.std_logic_1164.all;
实体foo是
港口(
信号输入:在标准逻辑中;
信号输出:输入输出标准逻辑;
信号输入_1:标准_逻辑中;
信号输入_2:标准_逻辑中;
信号输出1:输入输出标准逻辑;
信号输出2:输入输出标准逻辑
);
终端实体;
foo is的建筑风格
信号a、b:std_逻辑;
信号c:标准逻辑;
输入某些状态为(停止、移动);
信号状态:某些状态;
开始
未标记:
进程(状态)
开始
案例状态为
何时停止=>

2008年以前的VHDL没有三元运算符(类似于C的
?:
)用于顺序 语句,因此您不能编写
,如果c='0',则输入\u 1,否则输入\u 2
,但在 VHDL-2008您可以在c='0'其他输入\u 2时编写
输入\u 1

但是,可以通过制作一个小功能来实现紧凑的编码风格:

function ternary(cond : boolean; res_true, res_false : std_logic) return std_logic is
begin
  if cond then
    return res_true;
  else
    return res_false;
  end if;
end function;
因此,代码的移动部分可以编写为:

when move =>
  a <= ternary(c='0', input_1, input_2);
  b <= ternary(c='0', output_1, output_2);
移动时=>
A.

我不太清楚你在问什么:

我可以像上面这样做吗?不是所有的case选项都嵌套了,但是只有其中一些是嵌套的,或者在这种情况下还有其他方法吗

但这就是你想要做的吗?(请注意,我已将
c
添加到灵敏度列表中):

过程(状态,c)
开始
案例状态为
何时停止=>
A.

那么,有了它,就有可能实现分级FSM了吗?合成器能识别这个吗?你说的识别是什么意思?合成器将产生与您的描述相匹配的逻辑,因此在功能上是正确的(如果不是,请提交一个bug:)。它是否产生“最佳”表示将取决于合成器以及您所称的“最佳”与传递给工具的调谐标志。例如,XST认识到它是一个FSM,并为此进行了优化。我的问题是,如果在另一个内部有一个FSM,合成器将优化这两个。我用XST做了一个小测试,只认出了较低的那个。然而,顶级FSM非常简单…@ferdepe我并不惊讶xst没有看到嵌套状态机。我不知道是否有合成器真的会。但逻辑是否符合时机?它是否符合您的资源目标?代码可读吗?这些是从imho开始的关键度量。代码可读,目前满足我的资源目标。。。我必须看到我的会议要求。我在低频段使用它。。。
when move =>
  a <= ternary(c='0', input_1, input_2);
  b <= ternary(c='0', output_1, output_2);
when move =>
  case c is
    when '0' =>
      a <= input_1;
      b <= output_1;
    when others  =>
      a <= input_2;
      b <= output_2;
  end case;
process(state,c)
begin
  case state is
    when stop =>
      a <= input;  
      b <= output;
    when move =>
      case c is
        when '0' =>
           a <= input_1;
           b <= output_1;
        when '1' =>
           a <= input_2;
           b <= output_2;
        when others => null;
  end case;
end process;