Passing complex unconstrained array as signal to a procedure

Discussion in 'VHDL' started by Anne Onime, Mar 31, 2010.

  1. Anne Onime

    Anne Onime Guest

    I have the following definitions in a VHDL architecture:

    TYPE MemType IS ARRAY (MemDepth-1 DOWNTO 0) OF std_ulogic_vector(DataWidth-1 DOWNTO 0);
    SIGNAL Mem : MemType := (OTHERS => (OTHERS => '0'));

    such that MemDepth and DataWidth are generics on the entity. I would like to create the procedure "InitMem" in a
    package to initialize the Mem signal to a specific pattern. But I do not know what the specific settings of
    MemDepth and DataWidth will be for each instance of the entity that will be calling the procedure. So I would
    ideally like to specify an unconstrained parameter for the procedure. Obviously, I can also pass the MemDepth and
    DataWidth values along with the signal itself so that the procedure knows the array bounds.

    Is this possible? If so, what would the procedure look like? I would have thought it would be something like this,
    but I am getting compiler errors that I cannot define an unconstrained type:

    PACKAGE InitPkg IS

    TYPE MemType IS ARRAY (natural RANGE <>) OF std_ulogic_vector;

    PROCEDURE InitMem (
    SIGNAL Mem : INOUT MemType;
    CONSTANT DataWidth : IN positive;
    CONSTANT MemDepth : IN positive) IS

    ...

    Note that this initialization is NOT intended to be synthesizable. Any suggestions?

    - vhannak
    Anne Onime, Mar 31, 2010
    #1
    1. Advertising

  2. Anne Onime

    Tricky Guest

    It should be possible with the new VHDL2008 standard, but its not very
    well supported yet. Until then, the only thing you can do is to
    constrain the std_ulogic_vector.

    On 31 Mar, 04:17, Anne Onime <> wrote:
    > I have the following definitions in a VHDL architecture:
    >
    >   TYPE   MemType IS ARRAY (MemDepth-1 DOWNTO 0) OF std_ulogic_vector(DataWidth-1 DOWNTO 0);
    >   SIGNAL Mem : MemType := (OTHERS => (OTHERS => '0'));
    >
    > such that MemDepth and DataWidth are generics on the entity.  I would like to create the procedure "InitMem" in a
    > package to initialize the Mem signal to a specific pattern.  But I do not know what the specific settings of
    > MemDepth and DataWidth will be for each instance of the entity that will be calling the procedure.  So I would
    > ideally like to specify an unconstrained parameter for the procedure.  Obviously, I can also pass the MemDepth and
    > DataWidth values along with the signal itself so that the procedure knows the array bounds.
    >
    > Is this possible?  If so, what would the procedure look like?  I would have thought it would be something like this,
    > but I am getting compiler errors that I cannot define an unconstrained type:
    >
    > PACKAGE InitPkg IS
    >
    >   TYPE  MemType IS ARRAY (natural RANGE <>) OF std_ulogic_vector;
    >
    >   PROCEDURE InitMem (
    >     SIGNAL Mem  : INOUT MemType;
    >     CONSTANT DataWidth : IN positive;
    >     CONSTANT MemDepth : IN positive) IS
    >
    > ..
    >
    > Note that this initialization is NOT intended to be synthesizable.  Any suggestions?
    >
    > - vhannak
    Tricky, Mar 31, 2010
    #2
    1. Advertising

  3. Anne Onime wrote:

    > I have the following definitions in a VHDL architecture:
    >
    > TYPE MemType IS ARRAY (MemDepth-1 DOWNTO 0) OF
    > std_ulogic_vector(DataWidth-1 DOWNTO 0);
    >
    > SIGNAL Mem : MemType := (OTHERS => (OTHERS => '0'));


    Yuck: signal+memory.

    If the memory is going to contain more than a fair amount of bits, use a
    variable instead of a signal. A signal consumes about 100X more memory on
    your workstation/PC then a variable would.

    So if at all possible, keep mem confined to a single process, so it can be a
    variable. Limiting the number of processes (preferably: 1) is a good idea
    anyway.

    And indeed as said by Tricky, only VHDL-2008 supports arrays of
    unconstrained vectors.

    --
    Paul Uiterlinden
    www.aimvalley.nl
    e-mail addres: remove the not.
    Paul Uiterlinden, Mar 31, 2010
    #3
  4. Anne Onime

    KJ Guest

    On Mar 30, 11:17 pm, Anne Onime <> wrote:
    > I have the following definitions in a VHDL architecture:
    >
    >   TYPE   MemType IS ARRAY (MemDepth-1 DOWNTO 0) OF std_ulogic_vector(DataWidth-1 DOWNTO 0);
    >   SIGNAL Mem : MemType := (OTHERS => (OTHERS => '0'));
    >
    > such that MemDepth and DataWidth are generics on the entity.  I would like to create the procedure "InitMem" in a
    > package to initialize the Mem signal to a specific pattern.  But I do not know what the specific settings of
    > MemDepth and DataWidth will be for each instance of the entity that will be calling the procedure.

    <snip>
    ...
    >
    > Note that this initialization is NOT intended to be synthesizable.  Any suggestions?
    >


    Use two dimensional arrays instead for the procedure. Then you can
    either:
    - Change the entity (and whatever instantiates the entity...) to use
    2d arrays...probably more work than it's worth or...
    - Create functions within the architecture of the entity to convert
    your array of arrays into a 2d array. It's not that difficult to do.

    Kevin Jennings
    KJ, Mar 31, 2010
    #4
  5. Hi Anne,

    you are allowed just one "degree of freedom" with VHDL before 2008. I regularily
    have things like the following in my testbenches:


    subtype t_slv32 is std_logic_vector(31 downto 0);
    type t_tlm_payload is array (natural range <>) of t_slv32;

    procedure memwr( addr : in std_logic_vector;
    pload : in t_tlm_payload;
    signal clk : in std_logic;
    .....

    and then call the procedure with
    memwr(X"1234001C",
    (X"96699669", X"1E711E71"),
    clk, ....

    If you use a generic for the word size you can probably still implmenet a portable
    /reusable concept, depending on your application.
    Charles Gardiner, Mar 31, 2010
    #5
    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. FE
    Replies:
    0
    Views:
    1,646
  2. Alex Rast
    Replies:
    3
    Views:
    5,150
    Jim Lewis
    Oct 6, 2003
  3. Pankaj
    Replies:
    2
    Views:
    816
    anupam
    Aug 23, 2004
  4. Amal
    Replies:
    5
    Views:
    8,666
    Brandon
    Mar 8, 2006
  5. jens
    Replies:
    3
    Views:
    826
Loading...

Share This Page