How to put part of one array into another

Discussion in 'VHDL' started by none, Sep 11, 2008.

  1. none

    none Guest

    I have 2 arrays declared in my code :

    type Array6Deep96Bit is array (6 downto 1) of std_logic_vector (95
    downto 0) ;
    type Array16Deep96Bit is array (16 downto 1) of std_logic_vector (95
    downto 0) ;


    In an instantiation of a block of code, I'd like to port the first 6
    array words into the block:

    port map (
    BackplaneSerialDataIn => DataFromPackToMux(6 downto 1),

    where BackplaneSerialDataIn is of type Array6Deep96Bit and
    DataFromPackToMux is of type Array16Deep96Bit.

    I'm using Aldec Active-HDL and it gives me an error stating "Actual
    parameter type in port map does not match the port formal type
    "BackplaneSerialDataIn"

    I've tried different permutations of the instantiation such as
    explicitly referencing the array index, but I either get the previous
    error message or on that says "No actual specified for local port
    "BackplaneSerialDataIn"

    Any ideas on how to write this without having to expand out the array to
    it's individual elements?

    Thanks

    Ron
    none, Sep 11, 2008
    #1
    1. Advertising

  2. none

    KJ Guest

    On Sep 11, 2:47 pm, none <> wrote:
    > I have 2 arrays declared in my code :
    >
    > type Array6Deep96Bit    is array (6 downto 1) of std_logic_vector (95
    > downto 0) ;
    > type Array16Deep96Bit   is array (16 downto 1) of std_logic_vector (95
    > downto 0) ;
    >
    > In an instantiation of a block of code, I'd like to port the first 6
    > array words into the block:
    >
    > port map (
    >         BackplaneSerialDataIn => DataFromPackToMux(6 downto 1),
    >
    > where BackplaneSerialDataIn is of type Array6Deep96Bit and
    > DataFromPackToMux is of type Array16Deep96Bit.
    >
    > I'm using Aldec Active-HDL and it gives me an error stating "Actual
    > parameter type in port map does not match the port formal type
    > "BackplaneSerialDataIn"
    >


    This is what is known as data type checking. The entity parameter
    BackplaneSerialDataIn is type 'Array6Deep96Bit', but you're trying to
    give it DataFromPackToMux(6 downto 1) which is a slice of an array of
    type 'Array16Deep96Bit', those elements being of type
    'std_logic_vector (95 downto 0)'. Since these are two different types
    you're getting the error.

    Instead you might want to try out the following approach:

    type Array96Bit is array(natural range <>) of std_logic_vector (95
    downto 0);
    subtype Array6Deep96Bit is array (6 downto 1) of Array96Bit;
    subtype Array16Deep96Bit is array (16 downto 1) of Array96Bit;

    Now the new types 'Array6Deep96Bit' and 'Array16Deep96Bit' are arrays
    of the same type and any slice of them will also be of that same type
    (i.e. type 'Array96Bit').

    It's confusing when you get started creating your types because you
    tend to think of it in terms of the definitions of the types that the
    thing is made up of. In this case you were looking at your new types
    as both being simply different sized collections of the same type of
    thing (std_logic_vector(95 downto 0). But a strongly typed language
    does not allow for such syntax. It looks at the type that is expected
    and expects to find something of that same type being assigned.
    Things of type 'xyz' cannot be assigned to something that is of type
    'abc' even if the definitions of those two types is identical.

    What you need to do is just not look so deeply (i.e. don't look at the
    definition of the new types when trying to deduce what the type
    mismatch is), just look at the actual types being passed around. By
    first defining a generic array type as I did ( i.e. 'Array96Bit') that
    can be used to define any range of subtypes from it, you're writing
    the code in a manner that it is type correct...and as you can see,
    it's not that difficult or different from your original code.

    Kevin Jennings
    KJ, Sep 11, 2008
    #2
    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. loveNUNO
    Replies:
    2
    Views:
    907
    loveNUNO
    Nov 20, 2003
  2. TreatmentPlant
    Replies:
    9
    Views:
    446
    Markus Schoder
    Apr 16, 2006
  3. navS
    Replies:
    3
    Views:
    504
    Ismo Salonen
    May 9, 2008
  4. Robert Cohen
    Replies:
    3
    Views:
    265
    Andrew Durstewitz
    Jul 15, 2003
  5. Jack
    Replies:
    8
    Views:
    274
Loading...

Share This Page