【发布时间】:2014-12-18 19:00:31
【问题描述】:
我试图更好地利用 VHDL protected 类型,所以我将以下测试放在一起(当然只是为了说明 - 我的实际用例要复杂得多):
type prot_type1 is protected
procedure set (new_data : integer);
impure function get return integer;
end protected prot_type1;
type prot_type1 is protected body
variable data : integer := 0;
procedure set (new_data : integer) is
begin
data := new_data;
end procedure set;
impure function get return integer is
begin
return data;
end function get;
end protected body prot_type1;
这编译。但是,以下行没有:
type prot_type1_array is array (natural range <>) of prot_type1;
Ashenden 说(第 3 版,第 589 页)“受保护的类型不能用作......复合类型的元素”。这是不幸的。我希望能够用 body 创建另一个受保护的类型:
type prot_type2 is protected body
variable data : prot_type1_array(0 to 3);
procedure set (idx : natural; new_data : integer) is
begin
data(idx).set(new_data);
end procedure set;
...
end protected body prot_type2;
并避免在prot_type1.set() 中重复代码(在这种情况下这无疑是微不足道的,但在我的实际用例中会复杂得多)。不过,似乎我唯一的选择是(1)基本上重写整个prot_type1,除了我的私有变量的数组类型。或者(2),在内部展平数组,如:
type prot_type2 is protected body
variable data0 : prot_type1;
variable data1 : prot_type1;
procedure set (idx : natural; new_data : integer) is
begin
case idx is
when 0 =>
data0.set(new_data);
when 1 =>
data1.set(new_data);
when others =>
-- handle exceptions here
end case;
end procedure set;
...
end protected body prot_type2;
这可行,但对于小型阵列来说有点不受欢迎,对于大型阵列来说非常不受欢迎。还有其他方法吗?
【问题讨论】:
-
也许在
prot_type中使用access类型和integer数组可能是一种可能性。然后可以创建始终对数组进行操作的prot_type,并使用指定数组大小的init方法。那么默认大小可以为1,默认idx可以为0,所以prot_type的使用默认为标量运算,但在需要时仍支持数组运算。是否适合您的实际工作场景? -
好主意,值得一试。不过,我更关心的是重用现有的受保护类型。如果在某些 IP 包中为我提供了标量保护类型,例如...
-
@Morten,这正是我在记分牌包中所做的。作为一个开源 IP 提供商,我觉得这很烦人。编写一个提供删除某些项目的命令的标记记分牌已经足够具有挑战性,而不会增加我必须在内部创建一组记分牌的额外复杂性。在 VHDL 标准组中,我们提出了解决此问题的建议。确保下载优先事项表并投票。如果您对记分牌包感兴趣,请给我发送电子邮件。
-
@Jim - 您对为什么不允许这样做有任何见解吗?
-
在 2008 年修订期间没有要求。
标签: vhdl