用VHDL调用子过程

时间:2011-01-18 13:13:55

标签: hardware vhdl

我有两个嵌套程序,其中“主”程序 利用“subproc”在变量中累积结果 t0和t1,然后在结束时返回。这应该都是 在一个时钟周期内计算,电路或多或少 只包含简单的逻辑门(xor,或,和)。当我尝试 如下所述描述电路我得到以下错误:

Acutal (variable t0) for formal "a" is not a signal

这是有道理的,因为子过程需要信号作为输入, 但我想在主程序中传递一个变量。是 有一个简单的方法可以通过强制转换来避免这个问题 示例

由于

procedure subproc
(
  signal a : in  std_logic_vector(31 downto 0);
  signal b : in  std_logic_vector(31 downto 0);
  signal c : in  std_logic_vector(31 downto 0);
  signal d : in  std_logic_vector(31 downto 0);    
  signal e : out std_logic_vector(31 downto 0);
  signal f : out std_logic_vector(31 downto 0)    
)
is
  variable x : std_logic_vector(31 downto 0);
  variable y : std_logic_vector(31 downto 0);    
begin

  x := (others => '0');
  y := (others => '0');

  for i in 0 to 31 loop
      x(i) := (a(i) xor b(i)) and (c(i) xor d(i));
      y(i) := (a(i) xor b(i)) or ((d(i) xor c(i)) xor b(i));
  end loop;

  e <= x(31 downto 0);
  f <= y(31 downto 0);

end;

procedure main
(
  signal a : in  std_logic_vector(31 downto 0);
  signal b : in  std_logic_vector(31 downto 0);
  signal r : out std_logic_vector(31 downto 0)
)
is
  variable res : std_logic_vector(31 downto 0);
  variable t0, t1 : std_logic_vector(31 downto 0);
  constant c : std_logic_vector(31 downto 0) := X"fedcba90";
  constant d : std_logic_vector(31 downto 0) := X"7654321f";       
begin

  t0 := (others => '0');
  t1 := (others => '0');

  for i in 0 to 31 loop
    if ( (c(i) = '0') && (d(i) = '1') ) then
       subproc( t0, t1, 
                a, b, t0, t1 );
    end if;              
  end loop;

  r <= t0;
end;      

2 个答案:

答案 0 :(得分:2)

首先,你的“if”子句是用C风格编写的。你想说:

if (c(i) = '0') and (d(i) = '1') then

但问题实际上是你将程序描述为将SIGNAL作为参数。如果要将结果分配给变量,则需要声明不同的过程签名:

procedure subproc (
signal a : in  std_logic_vector(31 downto 0);
signal b : in  std_logic_vector(31 downto 0);
signal c : in  std_logic_vector(31 downto 0);
signal d : in  std_logic_vector(31 downto 0);
variable e : out std_logic_vector(31 downto 0);
variable f : out std_logic_vector(31 downto 0))

但是,您还需要将所有作业更改为ef,以便它们是变量分配:

e := x(31 downto 0);

答案 1 :(得分:0)

为什么不直接将subproc参数定义为变量而不是信号?