How to put part of one array into another

N

none

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
 
K

KJ

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top