gpt4 book ai didi

vhdl - 基于通用设置VHDL外部属性

转载 作者:行者123 更新时间:2023-12-02 10:46:48 25 4
gpt4 key购买 nike

我正在尝试编写调用外部子程序并支持VHDL-2008 VHPI 接口(interface)和Modelsim FLI 接口(interface)的VHDL 模块。 VHDL-2008 标记外部子程序的机制是:

atrribute foreign of some_subprogram : procedure is "VHPI libname;some_subprogram";

但是 Modelsim 的 FLI 将其定义为:

attribute foreign of some_subprogram : procedure is "some_subprogram libname";

我想对这些使用相同的实体/架构对,因为所有 VHDL 都是相同的。唯一不同的是外部子程序属性。我尝试过类似的方法:

function get_foreign_attribute_string(func_name : in string; libname : in libname) return string;

attribute foreign of some_subprogram : procedure is get_foreign_attribute_string("some_subprogram", "libname");

但是 Modelsim 拒绝接受外部属性不是字符串文字的说法。

我尝试将函数插入包中,并在包主体中定义属性,但它要求将属性附加到函数声明中。

缺少声明两个包并根据工具集有选择地编译,我不确定如何实现这一点。

安迪的想法?

编辑:这是一个示例案例。

library std; -- for foriegn attribute
use std.all;

entity foo is
generic
(
SIMULATOR : integer range 0 to 1 -- 0 = Modelsim FLI, 1 = VHDL-2008 VHPI
);
end entity foo;

architecture test of foo is
function get_foreign_attribute_string(func_name : in string; libname : in string) return string is
begin
case SIMULATOR is
when 0 =>
return func_name & " " & libname;
when 1 =>
return "VHPI " & libname & ";" & func_name;
end case;
end function;

procedure some_subprogram is
begin
report "some_subprogram";
end procedure;
attribute foreign of some_subprogram : procedure is get_foreign_attribute_string("some_subprogram", "libname");
begin
end architecture test;

编辑:这是我的第一个解决方法:

library std; -- for foreign attribute
use std.all;

entity foo is
generic
(
SIMULATOR : integer range 0 to 1 -- 0 = Modelsim FLI, 1 = VHDL-2008 VHPI
);
end entity foo;

architecture test of foo is
procedure some_subprogram_mti is
begin
assert false;
end procedure some_subprogram_mti;
attribute foreign of some_subprogram_mti : procedure is "some_subprogram libname";

procedure some_subprogram_vhpi is
begin
assert false;
end procedure some_subprogram_vhpi;
attribute foreign of some_subprogram_vhpi : procedure is "VHPI libname;some_subprogram";

procedure some_subprogram is
begin
case SIMULATOR is
when 0 =>
some_subprogram_mti;
when 1 =>
some_subprogram_vhpi;
end case;
end procedure;

begin
end architecture test;

不幸的是,这也失败了,因为模拟器在精化过程中尝试绑定(bind)外部函数。并且 _vhpi 版本不会绑定(bind)。

最佳答案

并不是真正的答案,但评论太长了:

这似乎是 foreign 属性的特殊行为。因此,这段代码在 Modelsim 上运行良好:

entity ATTRIBUTE_TEST is
end entity ATTRIBUTE_TEST;

architecture ATTRIBUTE_TEST of ATTRIBUTE_TEST is
function get_foreign_attribute_string(func_name : in string; libname : in string) return string is
begin
return func_name & " " & libname;
end function;
procedure some_subprogram is
begin
report "some_subprogram";
end procedure;
attribute not_foreign : string;
attribute not_foreign of some_subprogram : procedure is get_foreign_attribute_string("some_subprogram", "libname");
begin
process
begin
report "process";
wait;
end process;
end architecture ATTRIBUTE_TEST;

1076-2008 第 14.4.1 节规定:

The elaboration of a declarative part consists of the elaboration of the declarative items, if any, in the order in which they are given in the declarative part. This rule holds for all declarative parts, with the following three exceptions:

...

c) A subprogram declarative part whose subprogram is decorated with the 'FOREIGN attribute defined in package STANDARD.

For these cases, the declarative items are not elaborated; instead, the design entity or subprogram is subject to implementation-dependent elaboration.

这似乎与这里相关。

关于vhdl - 基于通用设置VHDL外部属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35933733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com