首页 文章

如何使用顺序语句(例如进程)来创建常量值而无需等待?

提问于
浏览
0

为了保持一致性和易维护性,我想使用顺序语句制作一些常量,例如:正在进行中 .

我用以下方法定义了一个范围:

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;

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

一种方法当然是在进程列表中使用未使用的信号,如时钟,但这是一种丑陋的方式 .

并发风格如下:

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

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

有没有办法使用顺序语句来制作常量,但_2584199中不需要 wait

1 回答

  • 1

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

    -- 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);
    

相关问题