VHDL中的可变长度std_logic_vector初始化
发布时间:2020-12-15 04:14:31 所属栏目:Java 来源:网络整理
导读:我有一个可变长度向量std_logic_vector(X downto 0).现在我试图在我的包中定义一个常量用于复位,这样较低的X / 2位是1,其他的是0. 例如,3位向量(X = 3)将使常数“011”,而4位向量将给出常数“0011”. 我怎么能在VHDL包中做到这一点? 下面的代码解释了我想要
我有一个可变长度向量std_logic_vector(X downto 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 := <???>; 解决方法
根据需要,至少有两种选择来初始化您的记录类型.一个是使用初始化函数,另一个是在聚合中使用N的值.
函数是初始化自定义数据类型的好方法.在您的情况下,您可以创建函数default_entry_from_width(n),返回entry_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 另一种方法是使用预先定义的N值用聚合来初始化常量: constant N: natural := 4; constant ENTRY_3: entry_type := ( state => ( N-1 downto N/2 => '1',N/2-1 downto 0 => '0' ) ); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |