Deferred constant in package

Discussion in 'VHDL' started by hssig, Nov 30, 2009.

  1. hssig

    hssig Guest

    Hi,

    I am defining a function and a constant in the following manner:


    package pkg_test is
    function f_calc( inp: integer) return integer;
    constant cVAL : integer;
    end package pkg_test;


    package body pkg_test is
    function f_calc( inp: integer) return integer is
    begin
    ...
    end function f_calc;

    constant cVAL : integer := f_calc(16);

    type type_sig is array (natural range <>) of std_logic_vector(cVAL
    downto 0);
    end package body pkg_test;

    The conflict: If I want to make "type_sig" visible for my component,
    the type has to be defined in the package and not in the package
    body . How can I find a remedy ?

    Thank you, cheers
    hssig
     
    hssig, Nov 30, 2009
    #1
    1. Advertising

  2. hssig wrote:

    > The conflict: If I want to make "type_sig" visible for my component,
    > the type has to be defined in the package and not in the package
    > body .


    Make that *declared* in the package and assigned in the body.

    How can I find a remedy ?

    What's the problem?

    That's how it works for deferred constants.

    Maybe you want to declare your constant
    in the process where it is used.

    -- Mike
     
    Mike Treseler, Nov 30, 2009
    #2
    1. Advertising

  3. Mike Treseler <> writes:

    > hssig wrote:
    >
    >> The conflict: If I want to make "type_sig" visible for my component,
    >> the type has to be defined in the package and not in the package
    >> body .

    >
    > Make that *declared* in the package and assigned in the body.
    >
    > How can I find a remedy ?
    >
    > What's the problem?
    >
    > That's how it works for deferred constants.
    >
    > Maybe you want to declare your constant
    > in the process where it is used.
    >
    > -- Mike


    I think the original problem was that the package should declare the
    type (so it can be used un may places, presumably), which requires the
    elaboration of the function to compute the width. But you can't put a
    function body definition inside a package declaration. There's the
    problem.

    One possible workaround would be to put the function (alone) into an
    auxiliary package, and then use it to make the type public in a
    body-less (disembodied???) package:


    package aux...
    function f(integer) return integer...
    end package aux;

    package body aux
    function f(integer) return integer blah blah...
    end package body;

    use work.aux.all;
    package p
    constant cVal = f(16); -- imported f
    type v is array... (cVal-1 downto 0);
    end package;


    - Kenn


    --
    ---------------------------------
     
    Kenn Heinrich, Nov 30, 2009
    #3
  4. hssig

    KJ Guest

    On Nov 30, 12:32 pm, hssig <> wrote:
    > Hi,
    >
    > I am defining a function and a constant in the following manner:
    >
    > package pkg_test is
    > function f_calc( inp: integer) return integer;
    > constant cVAL : integer;
    > end package pkg_test;
    >
    > package body pkg_test is
    > function f_calc( inp: integer) return integer is
    > begin
    >     ...
    > end function f_calc;
    >
    > constant cVAL : integer := f_calc(16);
    >
    > type type_sig is array (natural range <>) of std_logic_vector(cVAL
    > downto 0);
    > end package body pkg_test;
    >
    > The conflict: If I want to make "type_sig" visible for my component,
    > the type has to be defined in the package and not in the package
    > body . How can I find a remedy ?
    >


    Rather than an array of std_logic_vectors of some non-constant size,
    you could define type_sig as a two dimensional array of std_logic
    unconstrained in either dimension.

    After you do that though you wont be able to assign an entire "cVAL
    downto 0" vector element of your data type (or retrieve an entire
    "cVAL downto 0" either).

    So what you'll want to do is then some functions to put into your
    package like the following:
    - A function that given the 2d array input and an index, return an
    array of std_logic_vectors from the 'index' column of the 2d array.
    - A function (or procedure) that given the 2d array, an array of
    std_logic_vectors and an index, copies the array of vectors into the
    indexed column of the 2d array.

    These functions would be defined to work with unconstrained vectors
    and arrays because it can determine the limits within the function
    itself.

    It's a bit clunky but does work. The alternative is to work directly
    with the 2d array. Depending on what you're doing, this might be
    better, but in many cases it's not and the helper functions/procedures
    are the better way to go.

    Kevin Jennings
     
    KJ, Dec 1, 2009
    #4
  5. hssig

    hssig Guest

    Hi Kenn, Kevin,

    thank you for your explanations. I like Kenn's proposal to source the
    function(s) out to a second package, Kevin's idea seems to be a good
    alternative which I have to think about.

    cheers,
    hssig
     
    hssig, Dec 1, 2009
    #5
  6. Kenn Heinrich wrote:

    > I think the original problem was that the package should declare the
    > type (so it can be used un may places, presumably), which requires the
    > elaboration of the function to compute the width. But you can't put a
    > function body definition inside a package declaration.


    But I don't have to.
    http://groups.google.com/group/comp.lang.vhdl/search?q=xyz_pkg defer



    -- Mike Treseler
     
    Mike Treseler, Dec 3, 2009
    #6
  7. Mike Treseler <> writes:

    > Kenn Heinrich wrote:
    >
    >> I think the original problem was that the package should declare the
    >> type (so it can be used un may places, presumably), which requires the
    >> elaboration of the function to compute the width. But you can't put a
    >> function body definition inside a package declaration.

    >
    > But I don't have to.
    > http://groups.google.com/group/comp.lang.vhdl/search?q=xyz_pkg defer
    >
    >
    >
    > -- Mike Treseler



    Irrelevant. That's just what the OP was doing originally. But it does
    not show how to make use of either cVal or f_calc inside the package
    declaration, which is what the OP specifically asked for in order to
    export the constrained type "type_sig" from the package.

    - Kenn

    --
     
    Kenn Heinrich, Dec 3, 2009
    #7
  8. Kenn Heinrich wrote:

    > Irrelevant. That's just what the OP was doing originally. But it does
    > not show how to make use of either cVal or f_calc inside the package
    > declaration, which is what the OP specifically asked for in order to
    > export the constrained type "type_sig" from the package.


    My point is that while using two packages works fine,
    I can do the same thing using a single package and body.
    Deferred functional constants belong in the body.
    It is a fact that they are not allowed in the package,
    but that does not stop me from using one from the package body.

    -- Mike Treseler
     
    Mike Treseler, Dec 3, 2009
    #8
    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:
    961
  2. Bryan

    deferred decorator

    Bryan, Dec 8, 2004, in forum: Python
    Replies:
    3
    Views:
    354
    Nick Coghlan
    Dec 9, 2004
  3. Jp Calderone

    Re: [Twisted-Python] xmlrpc deferred

    Jp Calderone, May 27, 2005, in forum: Python
    Replies:
    0
    Views:
    492
    Jp Calderone
    May 27, 2005
  4. Replies:
    8
    Views:
    446
    Peter Otten
    May 10, 2006
  5. Tom Plunket

    Deferred imports

    Tom Plunket, Jul 15, 2006, in forum: Python
    Replies:
    1
    Views:
    317
    Justin Azoff
    Jul 15, 2006
Loading...

Share This Page