procedure declaration problem

C

Chuck Roth

Guest
The following code simulates and synthesizes without any problem:

entity proctest is
port(A: inout positive range 1 to 15; clk: in bit);
end proctest;
architecture Behavioral of proctest is
signal St: positive range 1 to 15;
begin
process(clk)
procedure P1 is
begin A <= A+1; end P1;
procedure P2 is
begin A <= A+2; end P2;
begin
if clk'event and clk = '1' then
if St = 1 then P1; end if;
if St = 2 then P2; end if;
if St = 3 then P1; end if;
St <= St+1;
end if;
end process;
end Behavioral;

If I move the procedure declarations from the process to the architecture
declaration section, I get syntax error messages: "cannot drive signal A in
procedure P1".
Why? I thought procedures declared in the architecture would be global to
all processes. When is it okay to declare procedures in the architecture
and when is it not?

-- C. H. Roth
 
Chuck Roth wrote:
The following code simulates and synthesizes without any problem:

entity proctest is
port(A: inout positive range 1 to 15; clk: in bit);
end proctest;
architecture Behavioral of proctest is
signal St: positive range 1 to 15;
begin
process(clk)
procedure P1 is
begin A <= A+1; end P1;
procedure P2 is
begin A <= A+2; end P2;
begin
if clk'event and clk = '1' then
if St = 1 then P1; end if;
if St = 2 then P2; end if;
if St = 3 then P1; end if;
St <= St+1;
end if;
end process;
end Behavioral;

If I move the procedure declarations from the process to the architecture
declaration section, I get syntax error messages: "cannot drive signal A in
procedure P1".
Why? I thought procedures declared in the architecture would be global to
all processes. When is it okay to declare procedures in the architecture
and when is it not?

-- C. H. Roth
Wouldn't you need to declare the procedures formally?

procedure P1 (signal A : inout positive range 1 to 15 ) is
begin A <= A+1; end P1;
procedure P2 (signal A : inout positive range 1 to 15 ) is
begin A <= A+2; end P2;

Then call them as P1(A), P2(A)...

Maybe a procedure declared within a process inherits all
the variables the process had, including the global ports,
but a procedure declared outside a process has to have
a formal parameter list specified?

Not the 'A' within the code above isn't the same A as the
port.

-Dave

--
David Ashley http://www.xdr.com/dash
Embedded linux, device drivers, system architecture
 
Chuck Roth wrote:

If I move the procedure declarations from the process to the architecture
declaration section, I get syntax error messages: "cannot drive signal A in
procedure P1".
Because the procedure, if legal, would be in scope for any process in
the architecture.

When is it okay to declare procedures in the architecture
When the procedure is passed the signal
as a parameter.

Here's a simpler example:
__________________________________
library ieee;
use ieee.std_logic_1164.all;
entity proc_test is
end proc_test;

architecture sim of proc_test is
signal test_s : std_logic;

procedure ok_driver -- signal parameter
( signal arg: inout std_logic) is
begin
arg <= '0';
end ok_driver;

procedure bad_driver is -- direct drive
begin
-- test_s <= '0'; -- won't compile:
-- ** Error: Cannot drive signal 'test_s' from this subprogram.
end bad_driver;

begin
ok_driver(test_s); -- works
end sim;
_____________________________________

However, I would write your example without
any signals at all...
_____________________________________
entity proctest is
port(A : out positive range 1 to 15;
rst : in bit;
clk : in bit);
end proctest;
architecture Behavioral of proctest is
begin
process(clk)
variable A_v : positive;
procedure P1 is
begin A_v := A_v+1; end P1;
procedure P2 is
begin A_v := A_v+2; end P2;
begin
pt : if rst = '1' then
A_v := 1;
elsif clk'event and clk = '1' then
if A_v = 1 then P1; end if;
if A_v = 2 then P2; end if;
if A_v = 3 then P1; end if;
P1;
end if pt;
end process;
end Behavioral;
___________________________________

I would probably also replace
those procedures with functions

-- Mike Treseler
 
Chuck Roth:


If I move the procedure declarations from the process to the
architecture declaration section, I get syntax error messages:
"cannot drive signal A in procedure P1".
Why? I thought procedures declared in the architecture would be
global to all processes. When is it okay to declare procedures in the
architecture and when is it not?
If you assign a signal from within a procedure that is not inside a
process, this signal must be passed to the procedure as a signal argument.

(Last paragraphe of LRM 8.4.1)

--
jr
 

Welcome to EDABoard.com

Sponsor

Back
Top