【问题标题】:Custom types vhdl in port declaration端口声明中的自定义类型 vhdl
【发布时间】:2020-03-22 17:13:32
【问题描述】:

我想为程序使用自定义输出端口。 我已经阅读了Can custom types be used in port declaration?,但它并没有解决我的问题。

在 my_package.vhd 中:

package my_package is
    type custom_type is (a1,a2,a3,a4);
end package;

然后在我的 vhdl 程序中:

use work.my_package.all;

entity test is 
    port(testInt : out custom_type);
end entity test;

architecture test_a of test is
    type custom_type is (a1,a2,a3,a4);
    signal s:  custom_type;
begin
    testInt <= s;
end architecture;

但是,现在我有错误:

标识符“s”的类型与其作为“custom_type”类型的用法不一致

【问题讨论】:

  • IEEE Std 1076-2008 6.2 类型声明“通过详细说明不同类型定义创建的类型是不同类型。” 12.3 可见性 “如果内部区域包含该声明的同形异义词,则称该声明隐藏在(部分)内部声明区域内;然后,外部声明隐藏在内部同形异义词的直接范围内。” custom_type 的第二个声明隐藏了架构主体中的包声明(内部声明区域,use 子句出现在根声明区域中)。注释掉内部声明。

标签: vhdl


【解决方案1】:

您已经在 my_package 中声明了 custom_type。因为您在test 实体的体系结构中再次声明了它,所以您有效地创建了一个新类型。因为 VHDL 是强类型的,所以实体中的类型与包中声明的类型不同(并且不兼容)。编译器将使用本地声明的类型而不是包中的类型。

只需从架构中删除一个,然后使用来自通过use work.my_package.all; 子句已经可见的包中的那个。

【讨论】:

    猜你喜欢
    • 2013-05-28
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多