端口声明中的自定义类型vhdl

问题描述 投票:0回答:1

我想使用程序的自定义输出端口。我读过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”类型的用法不同

vhdl
1个回答
1
投票

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

仅从体系结构中删除一个,并使用已通过use work.my_package.all;子句可见的软件包中的一个。

© www.soinside.com 2019 - 2024. All rights reserved.