我在我的 VHDL 测试台中使用聚合时遇到了一些麻烦(简写如下所示)。
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all
entity TB is
end entity;
architecture RTL of TB is
-- constant(s)
constant CLK_PERIOD : time := 10 ns; -- 100 MHz
-- signal(s)
signal CLK : std_logic := '0';
signal nRST : std_logic := '1';
signal CONFIG_REG : std_logic_vector(7 downto 0) := (others => '0');
begin
-- clock driver
CLK <= NOT CLK after (CLK_PERIOD / 2.0);
-- main process
process
begin
-- reset driver...
nRST <=
'1',
'0' after (CLK_PERIOD * 1);
-- set initial configuration...
CONFIG_REG <= (
6 => '1',
3 downto 2 => "01",
7 | 0 => '1',
others => '0'
);
-- do test-bench stuff...
-- update configuration...
CONFIG_REG <= (
6 => '0',
3 downto 2 => "10",
7 | 0 => '1',
others => '0'
);
-- do more test-bench stuff...
end process;
end architecture;
我真的想“命名”配置寄存器的各个部分,以便它实际上读起来很好。
所以我想说:
Bit[6] = ENABLE
Bit[3:2] = MODE
Bit[7|0] = READY_DONE
我知道我可以为 6 使用常量:
constant ENABLE : integer := 6;
然后我的代码如下所示:
CONFIG_REG <= (
ENABLE => '1',
3 downto 2 => "01",
7 | 0 => '1',
others => '0'
);
但是我很难尝试获取范围3 downto 2
和7|0
命名,以便代码看起来像:
CONFIG_REG <= (
ENABLE => '1',
MODE => "01",
READY_DONE => '1',
others => '0'
);
我认为我可以使用别名来完成此操作,并且我一直在查看VHDL 黄金参考指南(第 15 页),就理解别名和范围而言,它非常有帮助,但我仍然无法弄清楚如何命名范围本身或值的“或”(|)。
目前我有以下'hack',我不太喜欢......
constant ENABLE : integer := 6;
alias MODE is CONFIG_REG(3 downto 2);
-- what to do about the OR though???
CONFIG_REG <= (
ENABLE => '1',
MODE'RANGE => "01",
7 | 0 => '1',
others => '0'
);
我真的想让我的测试台可读,这样当我在 6 个月内查看它时。从现在开始,我将知道它在做什么,而不必去弄清楚“现在又是什么 bit[6] ???” 或者如果我必须将我的代码交给其他开发人员,他们可以很容易地了解我想要完成的工作。
任何帮助/建议将不胜感激如何做到这一点。
谢谢阅读。
编辑:修复7 | 0
有效:
无效的:
7 | 0 => "10",
有效的:
7 | 0 => '1',