如何使用顺序语句(例如过程)来生成常量值而不等待?

How to use sequential statements (e.g. process) to make constant value but without wait?

为了一致性和便于维护,我想使用顺序语句来制作一些常量,例如处理中。

我定义了一个范围:

subtype FIELD is natural range 3 downto 0;

生成值的过程可能如下所示:

process is
begin
    reg <= (others => '0');
    reg(FIELD) <= (others => '1');
    wait;  -- Error in Xilinx ISE
end process;

但是,wait 不被 Xilinx ISE 综合工具接受。

一种方法当然是在进程列表中使用未使用的信号,例如时钟,但那有点丑陋。

并发样式如下:

reg <= (FIELD => (others => '1'), others => '0');

但是在VHDL中不能像FIELD那样使用

有没有办法使用顺序语句创建常量,但 process 中不需要 wait

您可以使用函数来执行此操作。请注意,我没有对范围进行任何错误检查,但并不难。

-- subtypes
subtype FIELD is natural range 3 downto 0;

-- functions
function test_func(a: std_logic_vector) return std_logic_vector is
    variable result : std_logic_vector(a'left downto a'right) := a;
begin
    result(FIELD) := (others => '1');
    return result;
end function;

-- constants
constant ALL_ZEROS  : std_logic_vector(7 downto 0) := (others => '0');

-- signals
signal reg          : std_logic_vector(7 downto 0) := test_func(ALL_ZEROS);