我在使用我的VHDL测试工作台中的聚合物时遇到了一些麻烦(如下图所示)。使用别名的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 Golden Reference Guide (p.15)这一直是非常有益的,据了解别名和范围去,但我仍然无法弄清楚如何命名范围本身或值或'或'(|)。
目前,我有下面的“黑客”,我真的不喜欢...
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个月。从现在开始,我会知道它在做什么,而不必去找出“现在又是什么[6]了?”或者如果我必须将我的代码交给另一个开发人员,他们可以轻松了解我想要完成的任务。
任何帮助/建议,将不胜感激如何做到这一点。
感谢您的阅读。
编辑:修正了7 | 0
是有效的:
无效:
7 | 0 => "10",
有效期:
7 | 0 => '1',
除@ user1155120的答案外,还可以使用索引类型为枚举类型的数组。 – Paebbels
你有没有理由不使用记录类型?他们命名了字段。如果您还需要矢量化版本的数据,则可以非常轻松地在矢量和记录类型之间编写转换函数。 –
@RenaudPacalet我没有使用记录,因为它对我来说没有任何意义,只要寄存器是什么(即一个位的集合)。你通常使用记录来表示设计中的寄存器而不是'std_logic_vector'? – bgarisn