Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

function for converting an array to a vector

Status
Not open for further replies.

shaiko

Advanced Member level 5
Joined
Aug 20, 2011
Messages
2,644
Helped
303
Reputation
608
Reaction score
297
Trophy points
1,363
Activity points
18,302
I want to write a function that receives an array of multiple std_logic_vector elements and concatenates them to a single long std_logic_vector.

This is what I wrote:

Code:
function array_to_sentence 
( array_data : array , 
  width_array : positive , 
  depth_array : positive ) return std_logic_vector ; 
variable sentence : std_logic_vector ( width_array * depth_array - 1 downto 0 ) ;
begin
for index in 0 to depth_array - 1 
loop
  sentence ( ( ( width_array * ( depth_array - index ) ) - 1 ) downto ( width_array * ( depth_array - index ) - width_array ) ) <= array_data ( index ) ;
  end loop ;
  return sentence ;
end function array_to_sentence ;

Compilation fails with this note:
near "array": expecting STRING or IDENTIFIER or << or '('

Please help me rewrite the function.
 

you cannot have an array type called array
Also, function parameters are separated with ; not ,
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
I changed the , to ;

Regarding the array:
It's defined as:
"array_data : array"

How can I define it without giving it specific boundaries?
 

The function has to refer to an external array type definition, e.g. in a package.
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
The function has to refer to an external array type definition, e.g. in a package.
And can that array be of undefined boundaries?
 

And can that array be of undefined boundaries?

for your example, in VHDL 93 - No, the length of each element must be defined in the package, but the total length of the array can be undefined
for VHDL 2008, both dimensions can be undefined, and then defined when the function is called, removing the need for the width and depth arguments from the function:

output <= array_to_sentence( x : my_array_type(7 downto 0)(7 downto 0) )

then you can use the 'length attributes to define all the internal lengths.
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
How can I use the length attribute to determine both dimensions of the array?

For example, if x is a vector:
simple enough, x'length gives the width of vector x.

but what if x was an array?
How can I use the length attribute for finding the width of x?
How can I use the length attribute for finding the depth of x?
 

if X is an array of arrays, you can just index into it to find the length of the 2nd array:

x(n)'length
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
What if I don't do it with a function...
Suppose, the array is defined in an entity. Can the boundaries be set by the entity's generics?
 

Yes. But its very difficult to comment without seeing a real code example and putting it into context.
Anything inside an entity has access to the generics.
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top