FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > VHDL

VHDL comp.lang.vhdl newsgroup / Usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-06-2006, 07:58 PM
Chuck Roth
Guest
 
Posts: n/a
Default procedure declaration problem

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


Reply With Quote
  #2 (permalink)  
Old 09-06-2006, 10:18 PM
David Ashley
Guest
 
Posts: n/a
Default Re: procedure declaration problem

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
Reply With Quote
  #3 (permalink)  
Old 09-06-2006, 10:34 PM
Mike Treseler
Guest
 
Posts: n/a
Default Re: procedure declaration problem

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
Reply With Quote
  #4 (permalink)  
Old 09-07-2006, 09:57 AM
jr
Guest
 
Posts: n/a
Default Re: procedure declaration problem

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
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function declaration raghu Verilog 2 09-14-2006 09:34 AM
maxplusII error: a deferred constant declaration without a full declaration is not supported Noah VHDL 5 04-07-2006 03:34 PM
port declaration Andy Luotto Verilog 2 03-29-2006 06:24 PM
constants declaration Benjamin Todd VHDL 2 02-15-2004 01:49 PM
port declaration problem chris VHDL 9 11-14-2003 10:16 PM


All times are GMT +1. The time now is 02:38 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved