【问题标题】:VHDL - GHDL Initialise std_logic_vector with smaller bit lengthVHDL - GHDL 用较小的位长度初始化 std_logic_vector
【发布时间】:2019-05-19 14:16:39
【问题描述】:

我有一个signal dataIn : std_logic_vector ( 15 downto 0);

我想提供小于 16 位的输入,例如 dataIn <= x"000a",这些位占据最高有效位,其余位为零。 在verilog中你可以很容易地做到这一点,但在VHDL中你会得到错误:

“字符串长度与定义的匿名整数子类型不匹配...”。

我知道如果您使用 16x"bit_string" 可以解决问题,但这仅适用于 VHDL-2008,ghdl 尚不支持 VHDL-2008。

IEEE Std 1076-2002 有什么方法吗?

【问题讨论】:

  • ghdl 实际上确实 支持 VHDL2008(在我看来甚至比大多数商业模拟器更完整)。下载最新版本并尝试--std=08 命令行开关。
  • 您的示例 dataIn <= x"000a" 提供了一个长度为 16 的简单信号分配波形表达式。例如IEEE Std 1076-2002 13.7 位串文字“如果基本说明符是'O'(分别为'X'),则位串文字的值是通过将bit_value中的每个扩展数字替换为由以下组成的序列而获得的序列三个(分别为四个)值,表示取自字符文字 '0' 和 '1';..." 的扩展数字(为了您的目的,这比 -2008 15.8 位字符串文字,扩展位值更容易阅读)。尝试不同的示例。

标签: vhdl ghdl


【解决方案1】:

对于 VHDL-87/93/2002,您可以使用 numeric_std 包中的 resize 函数。

library ieee;
use ieee.numeric_std.all;
...
constant FOO : std_logic_vector(2 downto 0) := "010";
signal dataIn : std_logic_vector(15 downto 0) := std_logic_vector(resize(unsigned(FOO), 16));

请注意,resize 函数仅针对 signedunsigned 类型定义。
如果您希望将短位字符串放入 MSB,您可能需要使用 'reverse_order 属性。

通常你会发现定义一个封装更复杂初始化的专用函数更容易。

constant FOO : std_logic_vector(2 downto 0) := "010";

function init_dataIn (bar : std_logic_vector; len : integer) return std_logic_vector is
begin
  return bar & (len - bar'length - 1 downto 0 => '0');
end function init_dataIn;

signal dataIn : std_logic_vector(15 downto 0) := init_dataIn(FOO, 16);

【讨论】:

  • 对于完全受限的子类型(信号数据输入,如图所示)dataIn <= (1 => FOO(1), others => '0'); -2008 9.3.3.3 数组聚合“具有其他选项的数组聚合的索引范围应可从上下文中确定。 ...e) 作为赋值语句中的值表达式,其中目标是声明的对象(或其成员),并且目标的子类型是完全约束的数组子类型或目标是切片名称。”另见 IEEE Std 1076-1993/2000/2002 7.3.2.2 Array aggregates, d)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多