procedure declaration problem

Discussion in 'VHDL' started by Chuck Roth, Sep 6, 2006.

  1. Chuck Roth

    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, Sep 6, 2006
    #1
    1. Advertising

  2. Chuck Roth

    David Ashley Guest

    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
    David Ashley, Sep 6, 2006
    #2
    1. Advertising

  3. 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
    Mike Treseler, Sep 6, 2006
    #3
  4. Chuck Roth

    jr Guest

    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
    jr, Sep 7, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    950
  2. Alex Vinokur
    Replies:
    4
    Views:
    581
    Jonathan Turkanis
    Apr 5, 2004
  3. Ovidesvideo
    Replies:
    4
    Views:
    499
    Andrey Tarasevich
    Dec 10, 2004
  4. Mike P
    Replies:
    0
    Views:
    3,295
    Mike P
    Jun 19, 2006
  5. AlexWare
    Replies:
    2
    Views:
    752
    Paul Uiterlinden
    Oct 23, 2009
Loading...

Share This Page