【问题标题】:Declare a signal of the same type as another signal (VHDL)声明与另一个信号相同类型的信号(VHDL)
【发布时间】:2017-11-20 13:13:09
【问题描述】:

是否可以在 VHDL 中声明与另一个信号相同类型的信号?

例如,假设我们有以下信号声明:

signal address_q : integer range 0 to 31;

我需要声明一个变量address_d,它与address_q 变量(integer range 0 to 31) 的类型相同。是否可以通过使用内置信号属性或其他方式来做到这一点?

【问题讨论】:

    标签: syntax signals vhdl


    【解决方案1】:

    subtype 属性可能是您正在寻找的:

    entity foo is
    end entity foo;
    
    architecture bar of foo is
      signal address_q : integer range 0 to 31;
    begin
      process
        variable v: address_q'subtype;
      begin
        report to_string(v'subtype'left);
        report to_string(v'subtype'right);
        wait;
      end process;
    end architecture bar;
    

    用 GHDL 模拟:

    foo.vhd:10:5:@0ms:(report note): 0
    foo.vhd:11:5:@0ms:(report note): 31
    

    注意:此属性已在 VHDL 2008 中引入。请勿尝试将其与旧版本的 VHDL 标准一起使用。

    【讨论】:

    • 这正是我想要的,但不幸的是,它在 2008 年之前的版本中不起作用。
    【解决方案2】:

    第一种方式:

    您可以一次声明更多信号,用逗号分隔它们。

    signal address_q, address_d : integer range 0 to 31;
    

    第二种方式:

    您可以先声明您的类型,然后将其用于所有信号声明。

    type my_type is integer range 0 to 31;
    
    signal address_q : my_type;
    signal address_d : my_type;
    

    【讨论】:

    • 我知道如何使用这两种方法,但我希望使用信号属性获取信号类型可能会有一些技巧,例如type my_type is signal'type
    • @MarkoGulin 好的。我已经着急了。 :)
    • 你没有,我没有在问题中指定我到底想要什么。感谢你的回答! :)
    • 保留答案,这是原始问题的可能解决方案之一。如果没有其他方法,我会接受答案。
    猜你喜欢
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 2014-02-22
    • 2013-12-18
    相关资源
    最近更新 更多