VHDL中变长std_逻辑_向量初始化
我有一个可变长度的向量VHDL中变长std_逻辑_向量初始化,vhdl,Vhdl,我有一个可变长度的向量std\u logic\u向量(X到0)。现在我试图在我的包中定义一个常量来重置,这样较低的X/2位为1,其他位为0 例如,一个3位向量(X=3)将使常数“011”,而一个4位向量将使常数“0011” 如何在VHDL包中实现这一点? 下面的代码解释了我要做的事情 type Entry_Type is record state : std_logic_vector(X-1 downto 0); end record; constant Entry_Constant : E
std\u logic\u向量(X到0)
。现在我试图在我的包中定义一个常量来重置,这样较低的X/2
位为1,其他位为0
例如,一个3位向量(X=3
)将使常数“011”
,而一个4位向量将使常数“0011”
如何在VHDL包中实现这一点?
下面的代码解释了我要做的事情
type Entry_Type is record
state : std_logic_vector(X-1 downto 0);
end record;
constant Entry_Constant : Entry_Type := <???>;
类型输入\u类型为记录
状态:标准逻辑向量(X-1向下至0);
结束记录;
常量输入\常量:输入\类型:=;
至少有两种选择可以根据需要初始化记录类型。一个是使用初始化函数,另一个是使用聚合中的N值
函数是初始化自定义数据类型的好方法。在您的情况下,您可以从宽度(n)创建一个函数default\u entry\u,返回entry\u type
值:
type entry_type is record
state: std_logic_vector;
end record;
function default_entry_from_width(width: natural) return entry_type is
variable return_vector: std_logic_vector(width-1 downto 0);
begin
for i in return_vector'range loop
return_vector(i) := '1' when i <= width/2 else '0';
end loop;
return (state => return_vector);
end;
constant ENTRY_1: entry_type := default_entry_from_width(3); -- return 011
constant ENTRY_2: entry_type := default_entry_from_width(4); -- return 0011
你的意思是这样的:
library ieee;
use ieee.std_logic_1164.all;
package vector_length is
constant X: natural := 3; -- Entry_Type.state length
type Entry_Type is
record
state : std_logic_vector(X-1 downto 0);
end record;
constant entry_default: Entry_Type :=
(state =>
(X-1 downto NATURAL(REAL((X-1)/2) + 0.5) =>'0', others => '1')
);
end package vector_length;
library ieee;
use ieee.std_logic_1164.all;
use work.vector_length.all;
entity fum is
end entity;
architecture foo of fum is
signal entry: Entry_Type := entry_default;
signal default: std_logic_vector (X-1 downto 0);
begin
TEST:
process
begin
default <= entry.state;
wait for 100 ns; -- so it will show up in a waveform display
wait;
end process;
end architecture;
ieee库;
使用ieee.std_logic_1164.all;
包向量_长度为
常数X:自然值:=3;--输入\类型.状态长度
类型输入\类型为
记录
状态:标准逻辑向量(X-1向下至0);
结束记录;
常量输入\默认值:输入\类型:=
(州=>
(X-1向下至自然(实((X-1)/2)+0.5)=>0',其他=>1')
);
端包向量_长度;
图书馆ieee;
使用ieee.std_logic_1164.all;
使用work.vector_length.all;
实体fum是
终端实体;
fum的体系结构foo是
信号录入:录入类型:=录入默认值;
信号默认值:标准逻辑向量(X-1向下至0);
开始
测试:
过程
开始
默认值,如果向记录类型条目添加其他元素,则需要将这些元素的任何默认值添加到条目默认值,其默认值为聚合。
library ieee;
use ieee.std_logic_1164.all;
package vector_length is
constant X: natural := 3; -- Entry_Type.state length
type Entry_Type is
record
state : std_logic_vector(X-1 downto 0);
end record;
constant entry_default: Entry_Type :=
(state =>
(X-1 downto NATURAL(REAL((X-1)/2) + 0.5) =>'0', others => '1')
);
end package vector_length;
library ieee;
use ieee.std_logic_1164.all;
use work.vector_length.all;
entity fum is
end entity;
architecture foo of fum is
signal entry: Entry_Type := entry_default;
signal default: std_logic_vector (X-1 downto 0);
begin
TEST:
process
begin
default <= entry.state;
wait for 100 ns; -- so it will show up in a waveform display
wait;
end process;
end architecture;