Vhdl 状态到标准逻辑

Vhdl 状态到标准逻辑,vhdl,fpga,Vhdl,Fpga,我将我的状态定义如下: type state_type is (s0, s1, s2, s3); signal state : state_type; 现在我想用这个状态信息来形成另一个信号 signal data : std_logic_vector(3 downto 0); signal data_plus_state : std_logic_vector(5 downto 0); .... data_plus_state <= data & state; 信号数据:

我将我的状态定义如下:

type state_type is (s0, s1, s2, s3);
signal state   : state_type;
现在我想用这个状态信息来形成另一个信号

signal data : std_logic_vector(3 downto 0);
signal data_plus_state : std_logic_vector(5 downto 0);

....
data_plus_state <= data & state;
信号数据:标准逻辑向量(3到0);
信号数据加状态:标准逻辑向量(5到0);
....

数据加状态定义将状态转换为标准逻辑向量的子程序

该子程序包含case语句,类似于:

case state is
  when s0 => return <std_logic_vector value for s0>;
  when s1 => return <std_logic_vector value for s1>;
  when s2 => return <std_logic_vector value for s2>;
  when s3 => return <std_logic_vector value for s3>;
end case;
案例状态为
当s0=>返回时;
当s1=>返回时;
当s2=>返回时;
当s3=>返回时;
终例;

子程序和案例答案将非常有效。如果你想要什么东西,你可以用这个

signal state_slv : std_logic_vector(1 downto 0);

state_slv <= "00" when state = s0 else
             "01" when state = s1 else
             "10" when state = s2 else
             "11";

data_plus_state <= data & state_slv;
信号状态:标准逻辑向量(1到0);

state_slv似乎您希望将两个(或更多)信号放入一个信号(或端口)

这里的方法不是连接信号,而是将它们放在一个记录中。优点是信号的每个部分的语义(含义)都得到了清晰的表达。这样,您就不必对每个数据元素进行编码(稍后再进行解码)

type state_type is (s0, s1, s2, s3);
signal state   : state_type;
signal data : std_logic_vector(3 downto 0);
type data_plus_state_type is record
    data : std_logic_vector(3 downto 0);
    state: state_type;
end record data_plus_state_type;
signal data_plus_state : data_plus_state_type;
然后,您可以将两个信号放在一个记录信号中:

data_plus_state <= (data, state);
-- or:
data_plus_state.data <= data;
data_plus_state.state <= state;

data\u plus\u state属于ChipHacker,但SO未提供任何选项。真糟糕!