vhdl:passing generic sized arrays to functions?

Im have different sizes of std_logic_vector arrays and want to run functions on different array types where vector sizes are different (array height is unconstrained). Ive looked at subtypes, but cant find a solution. I think it stops because an array doesnt seem to be able to be a subtype of a generic sized array. Does anyone know how to do that?

Reply to
Morten Leikvoll
Loading thread data ...

y
e

I'm not quite sure if I understand what you're asking for, but functions can work with unconstrained arrays. Inside the function, one can then determine the bounds of the array with the usual array attributes (i.e. 'low, 'high, 'range, etc.)

Example:

function foo(my_slv: std_logic_vector) return std_logic is begin for i in my_slv'range loop ... end loop; ...

Does that help?

Kevin Jennings

Reply to
KJ

Not really but thanks for trying..Your function doesnt work with an array. Ill try to explain better.. I have two array types: type SLVAR1 is array(natural range ) of std_logic_vector(10 downto 0); type SLVAR2 is array(natural range ) of std_logic_vector(5 downto 0);

I want to pass them both to the same function as generic array size, but since they have different typenames, that is not possible. Is there a way to define those arrays differently so that they can be passed to a common function?

Reply to
Morten Leikvoll

That's a nice little resonance. "maxascent" was bothered by exactly this in the recent thread "VHDL Basic Question".

True 2-dimensional arrays provide one possible way out, although they will cost you some added trouble. See my latest response in that thread for some sketch ideas.

If this is purely testbench code then there are things you can do with access types to give the flexibility you need (and, probably, more than you need). For RTL synthesis... does anyone know the current level of tool support for unconstrained element types in aggregates? Generics on packages?

--
Jonathan Bromley
Reply to
Jonathan Bromley

ay.

.

sed

No, but there are a few ways around...

  1. VHDL does allow function names to be overloaded so you can define two functions with the same name, one that expects type SLVAR1, the other that expects type SLVAR2.

  1. Instead of using arrays of vectors, use a 2 dimensional array. Doing this will likely mean that you need to create additional functions to convert vectors into the appropriate row/column of the 2d array.

Kevin Jennings

Reply to
KJ

I read that thread but it appeared to be a different Q. It doesnt look like the problem used different sized arrays and my first pri here is to make this clean code. My only option now is to generate one function for each size, wich is a bit awkward. For each size I could convert types and call a more generic function, but I'd like to know if there is an even more clean way to do it. If arrays could be a subtype of another [unconstrained] array, I think it would solve my problem, but I dont think it can?

Reply to
Morten Leikvoll

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.